Skip to content
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

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 13 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
up:
@docker-compose -f local.yml up

build:
@docker-compose -f local.yml up --force-recreate --build
Copy link
Member

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?


manage:
@docker-compose -f local.yml run --rm django python ./manage.py $(filter-out $@,$(MAKECMDGOALS)) --settings=config.settings.local
Copy link
Member

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.

Copy link

@elyak123 elyak123 Mar 20, 2019

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.


# https://stackoverflow.com/a/6273809/1826109
%:
@: