Skip to content

Commit

Permalink
Merge pull request #54 from chnm/feature/docker-compose
Browse files Browse the repository at this point in the history
merge feature/docker-compose into main
  • Loading branch information
qtrinh2 authored Sep 13, 2024
2 parents 373394d + f7cc9cc commit eee784c
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 12 deletions.
4 changes: 2 additions & 2 deletions docker-compose.yml
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
---
name: winterthur

services:
app:
build: .
image: "rrchnm/winterthur"
container_name: "winterthur-app"
ports:
- 8000:8000
volumes:
Expand Down Expand Up @@ -31,7 +32,6 @@ services:
condition: service_healthy
db:
image: postgres:16
container_name: "winterthur-db"
volumes:
- pg-data:/var/lib/postgresql/data
environment:
Expand Down
43 changes: 33 additions & 10 deletions docker-compose.yml.j2
Original file line number Diff line number Diff line change
@@ -1,10 +1,14 @@
# this is a Jinja2 template file used during the Ansible deployment
# environment specific configuration can be found in our Ansble scripts
---
name: {{ compose_stack_name }}

services:

{% set service = 'app' %}

app:
image: ghcr.io/{{ template.git.package.image_name }}:{{ template.git.package.tag }}
container_name: {{ template.name }}_app
restart: unless-stopped
ports:
- "{{ template.env.host_app_port }}:8000"
Expand All @@ -26,22 +30,41 @@ services:
command: >
sh -c "poetry run python3 manage.py migrate &&
poetry run python3 manage.py runserver 0.0.0.0:8000"
{% if template.volumes is defined %}
{% set vols = (template.volumes | selectattr('service', 'eq', service)) %}
{% if vols is iterable and vols | length > 0 %}

volumes:
- dj-static:/app/staticfiles
{% for vol in vols %}

- {{ vol.name }}:{{ vol.container_path }}
{% endfor %}
{% endif %}
{% endif %}

depends_on:
db:
condition: service_healthy

db:
image: postgres:12
container_name: {{ template.name }}_db
restart: unless-stopped
volumes:
- pg-data:/var/lib/postgresql/data/
environment:
- POSTGRES_DB={{ template.env.db_name }}
- POSTGRES_USER={{ template.env.db_user }}
- POSTGRES_PASSWORD={{ template.env.db_pass }}
- POSTGRES_HOST=db
{% if template.volumes is defined %}
{% set vols = (template.volumes | selectattr('service', 'eq', service)) %}
{% if vols is iterable and vols | length > 0 %}

volumes:
{% for vol in vols %}

- {{ vol.name }}:{{ vol.container_path }}
{% endfor %}
{% endif %}
{% endif %}
healthcheck:
test: ["CMD-SHELL", "pg_isready -U {{ template.env.db_user }}"]
interval: 5s
Expand All @@ -50,9 +73,9 @@ services:

# external volumes managed and defined by ansible
volumes:
dj-static:
name: "{{ template.name }}_app-static-vol"
external: true
pg-data:
name: "{{ template.name }}_db-vol"
{% for vol in template.volumes %}

{{ vol.name }}:
name: "{{ compose_stack_name }}--{{ vol.name }}"
external: true
{% endfor %}

0 comments on commit eee784c

Please sign in to comment.