-
Notifications
You must be signed in to change notification settings - Fork 293
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Download and static caching as a feature #165
Conversation
For anyone wishing to try this and provide feedback change into your serverless project directory and remove the official serverless-python-requirements and install this one with...
Then modify your serverless.yml to include the useStaticCache: true...
Then try a |
I'll try and check it out soon. And fix up the linting errors, please: https://circleci.com/gh/UnitedIncome/serverless-python-requirements/345?utm_campaign=vcs-integration-link&utm_medium=referral&utm_source=github-build-link |
@dschep Feel free to just give this PR a brief glance, don't look too intensely yet. Just want to know if there's something I'm doing that is fundamentally wrong, let me know so I can re-align. Just fixed linting, but still have some test failures. I spent a little time this evening looking into some test failures... so far I have one major problem with a test. The
Proposed config with a static and download cache (without custom path) would be
This is necessary and desirable because this makes this feature more "standard" in this plugin and not added as an extra pip option with two commands. This came up because this pull request changes fundamentally how the Dockerization works. In the past, this plugin has been quite famous for "leaving trash" all over your project root if/when it fails for some fatal reason because we mounted the entire servicePath into Docker. To me, that was a fundamentally flawed approach and I saw it all the time, all that Docker needs is a requirements.txt file and a temporary folder volume mount to spit its outputs into. So, in this PR, Docker was adjusted in this way works and mounts only a dedicated cache/temp sub-directory into Docker, not your entire-project-directory. This is for security, integrity, scope, and static caching purposes. I'll work on implementing this next, and adding/modifying tests to cover this. |
A little closer, download cache is now a built-in feature, which works without having to specify extraCmd or a path for it. The cache path is now shared between both the static and the download path, for simplification. And now almost all (but one) tests pass, and some new tests exist. I'm wrestling with a small part of it, just need some more time to debug it. |
@AndrewFarley I'm using your version of serverless-python-requirements for a couple days, and it works as intended using |
Thanks for more sets of eyes and/or trying it @Valian. Good to hear you've seen the same results. I'm slammed with work this week but I hope to finish up the last tests and do a few more tweaks so we can get this in mainline soon. |
That's great news @Valian! Thanks for the testing! 😄 |
Hi @AndrewFarley! I tested your PR with the // Use same user so requirements folder is not root and so --cache-dir works
cmdOptions.push('-u', `${process.getuid()}`); by // Set the ownership of the folder to current user
pipCmd = quote(pipCmd);
const chownCmd = quote([
'chown', '-R', `${process.getuid()}:${process.getgid()}`, '/var/task',
]);
pipCmd = ['/bin/bash', '-c', '"' + pipCmd + ' && ' + chownCmd + '"']; You'll need to add this import as well: const {quote} = require('shell-quote'); See my comment here as well: #182 (comment) as I don't know if @dschep will want to keep it like that. Thanks! |
@cgrimal Thanks for the mini patch, I'll try to apply it, but I don't know how to test it. Have a few minutes to chat? I'd love to understand, especially from the author, what that feature is supposed to do exactly. Ping me, farley at neonsurge dot com. I'd like to make some time asap to finish this and one of the blockers is indeed the dockerssh. Would love your help. I could add you as a admin on my fork and we could work together on it or something? |
I'll spend some time now rebasing and resolving the conflicts to bring my MR back up to date, so we can move forward. |
Just did the merge, resolving conflicts with the latest from master, it fixed a handful of bugs that I had already sort-of coded around... I haven't gone and ran the unit tests or linting yet... working on it... |
Hey guys, so, back at it again and think it's ready to go, rebased and refactored. All tests are passing locally but don't seem to pass on CircleCI, I'll try to fix this soon if I can figure it out. But if I could get @cgrimal to test your UID fix in this MR and to maybe test the DockerSSH overall? And @Valian / @dschep could you re-review? I refactored this quite a bit to change less code, be simpler, and work more like it used to in every way when the new features are disabled. Besides that just need to manually spot check on Windows. I'll wait till there's no other feedback/stoppers and do some final testing there. |
Great work @AndrewFarley! I tested it on my current project, and it works almost like a charm! The Even though I am the author of this feature, @dschep helped me quite a lot by suggesting great ideas that ended up being implemented in the PR! Eventually, what it does is quite straightforward. It links the files used by the SSH agent from your If you run the Docker process as your current user, the SSH agent won't find your SSH keys because it will look for the I remember that at first, I tried to keep the option passing the user id, but none of the workarounds I came up with manage to do the trick. @kichik: Regarding the issue with the Unfortunately, I found out the A minor remark as well is that we should escape all the path to volumes, including the ones related to If you want to add me as admin, I'll be glad to contribute (I don't know how much time I'll be able to put though), or I could do a PR on your branch? Many thanks guys, I'm really looking forward to using this feature! |
@cgrimal You raised a few interesting points...
|
Thanks for the quick feedback @AndrewFarley.
|
Oh snap!
So I'm afraid we have a problem... I have to go, but I'll try to think of a solution. |
@cgrimal That might be exactly why the CircleCI fails... if you have it failing (I don't see that error on my Mac or Ubuntu) then maybe you can debug and fix it for us? And also to answer your question above, I haven't done tests recently but last time I tested the existing cache-dir stuff didn't work. I'll try to see if I can make it work, and if it does I'll make it a warning if its used. If I can't make it work, I'll make it error out if used. |
@cgrimal Another idea to fix this problem in docker that randomly everyone seems to have, is to let the pip cache be build locally in the docker container, and then moved out from a local path to the mount after pip finishes. I think this may be the best way to solve this problem, because this removed the uid problem completely. |
Hey guys, sorry I haven't stayed on top of this discussion I'll try and catch up to review this over the weekend. |
@AndrewFarley I am not sure I understand your suggestion about the pip cache folder, but what I implemented is quite simple: I use the chmod before the pip command to give ownership to root, run the pip command, and then give ownership back to the user. What do you think? I tried to run the tests locally, but some are failing and I'm not sure it is related... (I'm on Ubuntu by the way) EDIT: The tests are passing on CircleCI! \o/ |
hey @AndrewFarley - started testing, but didnt get very far, unfortunately. Existing config is:
I should note that slim also does not work at all on windows Test 1 - Installation Only - FAIL
Result
Test 2 - Without Docker - SUCCESS
Result Test 3 - With Options - FAIL
Result
After doing some research I found this problem with npm . Unfortunately, I tried clearing cache and reinstalling latest npm (v5.6) rerunning, and even using admin privileges in shell, still getting that error. |
hey @AndrewFarley - any updates on this? my project is getting slower every time I add a library :( Were the test results helpful? |
*Bump I'm also very reliant on this plugin, and have super slow build times, Id love to see this rebased (again) and merged in ... |
@sweepy84 The results were helpful, if only to tell me that I (or someone) needs to get a Windows machine and help this merge request work properly in that environment. @farridav I've spent a lot of time rebasing this keeping this working with the latest code, but I don't always/continue to have time rebasing this code. This code is in place now in 4 pipelines working very successfully, but all of them are non-windows environments (Linux/OS-X), so this already fixed my problem. I will try to continue to rebase when I have a few moments. Bottom line is, I, or someone, needs to get a Windows machine (or many of them) to make this work properly on Widnows... or maybe we make Windows support optional for this feature-set? Unfortunately, due to the nature of Docker on Windows, I can't just spin up a VM on the cloud to test this, it needs a raw/real machine, and the highest level of Windows to do this. I neither have the time nor the money to waste nor the machines laying around to do this. Anyone? |
Hi @AndrewFarley - If you can look past the self-serving nature of this comment, I would strongly recommend that such a fundamental feature of this plugin (or any feature for that matter) by OS agnostic. You would be alienating a very large percentage of developers out there (possibly a majority - certainly my team). You've already done a lot of great work, fixing the windows bugs is well worth the effort in my opinion. Perhaps @dee-me-tree-or-love can assist with this, given he has already solved the windows problems (#212 / #227 )? |
@dschep - I'm actually getting a different error now
Using: pythonRequirements: |
@sweepy84 I had been running into the bind path problem on Windows as well - for me the issue was with the volume mounting for the Probably not a solution, but might help 🙃 |
Yeah, I worried that might be the case, hmph. Alright, I think I know how to fix it... but I need to get Docker on Windows working. Do any of you have a throwaway/temporary machine I can RDP into to try to debug this? Would save me unnecessary cost of buying Windows Ultimate just to get this feature implemented. @dee-me-tree-or-love / @sweepy84 , or again, maybe someone can step up with Windows and help me fix this in that platform? Let me know. My goal is/was never to alienate anyone @sweepy84, I just lack the resources to properly test/iterate on that platform. Complain to Microsoft not allowing docker on anything except the most expensive version of windows, and not on a VM as well. :( I tried a few VM providers (aws, gc) docker's not possible on the cloud far as I can tell. If you know how/where, point me in that direction and I'll make it work. |
Docker Toolbox is still available and works without Windows 10 Pro and without Hyper-V. |
Hmm, I'll try it out and let you guys know, thanks @kichik |
Sorry I can't really provide any help on bindpath issues on windows @sweepy84. I didn't write that feature and don't have the hardware or software licenses to test it 😕 |
Alright ladies and gentleman... I've got Windows support fully working. 99% of the way there... @sweepy84 / @kichik / @dee-me-tree-or-love or anyone else with active Windows codebases can you try this? I tested/confirmed all three scenarios work that @sweepy84 reported was failing above. Without docker works, with docker works, with static caching works and it uses the static cache. All tests are passing, all my active pipelines work with this code (tested against 5 different codebases/pipelines), and I can confirm all the things seem to work fine with Docker Toolbox on Windows 10. Maybe someone else can test with the latest Docker for Windows? Thanks for any testing/attention, sorry this one has taken forever, since it "works for me" I lost interest in trying to get it merged, and I couldn't justify working on it on a clients dime because it worked for me/us. Hope we're close and can get everyone able to use this soon. And in the near future have both download and static caching enabled by default (because it's amazing). Cheers! edit One minor bug I found, the download cache isn't quite working on Windows only, but it doesn't fail fatally, it just isn't caching. I'll try to fix it shortly, but this could always be fixed in a future merge as well. :P This is merge ready as far as I'm concerned. :P |
YESSSS!! @AndrewFarley - great job mate! Looks like its working well! oh the time we're going to save! I saw your edit about not caching in windows only - what do u mean by "Windows only" - looks to be working for me :) |
Re: @sweepy84 there is two kinds of caching, the "static" cache, or the output of pip, and the "download" cache, the intermediary downloads that pip downloads to feed into pip. The static cache is working perfectly on windows, but the download cache doesn't appear to work. But as I said, it's not doing this in a fatal way, it's just keeping the cache in docker from what I can tell. I don't have any more time this weekend to spend on this, I can try again next weekend to fix this feature, or we can merge it and I can fix that in a future patch. |
@AndrewFarley - oh ok - thanks clarifying. My 2 cents - makes sense for it to be merged in and fixed at a later time (ideally raise the bug after doing the merge so it's not forgotten) given it's size so you don't waste time rebasing. |
Good job on all the hardwork @AndrewFarley, I'll get to reviewing this ASAP. Sometime this week. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Finally got around to reading through all the changes. Amazing work @AndrewFarley. The code looks great and the feature is well designed, and I love the clean-up work you've done, both in the JS & the tests.
I agree that this would be excellent to enable by default. I'm gonna merge this and cut a new release. I'd love a PR updating to make these default behavior and bumping to version 5.0.0-beta0
!
I'll publish to NPM on monday when i'm on a computer with npm creds |
Released as v4.2.0!! |
Fixes #157 (filed by me)
What this does
Implementation details
.serverless
or.serverless/functionname
if deploying individually.serverless requirements cleanCache
. This clears all items including the download and static cache.false/true
false/true
<path>
/mnt/shared
and set this value to/mnt/shared/sls-py-cache
.<integer>
TODO
Replaces #162