Skip to content

Commit 2e2301b

Browse files
committed
Added Docker support
1 parent 2cd616d commit 2e2301b

10 files changed

+643
-14
lines changed

.gitignore

-1
Original file line numberDiff line numberDiff line change
@@ -3,5 +3,4 @@
33
*.pyc
44
.idea/
55

6-
{{ cookiecutter.project_slug }}/Pipfile.lock
76
todo_project_name/

.travis.yml

+7-2
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,13 @@
1+
sudo: required
2+
3+
services:
4+
- docker
5+
16
language: python
27

38
python:
49
- 3.6
510

6-
sudo: false
7-
811
cache: pip
912

1013
env:
@@ -16,3 +19,5 @@ install:
1619

1720
script:
1821
- make test
22+
- make test-static
23+
- make down

Makefile

+14-11
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,26 @@
11
.DEFAULT_GOAL := test
22

3-
.PHONY: requirements test
3+
.PHONY: down requirements test test-static
44

5-
requirements:
5+
requirements: ## Install the requirements needed to run Cookiecutter
66
pip install -r requirements.txt
7-
# TODO Restore once https://github.com/pypa/pipenv/issues/3224 is released
8-
# pip install pipenv
9-
pip install git+https://github.com/pypa/pipenv
107

11-
test:
8+
test: ## Ensure we can build and run a new project
129
# Remove any existing data
1310
rm -rf todo_project_name
1411

1512
# Create a new project with the default values
1613
cookiecutter . --no-input
1714

1815
# Execute the project's Make targets
19-
cd todo_project_name && make production-requirements requirements
20-
cd todo_project_name && SECRET_KEY=fake DATABASE_URL="sqlite://:memory:" pipenv run make detect_missing_migrations
21-
cd todo_project_name && SECRET_KEY=fake DATABASE_URL="sqlite://:memory:" pipenv run make migrate
22-
cd todo_project_name && pipenv run make validate
23-
cd todo_project_name && pipenv run make static
16+
cd todo_project_name && make docker.build
17+
cd todo_project_name && make local.up
18+
cd todo_project_name && docker exec -it todo_project_name.app make detect_missing_migrations
19+
cd todo_project_name && docker exec -it todo_project_name.app make migrate
20+
cd todo_project_name && docker exec -it todo_project_name.app make validate
21+
22+
test-static: ## Confirm nginx is serving static files
23+
curl -o /dev/null --fail --silent http://localhost:8080/static/admin/css/login.css
24+
25+
down: ## Shutdown the containers
26+
cd todo_project_name && make local.down

README.rst

+1
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ Features
1313
* Support for Python 3.6+
1414
* `12-Factor <https://12factor.net/>`_ based settings via `django-environ <https://django-environ.readthedocs.io/en/latest/>`_
1515
* Custom user model
16+
* Docker support
1617

1718

1819
Usage
+43
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
FROM python:3.6-alpine
2+
3+
WORKDIR /app/{{ cookiecutter.project_slug }}
4+
5+
ENV DJANGO_SETTINGS_MODULE {{ cookiecutter.project_slug }}.settings
6+
ENV PIPENV_DONT_USE_PYENV 1
7+
8+
RUN apk add --update \
9+
coreutils \
10+
gcc \
11+
libffi-dev \
12+
make \
13+
musl-dev \
14+
postgresql-dev \
15+
python3-dev \
16+
&& pip install pipenv \
17+
&& rm -rf /var/cache/apk/*
18+
19+
COPY Makefile /app/{{ cookiecutter.project_slug }}
20+
COPY Pipfile /app/{{ cookiecutter.project_slug }}
21+
COPY Pipfile.lock /app/{{ cookiecutter.project_slug }}
22+
23+
# TODO Switch to environment variable when https://github.com/pypa/pipenv/issues/3278 is resolved.
24+
RUN pipenv install --dev --system
25+
26+
COPY . /app/{{ cookiecutter.project_slug }}
27+
28+
RUN mkdir -p /logs \
29+
&& touch /logs/app.log
30+
31+
ENV PUBLIC_ROOT /public
32+
RUN make static
33+
34+
EXPOSE 8000
35+
36+
VOLUME /public/media
37+
VOLUME /public/static
38+
39+
40+
ENV LOG_FILE_PATH /logs
41+
ENV ENABLE_LOGGING_TO_FILE true
42+
ENV GUNICORN_CMD_ARGS "--workers=2 --worker-class=gevent --bind=0.0.0.0:8000"
43+
CMD ["gunicorn", "{{ cookiecutter.project_slug }}.wsgi"]

{{ cookiecutter.project_slug }}/Makefile

+17
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,23 @@ help: ## Display this help message
77
@echo "Please use \`make <target>\` where <target> is one of"
88
@perl -nle'print $& if m{^[\.a-zA-Z_-]+:.*?## .*$$}' $(MAKEFILE_LIST) | sort | awk 'BEGIN {FS = ":.*?## "}; {printf "\033[36m %-25s\033[0m %s\n", $$1, $$2}'
99

10+
docker.build: ## Build the Docker containers
11+
docker-compose build
12+
13+
docker.pull: ## Pull the Docker containers
14+
docker-compose pull
15+
16+
%.down: ## Stop the (local|production) Docker containers
17+
docker-compose -f docker-compose.yml -f docker-compose.$*.yml down
18+
19+
%.restart: ## Restart the (local|production) Docker containers
20+
docker-compose -f docker-compose.yml -f docker-compose.$*.yml restart
21+
22+
%.shell: ## Open a shell into the (local|production) app Docker container
23+
docker-compose -f docker-compose.yml -f docker-compose.$*.yml exec app /bin/ash
24+
25+
%.up: ## Start the (local|production) Docker containers
26+
docker-compose -f docker-compose.yml -f docker-compose.$*.yml up -d
1027

1128
clean: ## Delete generated byte code and coverage reports
1229
find . -name '*.pyc' -delete

0 commit comments

Comments
 (0)