From a4cd305d644e8283db61d866b246f8641e22ced6 Mon Sep 17 00:00:00 2001
From: qtrinh2 <qtrinh2@gmu.edu>
Date: Fri, 13 Sep 2024 15:31:02 -0400
Subject: [PATCH 1/2] added project name, removed container names

---
 docker-compose.yml | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/docker-compose.yml b/docker-compose.yml
index 7485497..3a3068e 100644
--- a/docker-compose.yml
+++ b/docker-compose.yml
@@ -1,9 +1,10 @@
 ---
+name: winterthur
+
 services:
   app:
     build: .
     image: "rrchnm/winterthur"
-    container_name: "winterthur-app"
     ports:
       - 8000:8000
     volumes:
@@ -31,7 +32,6 @@ services:
         condition: service_healthy
   db:
     image: postgres:16
-    container_name: "winterthur-db"
     volumes:
       - pg-data:/var/lib/postgresql/data
     environment:

From f7cc9ccc41ff4e0394df0516ff4382ed3c616615 Mon Sep 17 00:00:00 2001
From: qtrinh2 <qtrinh2@gmu.edu>
Date: Fri, 13 Sep 2024 15:33:49 -0400
Subject: [PATCH 2/2] 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
---
 docker-compose.yml.j2 | 43 +++++++++++++++++++++++++++++++++----------
 1 file changed, 33 insertions(+), 10 deletions(-)

diff --git a/docker-compose.yml.j2 b/docker-compose.yml.j2
index e50d869..d534706 100644
--- a/docker-compose.yml.j2
+++ b/docker-compose.yml.j2
@@ -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"
@@ -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
@@ -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 %}