-
-
Notifications
You must be signed in to change notification settings - Fork 2.9k
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
Makefile for use with docker #1879
base: master
Are you sure you want to change the base?
Conversation
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 this contribution! I'd be in favour of seeing this. However, I have a few comments:
- I think we should remove this file if
use_docker='n'
. This can be done by adding theMakefile
to the post-generation hook:
https://github.com/pydanny/cookiecutter-django/blob/d299e1d354270cd0ad14514c1f069068bef882da/hooks/post_gen_project.py#L62 - Ideally, could you add a
clear
target to clean up the docker containers & volumes, as suggested by @demestav here. - Also nice to have, you can generate a Makefile help with this neat trick.
Finally, feel free to add yourself to the list of contributors 🎉
@docker-compose -f local.yml up | ||
|
||
build: | ||
@docker-compose -f local.yml up --force-recreate --build |
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 find a bit confusing that make build
actually does a docker-compose up ...
. One might want to re-build and then run a manage command rather than starting the whole stack.
What's the reason for that? I'd rather keep them a bit more separate and only do docker-compose build
.
We can chain commands easily with make: make build up
,
Finally, could we accept an optional parameter to rebuild only one container, e.g. django
?
@docker-compose -f local.yml up --force-recreate --build | ||
|
||
manage: | ||
@docker-compose -f local.yml run --rm django python ./manage.py $(filter-out $@,$(MAKECMDGOALS)) --settings=config.settings.local |
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.
Why do we need the --settings=config.settings.local
? It's the default value, so we should be able to remove it.
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 use a Makefile
for docker too, and IMHO its quite useful because you can easily change from local to production;
buildev:
@sed -i.bak s/DJANGO_SETTINGS_MODULE=config.settings.production/DJANGO_SETTINGS_MODULE=config.settings.local/g .env
@sed -i.bak s/DJANGO_DEBUG=False/DJANGO_DEBUG=True/g .env
@docker-compose -f docker-compose-dev.yml up --build
and later on:
buildprod:
@sed -i.bak s/DJANGO_SETTINGS_MODULE=config.settings.local/DJANGO_SETTINGS_MODULE=config.settings.production/g .env
@sed -i.bak s/DJANGO_DEBUG=True/DJANGO_DEBUG=False/g .env
@docker-compose -f docker-compose.yml up --build
this way its idempotent. It doesnt matter if you are already on dev
environment, it will work as expected and it will change seamlessly to production in one command.
This is a great addition. Is there a particular reason why is only for local? I would also find this useful in production. |
Maybe a better alternative would be fabric instead? Similar idea/interface as Make, but in Python, so easier to maintain IMO. |
Would help if we want to enable more advanced things like #1133 |
You can grab some commands from here if you like:
|
@browniebroke I've updated my code comment (manage action had a bug) |
I personally like @pySilver offered option, it's a nice addition. |
@areski I'm using this for a long time and it is really helpful |
This PR seems abandonded, but if someone can put together a new one based on enhancements, I'll look at it. |
i find this useful! thanks |
Was looking into |
Yes I agree. Another benefit would be to have a more cross-platform tool, I don't think that |
Description
I use Makefile with docker to make it simpler call the frequent actions used in daily django development.
I've added the most frequent one. Hope it helps.
Rationale
It's not really needed but i think it saves time and remembering large commands.
Use case(s) / visualization(s)
write "make build" to set up the docker container
write "make up" to start container
write "make manage COMMAND" to call to any django command