-
-
Notifications
You must be signed in to change notification settings - Fork 964
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
Implemented Docker multi-stage build #1819
Conversation
This is lookin great, thanks for taking the time! 🎸
Not sure what kind of tests you meant, but the modified workflows have been run in this PR and things didn't break (that's a good sign 😁 ).
The names seem quite good as-is, but if you're open for changes I'd use
I don't have a strong preference, but since the original issue was about tox not working, I'd be inclined to keep everything in this PR. |
d4f8800
to
c93147a
Compare
Thanks for the feedback!
Nitpicks are good, if it helps me follow conventions :)
Docker's default is to build the last stage. As I dropped the changes to the workflow files, so they use the default behavior, and changed the naming convention to |
This solves the first part of django#1817, where tox fails to install test dependencies due to missing packages. - Added stages to Dockerfile. - Moved package removal to production stage. - Added target dev to compose file.
c93147a
to
5424f72
Compare
Added 'tracdb' container to compose file. Simplified docker settings to remove duplication. Added support for 'secrets.json' in the docker dev stage. Added the 'DJANGOPROJECT_DATA_DIR' env var to tox.
19356bc
to
9fbab4a
Compare
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.
Thanks for working on this! I have not reviewed the other parts of this PR, but wanted to offer a couple thoughts/context on the Dockerfile since @bmispelon tagged me on it. Consider these nitpicks only and please feel free to proceed as y'all see fit.
|
||
FROM djangoproject-www-dev AS djangoproject-www-prod | ||
|
||
RUN apt-get purge --assume-yes --auto-remove \ |
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.
If I understand correctly, the initial layer for djangoproject-www-prod
will still have these packages, so this won't actually reduce the size of the prod image. The purpose of removing the packages in the same layer as they are installed as that they don't end up as part of the layer.
The usual way to work around this with a multi-stage build is to start fresh and copy out of the first layer only the needed files, rather than depending on it in full. In my opinion (others will certainly differ), since Python venvs aren't really self-contained (as in this situation, they depend on system libraries), this is often more trouble than its worth for Python images.
A couple alternative ideas:
- Uninstall the
-dev
packages only whenREQ_FILE
isrequirements/prod.txt
- Uninstall the other packages but not
libpq-dev
always, which should fix the underlying issue
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.
Great catch, thanks.
I don't think uninstalling other packages would work, as tox
installs psycopg
from source, and I believe they are all build requirements. At least, purging different packages led to different errors in my tests.
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.
Got it, thanks. That makes sense. If gcc
is needed too, my second suggestion certainly doesn't make sense :)
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.
I'll revisit this tomorrow, but it should be doable via something like a Docker build arg (KEEP_DEPENDENCIES
), and making the package uninstall conditional.
This solves the first part of #1817, where tox fails to install test dependencies due to missing packages.
Notes (and unresolved questions)
Marking this a draft PR for now, as it could use some feedback :)
target
should suffice.install_deps
step, and allows the tests to run, but the actual tests still fail when run.