Skip to content

Commit fb11a8c

Browse files
committed
use volumes instead of data container
1 parent bcbe112 commit fb11a8c

File tree

10 files changed

+168
-197
lines changed

10 files changed

+168
-197
lines changed

README.md

Lines changed: 16 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -31,32 +31,34 @@ A [`cookiecutter`](https://github.com/audreyr/cookiecutter) template for Django/
3131
## Usage
3232
* Build the images: ```bash buildall.sh```
3333
* Start the project: ```docker-compose up ```
34-
* You can set every secret variable in the ```env.txt``` in the root
34+
* You can set every secret variable in the ```.secret``` in the root
3535
* If you want to run the project in production mode you need to set the following environment variable:
3636
* ```COMPOSE_FILE="production-docker-compose.yml"```
3737
* https://docs.docker.com/compose/reference/overview/#compose-file
3838

3939
## Tips & Tricks
4040
* Every image has a container_shared directory linked as a volume, so if you want to put something inside the container, or
41-
you want to get something from inside the containers like a backup file you just need to copy everything to this directory.
41+
you want to get something from the containers like a backup file you just need to copy everything into this directory.
4242
* Create a bash alias for for the docker-compose by edit the ```.bash_aliases``` file ```alias dc='docker-compose'```
43-
* Enter the container as root: ```dc run --rm proxy shell root```
43+
* Enter the container as root: ```dc run --rm postgres shell root```
4444
* You can use vim in every container.
4545
* https://www.digitalocean.com/community/tutorials/how-to-add-swap-on-ubuntu-14-04
4646
* better prompt: https://github.com/vertisfinance/gitprompt
4747

48+
## Volumes
49+
- The data volume, automatically created on the first start, which will contains every data.
50+
- You can find it in every container in here: ```/data/```
51+
4852
## Images
49-
1. base
50-
* Contains every data(db, files, logs) and connected to every other container as a volume (/data/).
51-
* If you delete the base container you will lose everything (be cautious)
52-
2. postgres
53+
1. postgres
5354
* postgresql-9.4
5455
* The 5433 port is open by default if you want to connect the db with a client
5556
* Commands:
57+
* start - start the database
5658
* shell - start a bash shell ```dc run --rm postgres shell```
5759
* backup - create a backup (```/data/backup/<backup_name>```) ```dc run --rm postgres backup```
5860
* restore - restore from a backup (```/data/backup/<backup_name>```) ```dc run --rm postgres restore```
59-
3. django-python3
61+
2. django-python3
6062
* The projects can be found under the /src/ directory
6163
* Installed Apps:
6264
* Django: 1.10.1
@@ -71,15 +73,18 @@ you want to get something from inside the containers like a backup file you just
7173
* django-modeltranslation: 0.11 [optional]
7274
* Commands:
7375
* shell -start a bash shell ```dc run --rm django shell```
74-
4. nginx
76+
* start_runserver - in development mode this will start django runserver
77+
* start_uwsgi - in production mode this will start the uwsgi
78+
3. nginx
7579
* Commands:
7680
* shell -start a bash shell ```dc run --rm nginx shell```
7781
* Installed Apps:
7882
* Nginx: 1.8.1
79-
5. nodejs [optional]
83+
4. nodejs [optional]
8084
* Commands:
8185
* shell -start a bash shell ```dc run --rm nodejs shell```
82-
* start_build -start the react build process than exit ```dc run --rm nodejs start_build```
86+
* start_build - start the react build process than exit ```dc run --rm nodejs start_build```
87+
* start_watchify - start the watchify process for the development mode
8388
* Installed Apps:
8489
* nodejs: 4.x.x
8590
* npm: 2.x.x

{{cookiecutter.repo_name}}/.secret

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
DJANGO_SECRET_KEY={SECRET_KEY}
22
DB_PASSWORD={{cookiecutter.db_password}}
3-
DEBUG=True
43
ALLOWED_HOSTS=
54
YANDEX_TRANSLATE_KEY=
65
EMAIL_HOST_USER={{cookiecutter.email_host_user}}

{{cookiecutter.repo_name}}/buildall.sh

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,3 @@ echo "nodejs"
2424
echo "--------------------"
2525
docker build -t {{cookiecutter.repo_name}}-nodejs "docker/nodejs"
2626
{%- endif %}
27-
28-
echo 'Start the data container'
29-
echo "--------------------"
30-
docker-compose --file data-docker-compose.yml up -d

{{cookiecutter.repo_name}}/data-docker-compose.yml

Lines changed: 0 additions & 10 deletions
This file was deleted.
Lines changed: 67 additions & 66 deletions
Original file line numberDiff line numberDiff line change
@@ -1,69 +1,70 @@
1-
proxy:
2-
hostname: {{cookiecutter.repo_name}}-proxy
3-
image: {{cookiecutter.repo_name}}-base
4-
command: start
5-
volumes_from:
6-
- {{cookiecutter.repo_name}}-data
7-
entrypoint: ['python3', '/config/run.py']
1+
version: '2'
82

9-
postgres:
10-
hostname: {{cookiecutter.repo_name}}-postgres
11-
image: {{cookiecutter.repo_name}}-postgres
12-
command: start
13-
volumes_from:
14-
- proxy
15-
volumes:
16-
- "./docker/postgres/config:/config"
17-
- "./container_shared:/container_shared"
18-
log_opt:
19-
max-size: "5m"
20-
max-file: "1"
21-
entrypoint: ['python3', '/config/run.py']
22-
environment:
23-
PGDATA: /data/postgres
24-
env_file: .secret
25-
ports:
26-
- "5433:5432"
3+
volumes:
4+
{{cookiecutter.repo_name}}-data-volume:
5+
driver: local
276

28-
django:
29-
hostname: {{cookiecutter.repo_name}}-django
30-
image: {{cookiecutter.repo_name}}-django-python3
31-
entrypoint: ['python3', '/config/run.py']
32-
command: start_runserver
33-
user: developer
34-
volumes_from:
35-
- proxy
36-
volumes:
37-
- "./src:/src"
38-
- "./docker/django-python3/config:/config"
39-
- "./container_shared:/container_shared"
40-
links:
41-
- "postgres:postgres"
42-
log_opt:
43-
max-size: "5m"
44-
max-file: "1"
45-
environment:
46-
PYTHONPATH: /src
47-
DJANGO_SETTINGS_MODULE: core.settings
48-
PYTHONUNBUFFERED: "true"
49-
env_file: .secret
50-
ports:
51-
- "80:8000"
7+
services:
8+
postgres:
9+
hostname: {{cookiecutter.repo_name}}-postgres
10+
image: {{cookiecutter.repo_name}}-postgres
11+
command: start
12+
volumes:
13+
- {{cookiecutter.repo_name}}-data-volume:/data
14+
- "./docker/postgres/config:/config"
15+
- "./container_shared:/container_shared"
16+
logging:
17+
options:
18+
max-size: "5m"
19+
max-file: "1"
20+
entrypoint: ['python3', '/config/run.py']
21+
environment:
22+
PGDATA: /data/postgres
23+
env_file: .secret
24+
ports:
25+
- "5433:5432"
5226

53-
{% if cookiecutter.use_react == 'True' -%}
54-
nodejs:
55-
hostname: {{cookiecutter.repo_name}}-nodejs
56-
image: {{cookiecutter.repo_name}}-nodejs
57-
command: start_watchify
58-
volumes_from:
59-
- proxy
60-
volumes:
61-
- "./docker/nodejs/config:/config"
62-
- "./container_shared:/container_shared"
63-
- "./react:/react"
64-
- "./src:/src"
65-
log_opt:
66-
max-size: "5m"
67-
max-file: "1"
68-
entrypoint: ['python3', '/config/run.py']
69-
env_file: .secret{% endif -%}
27+
django:
28+
hostname: {{cookiecutter.repo_name}}-django
29+
image: {{cookiecutter.repo_name}}-django-python3
30+
entrypoint: ['python3', '/config/run.py']
31+
command: start_runserver
32+
user: developer
33+
volumes:
34+
- {{cookiecutter.repo_name}}-data-volume:/data
35+
- "./src:/src"
36+
- "./docker/django-python3/config:/config"
37+
- "./container_shared:/container_shared"
38+
links:
39+
- "postgres:postgres"
40+
logging:
41+
options:
42+
max-size: "5m"
43+
max-file: "1"
44+
environment:
45+
PYTHONPATH: /src
46+
DJANGO_SETTINGS_MODULE: core.settings
47+
PYTHONUNBUFFERED: "True"
48+
DEBUG: "True"
49+
env_file: .secret
50+
ports:
51+
- "80:8000"
52+
53+
{% if cookiecutter.use_react == 'True' -%}
54+
nodejs:
55+
hostname: {{cookiecutter.repo_name}}-nodejs
56+
image: {{cookiecutter.repo_name}}-nodejs
57+
command: start_watchify
58+
volumes:
59+
- {{cookiecutter.repo_name}}-data-volume:/data
60+
- "./docker/nodejs/config:/config"
61+
- "./container_shared:/container_shared"
62+
- "./react:/react"
63+
- "./src:/src"
64+
logging:
65+
options:
66+
max-size: "5m"
67+
max-file: "1"
68+
entrypoint: ['python3', '/config/run.py']
69+
env_file: .secret
70+
{% endif -%}

{{cookiecutter.repo_name}}/docker/base/config/run.py

Lines changed: 0 additions & 26 deletions
This file was deleted.

{{cookiecutter.repo_name}}/docker/django-python3/config/run.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,7 @@ def generate_makemessages_command(domain):
4444

4545
# INIT: WILL RUN BEFORE ANY COMMAND AND START #
4646
def init(stopper):
47+
ensure_dir('/data/logs/', owner='developer', group='developer')
4748
ensure_dir('/data/logs/django', owner='developer', group='developer')
4849
ensure_dir('/data/static', owner='developer', group='developer')
4950
{% if cookiecutter.use_translation == 'True' -%}
@@ -58,7 +59,6 @@ def init(stopper):
5859
cmd = ['django-admin', 'collectstatic', '--noinput']
5960
{% endif -%}
6061
run_cmd(cmd, user='developer')
61-
run_cmd(['django-admin', 'migrate'], user='developer')
6262

6363
# Create db cache
6464
if os.path.isfile('/data/.init') is False:

{{cookiecutter.repo_name}}/docker/nginx/config/run.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88

99
@click.group()
1010
def run():
11+
ensure_dir('/data/logs/', owner='developer', group='developer')
1112
ensure_dir('/data/logs/nginx/', owner='developer', group='developer')
1213

1314

{{cookiecutter.repo_name}}/docker/postgres/config/run.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -133,6 +133,7 @@ def _restore(backupname):
133133
# INIT: WILL RUN BEFORE ANY COMMAND AND START #
134134
################################################
135135
def init(stopper=None):
136+
ensure_dir('/data/logs/', owner='developer', group='developer')
136137
ensure_dir(os.path.split(PGDATA)[0], owner='postgres', group='postgres')
137138
ensure_dir(SOCKET_DIR, owner='postgres', group='postgres')
138139
ensure_dir(BACKUP_DIR, owner='postgres', group='postgres')

0 commit comments

Comments
 (0)