From a4a806199858d4948670ae404a06353905a3a249 Mon Sep 17 00:00:00 2001 From: Kevin Veen-Birkenbach Date: Fri, 19 Sep 2025 19:13:44 +0200 Subject: [PATCH] Refactor: unify Docker build config via build.yml.j2 include Replaced duplicated inline build definitions in multiple docker-compose.yml.j2 templates with a shared include (roles/docker-container/templates/build.yml.j2). This ensures consistent use of pull_policy: never and Dockerfile context across services (Postgres, Bookwyrm, Bridgy Fed, Chess, Confluence, Jira, Moodle, OpenProject, Pretix, Roulette Wheel, WordPress, XWiki, Simpleicons). Conversation: https://chatgpt.com/share/68cd8f35-b764-800f-9b00-2c837103d2fb --- roles/docker-container/templates/build.yml.j2 | 6 ++++++ roles/svc-db-postgres/templates/docker-compose.yml.j2 | 5 +---- roles/web-app-bookwyrm/templates/docker-compose.yml.j2 | 4 +--- roles/web-app-bridgy-fed/templates/docker-compose.yml.j2 | 4 +--- roles/web-app-chess/templates/docker-compose.yml.j2 | 4 +--- roles/web-app-confluence/templates/docker-compose.yml.j2 | 4 +--- roles/web-app-jira/templates/docker-compose.yml.j2 | 4 +--- roles/web-app-moodle/templates/docker-compose.yml.j2 | 5 +---- roles/web-app-openproject/templates/docker-compose.yml.j2 | 6 ++---- roles/web-app-pretix/templates/docker-compose.yml.j2 | 4 +--- .../web-app-roulette-wheel/templates/docker-compose.yml.j2 | 4 +--- roles/web-app-wordpress/templates/docker-compose.yml.j2 | 4 +--- roles/web-app-xwiki/templates/docker-compose.yml.j2 | 4 +--- roles/web-svc-simpleicons/templates/docker-compose.yml.j2 | 5 +---- 14 files changed, 20 insertions(+), 43 deletions(-) create mode 100644 roles/docker-container/templates/build.yml.j2 diff --git a/roles/docker-container/templates/build.yml.j2 b/roles/docker-container/templates/build.yml.j2 new file mode 100644 index 00000000..9ca01adc --- /dev/null +++ b/roles/docker-container/templates/build.yml.j2 @@ -0,0 +1,6 @@ +{# integrate it into service sections to be build by Dockerfile #} + pull_policy: never + build: + context: . + dockerfile: Dockerfile +{# pass Arguments here #} \ No newline at end of file diff --git a/roles/svc-db-postgres/templates/docker-compose.yml.j2 b/roles/svc-db-postgres/templates/docker-compose.yml.j2 index f3328bc7..80e23d90 100644 --- a/roles/svc-db-postgres/templates/docker-compose.yml.j2 +++ b/roles/svc-db-postgres/templates/docker-compose.yml.j2 @@ -3,10 +3,7 @@ postgres: container_name: "{{ POSTGRES_CONTAINER }}" image: "{{ POSTGRES_CUSTOM_IMAGE_NAME }}" - build: - context: . - dockerfile: Dockerfile - pull_policy: never +{% include 'roles/docker-container/templates/build.yml.j2' %} command: - "postgres" - "-c" diff --git a/roles/web-app-bookwyrm/templates/docker-compose.yml.j2 b/roles/web-app-bookwyrm/templates/docker-compose.yml.j2 index 95c558b0..2b7aa39b 100644 --- a/roles/web-app-bookwyrm/templates/docker-compose.yml.j2 +++ b/roles/web-app-bookwyrm/templates/docker-compose.yml.j2 @@ -9,9 +9,7 @@ (python manage.py initdb || true) && python -m gunicorn bookwyrm.wsgi:application --bind 0.0.0.0:{{ container_port }} ' - build: - context: . - dockerfile: Dockerfile +{% include 'roles/docker-container/templates/build.yml.j2' %} image: "{{ BOOKWYRM_CUSTOM_IMAGE }}" container_name: "{{ BOOKWYRM_CONTAINER }}" hostname: "{{ BOOKWYRM_HOSTNAME }}" diff --git a/roles/web-app-bridgy-fed/templates/docker-compose.yml.j2 b/roles/web-app-bridgy-fed/templates/docker-compose.yml.j2 index 27f4e699..84999e13 100644 --- a/roles/web-app-bridgy-fed/templates/docker-compose.yml.j2 +++ b/roles/web-app-bridgy-fed/templates/docker-compose.yml.j2 @@ -1,9 +1,7 @@ {% include 'roles/docker-compose/templates/base.yml.j2' %} application: - build: - context: . - dockerfile: Dockerfile +{% include 'roles/docker-container/templates/build.yml.j2' %} args: BRIDGY_REPO_URL: "{{ BRIDGY_REPO_URL }}" BRIDGY_REPO_BRANCH: "{{ BRIDGY_REPO_BRANCH }}" diff --git a/roles/web-app-chess/templates/docker-compose.yml.j2 b/roles/web-app-chess/templates/docker-compose.yml.j2 index 59412d4e..576e0e0b 100644 --- a/roles/web-app-chess/templates/docker-compose.yml.j2 +++ b/roles/web-app-chess/templates/docker-compose.yml.j2 @@ -1,8 +1,6 @@ {% include 'roles/docker-compose/templates/base.yml.j2' %} application: - build: - context: . - dockerfile: Dockerfile +{% include 'roles/docker-container/templates/build.yml.j2' %} args: CHESS_VERSION: "{{ CHESS_VERSION }}" CHESS_REPO_URL: "{{ CHESS_REPO_URL }}" diff --git a/roles/web-app-confluence/templates/docker-compose.yml.j2 b/roles/web-app-confluence/templates/docker-compose.yml.j2 index dbc74b2d..96700ae6 100644 --- a/roles/web-app-confluence/templates/docker-compose.yml.j2 +++ b/roles/web-app-confluence/templates/docker-compose.yml.j2 @@ -1,8 +1,6 @@ {% include 'roles/docker-compose/templates/base.yml.j2' %} application: - build: - context: . - dockerfile: Dockerfile +{% include 'roles/docker-container/templates/build.yml.j2' %} image: "{{ CONFLUENCE_CUSTOM_IMAGE }}" container_name: "{{ CONFLUENCE_CONTAINER }}" hostname: '{{ CONFLUENCE_HOSTNAME}}' diff --git a/roles/web-app-jira/templates/docker-compose.yml.j2 b/roles/web-app-jira/templates/docker-compose.yml.j2 index a854cb56..353c2c31 100644 --- a/roles/web-app-jira/templates/docker-compose.yml.j2 +++ b/roles/web-app-jira/templates/docker-compose.yml.j2 @@ -1,9 +1,7 @@ {% include 'roles/docker-compose/templates/base.yml.j2' %} application: - build: - context: . - dockerfile: Dockerfile +{% include 'roles/docker-container/templates/build.yml.j2' %} image: "{{ JIRA_CUSTOM_IMAGE }}" container_name: "{{ JIRA_CONTAINER }}" hostname: '{{ JIRA_HOSTNAME }}' diff --git a/roles/web-app-moodle/templates/docker-compose.yml.j2 b/roles/web-app-moodle/templates/docker-compose.yml.j2 index 9f853533..756e7ba9 100644 --- a/roles/web-app-moodle/templates/docker-compose.yml.j2 +++ b/roles/web-app-moodle/templates/docker-compose.yml.j2 @@ -3,10 +3,7 @@ moodle: {% set container_port = 8080 %} container_name: {{ moodle_container }} - build: - context: . - dockerfile: Dockerfile - pull_policy: never +{% include 'roles/docker-container/templates/build.yml.j2' %} image: moodle_custom ports: - 127.0.0.1:{{ ports.localhost.http[application_id] }}:{{ container_port }} diff --git a/roles/web-app-openproject/templates/docker-compose.yml.j2 b/roles/web-app-openproject/templates/docker-compose.yml.j2 index e263c745..ea132de6 100644 --- a/roles/web-app-openproject/templates/docker-compose.yml.j2 +++ b/roles/web-app-openproject/templates/docker-compose.yml.j2 @@ -3,10 +3,7 @@ x-op-app: &app logging: driver: journald image: {{ openproject_custom_image }} - build: - context: . - dockerfile: Dockerfile - pull_policy: never +{% include 'roles/docker-container/templates/build.yml.j2' %} {% include 'roles/docker-compose/templates/base.yml.j2' %} @@ -19,6 +16,7 @@ x-op-app: &app {% include 'roles/docker-container/templates/base.yml.j2' %} image: {{ openproject_custom_image }} container_name: {{ openproject_proxy_name }} + pull_policy: never command: "./docker/prod/proxy" ports: - "127.0.0.1:{{ ports.localhost.http[application_id] }}:80" diff --git a/roles/web-app-pretix/templates/docker-compose.yml.j2 b/roles/web-app-pretix/templates/docker-compose.yml.j2 index 0136b770..65e2ae14 100644 --- a/roles/web-app-pretix/templates/docker-compose.yml.j2 +++ b/roles/web-app-pretix/templates/docker-compose.yml.j2 @@ -1,8 +1,6 @@ {% include 'roles/docker-compose/templates/base.yml.j2' %} application: - build: - context: . - dockerfile: Dockerfile +{% include 'roles/docker-container/templates/build.yml.j2' %} image: "{{ PRETIX_IMAGE_CUSTOM }}" container_name: "{{ PRETIX_CONTAINER }}" hostname: '{{ PRETIX_HOSTNAME}}' diff --git a/roles/web-app-roulette-wheel/templates/docker-compose.yml.j2 b/roles/web-app-roulette-wheel/templates/docker-compose.yml.j2 index 2eba3459..86bf14fb 100644 --- a/roles/web-app-roulette-wheel/templates/docker-compose.yml.j2 +++ b/roles/web-app-roulette-wheel/templates/docker-compose.yml.j2 @@ -1,9 +1,7 @@ {% include 'roles/docker-compose/templates/base.yml.j2' %} application: container_name: roulette_application - build: - context: . - pull_policy: never +{% include 'roles/docker-container/templates/build.yml.j2' %} ports: - 127.0.0.1:{{ ports.localhost.http[application_id] }}:8080 restart: {{ DOCKER_RESTART_POLICY }} diff --git a/roles/web-app-wordpress/templates/docker-compose.yml.j2 b/roles/web-app-wordpress/templates/docker-compose.yml.j2 index 97b5e6e5..47b46586 100644 --- a/roles/web-app-wordpress/templates/docker-compose.yml.j2 +++ b/roles/web-app-wordpress/templates/docker-compose.yml.j2 @@ -3,9 +3,7 @@ {% include 'roles/docker-container/templates/base.yml.j2' %} image: {{ WORDPRESS_CUSTOM_IMAGE }} container_name: {{ WORDPRESS_CONTAINER }} - build: - context: . - pull_policy: never +{% include 'roles/docker-container/templates/build.yml.j2' %} ports: - "127.0.0.1:{{ ports.localhost.http[application_id] }}:80" volumes: diff --git a/roles/web-app-xwiki/templates/docker-compose.yml.j2 b/roles/web-app-xwiki/templates/docker-compose.yml.j2 index c9c6b3bb..9c688c70 100644 --- a/roles/web-app-xwiki/templates/docker-compose.yml.j2 +++ b/roles/web-app-xwiki/templates/docker-compose.yml.j2 @@ -1,8 +1,6 @@ {% include 'roles/docker-compose/templates/base.yml.j2' %} application: - build: - context: . - dockerfile: Dockerfile +{% include 'roles/docker-container/templates/build.yml.j2' %} image: "{{ XWIKI_IMAGE_CUSTOM }}" container_name: "{{ XWIKI_CONTAINER }}" hostname: '{{ XWIKI_HOSTNAME}}' diff --git a/roles/web-svc-simpleicons/templates/docker-compose.yml.j2 b/roles/web-svc-simpleicons/templates/docker-compose.yml.j2 index eca0e6d5..811625b5 100644 --- a/roles/web-svc-simpleicons/templates/docker-compose.yml.j2 +++ b/roles/web-svc-simpleicons/templates/docker-compose.yml.j2 @@ -1,9 +1,6 @@ {% include 'roles/docker-compose/templates/base.yml.j2' %} application: - build: - context: . - dockerfile: Dockerfile - pull_policy: never +{% include 'roles/docker-container/templates/build.yml.j2' %} image: simpleicons-server:latest container_name: simpleicons-server ports: