Skip to content

Commit

Permalink
merge feature/docker-compose into main (#12)
Browse files Browse the repository at this point in the history
* removed container name, added project name

* docker compose template updates to support ansible docker deployment refactoring

- added project name
- removed container names
- volumes will only be defined in ansible host vars, so using a lot of jinja2 templating for volume definitions
  • Loading branch information
qtrinh2 authored Sep 16, 2024
1 parent dbc990e commit f692582
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 6 deletions.
3 changes: 2 additions & 1 deletion docker-compose.yml
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
name: ct-django

services:
app:
build: .
image: "rrchnm/ct-django"
container_name: "ct-app"
ports:
- "8000:8000"
environment:
Expand Down
27 changes: 22 additions & 5 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
ports:
- "{{ template.env.host_app_port }}:8000"
environment:
Expand All @@ -13,16 +17,29 @@ services:
- DJANGO_ALLOWED_HOSTS={{ template.env.allowed_hosts }}
- DJANGO_CSRF_TRUSTED_ORIGINS={{ template.env.trusted_origins }}
- SQLITE_PATH={{ template.env.sqlite_path }}
volumes:
- dj-sqlite:/db
command: >
sh -c "
poetry run python manage.py migrate &&
poetry run python 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:
{% for vol in vols %}

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


# external volumes managed and defined by ansible
volumes:
dj-sqlite:
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 f692582

Please sign in to comment.