From dfa5e2658245f11d5e930052f995c74cde6ab732 Mon Sep 17 00:00:00 2001 From: Kevin Veen-Birkenbach Date: Tue, 25 Nov 2025 18:34:11 +0100 Subject: [PATCH] Fix Mastodon role: run DB migrations before health checks, restructure setup/wait tasks, introduce service name variables, and update docker-compose templates. Reference: https://chatgpt.com/share/6925e87d-3e0c-800f-bfff-902d1faa122e --- roles/web-app-mastodon/tasks/01_setup.yml | 4 ++++ .../tasks/{01_wait.yml => 02_wait.yml} | 6 +++--- .../tasks/{02_cleanup.yml => 03_cleanup.yml} | 0 roles/web-app-mastodon/tasks/03_setup.yml | 3 --- roles/web-app-mastodon/tasks/main.yml | 10 +++++----- .../templates/docker-compose.yml.j2 | 12 ++++++------ roles/web-app-mastodon/vars/main.yml | 15 +++++++++++++-- 7 files changed, 31 insertions(+), 19 deletions(-) create mode 100644 roles/web-app-mastodon/tasks/01_setup.yml rename roles/web-app-mastodon/tasks/{01_wait.yml => 02_wait.yml} (76%) rename roles/web-app-mastodon/tasks/{02_cleanup.yml => 03_cleanup.yml} (100%) delete mode 100644 roles/web-app-mastodon/tasks/03_setup.yml diff --git a/roles/web-app-mastodon/tasks/01_setup.yml b/roles/web-app-mastodon/tasks/01_setup.yml new file mode 100644 index 00000000..6a8f4d47 --- /dev/null +++ b/roles/web-app-mastodon/tasks/01_setup.yml @@ -0,0 +1,4 @@ +- name: "Execute migration for '{{ application_id }}'" + command: + chdir: "{{ docker_compose.directories.instance }}" + cmd: "docker compose run --rm {{ MASTODON_SERVICE_NAME }} bundle exec rails db:migrate" diff --git a/roles/web-app-mastodon/tasks/01_wait.yml b/roles/web-app-mastodon/tasks/02_wait.yml similarity index 76% rename from roles/web-app-mastodon/tasks/01_wait.yml rename to roles/web-app-mastodon/tasks/02_wait.yml index 7a532a8f..1b5cd2b2 100644 --- a/roles/web-app-mastodon/tasks/01_wait.yml +++ b/roles/web-app-mastodon/tasks/02_wait.yml @@ -11,9 +11,9 @@ delay: 5 until: healthcheck.stdout == "healthy" loop: - - mastodon - - streaming - - sidekiq + - "{{ MASTODON_SERVICE_NAME }}" + - "{{ MASTODON_STREAMING_SERVICE_NAME }}" + - "{{ MASTODON_SIDEKIQ_SERVICE_NAME }}" loop_control: label: "{{ item }}" changed_when: false \ No newline at end of file diff --git a/roles/web-app-mastodon/tasks/02_cleanup.yml b/roles/web-app-mastodon/tasks/03_cleanup.yml similarity index 100% rename from roles/web-app-mastodon/tasks/02_cleanup.yml rename to roles/web-app-mastodon/tasks/03_cleanup.yml diff --git a/roles/web-app-mastodon/tasks/03_setup.yml b/roles/web-app-mastodon/tasks/03_setup.yml deleted file mode 100644 index 3efbcacc..00000000 --- a/roles/web-app-mastodon/tasks/03_setup.yml +++ /dev/null @@ -1,3 +0,0 @@ -- name: "Execute migration for '{{ application_id }}'" - command: - cmd: "docker exec {{ MASTODON_CONTAINER }} bundle exec rails db:migrate" diff --git a/roles/web-app-mastodon/tasks/main.yml b/roles/web-app-mastodon/tasks/main.yml index 2d163d1f..59021e27 100644 --- a/roles/web-app-mastodon/tasks/main.yml +++ b/roles/web-app-mastodon/tasks/main.yml @@ -18,15 +18,15 @@ vars: docker_compose_flush_handlers: true +- name: "start setup procedures for mastodon" + include_tasks: 01_setup.yml + - name: "Wait for Mastodon" - include_tasks: 01_wait.yml + include_tasks: 02_wait.yml - name: "Cleanup Mastodon caches when MODE_CLEANUP is true" - include_tasks: 02_cleanup.yml + include_tasks: 03_cleanup.yml when: MODE_CLEANUP | bool -- name: "start setup procedures for mastodon" - include_tasks: 03_setup.yml - - name: "Include administrator routines for '{{ application_id }}'" include_tasks: 04_administrator.yml diff --git a/roles/web-app-mastodon/templates/docker-compose.yml.j2 b/roles/web-app-mastodon/templates/docker-compose.yml.j2 index 8ea62da1..a98b2cff 100644 --- a/roles/web-app-mastodon/templates/docker-compose.yml.j2 +++ b/roles/web-app-mastodon/templates/docker-compose.yml.j2 @@ -1,9 +1,9 @@ {% include 'roles/docker-compose/templates/base.yml.j2' %} - mastodon: -{% set service_name = 'mastodon' %} +{% set service_name = MASTODON_SERVICE_NAME %} {% set container_port = 3000 %} {% set container_healthcheck = 'health' %} + {{ service_name }}: container_name: {{ MASTODON_CONTAINER }} image: "{{ MASTODON_IMAGE }}:{{ MASTODON_VERSION }}" {% include 'roles/docker-container/templates/base.yml.j2' %} @@ -16,10 +16,10 @@ - data:/mastodon/public/system {% include 'roles/docker-container/templates/networks.yml.j2' %} - streaming: -{% set service_name = 'streaming' %} +{% set service_name = MASTODON_STREAMING_SERVICE_NAME %} {% set container_port = 4000 %} {% set container_healthcheck = 'api/v1/streaming/health' %} + {{ service_name }}: container_name: {{ MASTODON_STREAMING_CONTAINER }} image: "{{ MASTODON_STREAMING_IMAGE }}:{{ MASTODON_STREAMING_VERSION }}" {% include 'roles/docker-container/templates/base.yml.j2' %} @@ -30,8 +30,8 @@ {% include 'roles/docker-container/templates/depends_on/dmbs_excl.yml.j2' %} {% include 'roles/docker-container/templates/networks.yml.j2' %} - sidekiq: -{% set service_name = 'sidekiq' %} +{% set service_name = MASTODON_SIDEKIQ_SERVICE_NAME %} + {{ service_name }}: container_name: {{ MASTODON_SIDEKIQ_CONTAINER }} image: "{{ MASTODON_IMAGE }}:{{ MASTODON_VERSION }}" {% include 'roles/docker-container/templates/base.yml.j2' %} diff --git a/roles/web-app-mastodon/vars/main.yml b/roles/web-app-mastodon/vars/main.yml index f33ebe2b..0e7c794e 100644 --- a/roles/web-app-mastodon/vars/main.yml +++ b/roles/web-app-mastodon/vars/main.yml @@ -2,13 +2,24 @@ application_id: "web-app-mastodon" database_type: "postgres" -# Mastodon Specific +# Mastodon + +## Main MASTODON_VERSION: "{{ applications | get_app_conf(application_id, 'docker.services.mastodon.version') }}" MASTODON_IMAGE: "{{ applications | get_app_conf(application_id, 'docker.services.mastodon.image') }}" MASTODON_CONTAINER: "{{ applications | get_app_conf(application_id, 'docker.services.mastodon.name') }}" MASTODON_VOLUME: "{{ applications | get_app_conf(application_id, 'docker.volumes.data') }}" +MASTODON_SERVICE_NAME: "mastodon" + +## Streaming MASTODON_STREAMING_VERSION: "{{ applications | get_app_conf(application_id, 'docker.services.streaming.version') }}" MASTODON_STREAMING_IMAGE: "{{ applications | get_app_conf(application_id, 'docker.services.streaming.image') }}" MASTODON_STREAMING_CONTAINER: "{{ applications | get_app_conf(application_id, 'docker.services.streaming.name') }}" -MASTODON_SIDEKIQ_CONTAINER: "{{ applications | get_app_conf(application_id, 'docker.services.mastodon.name') }}_sidekiq" +MASTODON_STREAMING_SERVICE_NAME: "streaming" + +## Sidekiq +MASTODON_SIDEKIQ_CONTAINER: "{{ applications | get_app_conf(application_id, 'docker.services.mastodon.name') }}-sidekiq" +MASTODON_SIDEKIQ_SERVICE_NAME: "sidekiq" + +## General MASTODON_ALLOWED_PRIVATE_ADDRESSES: "{{ networks.local['svc-db-postgres'].subnet if 'web-app-chess' in group_names else ''}}" \ No newline at end of file