diff --git a/roles/web-app-discourse/handlers/main.yml b/roles/web-app-discourse/handlers/main.yml index 524a11676f..94708c8d57 100644 --- a/roles/web-app-discourse/handlers/main.yml +++ b/roles/web-app-discourse/handlers/main.yml @@ -1,5 +1,21 @@ --- +- name: "๐Ÿ”จ Bootstrap the stack host image" + include_tasks: stack_host.yml + vars: + DISCOURSE_LAUNCHER_ACTION: rebuild + when: IS_STACK_HOST | bool + listen: rebuild-discourse + +- name: "๐Ÿ“ Record that the bootstrap already recreated the container" + ansible.builtin.set_fact: + DISCOURSE_REBUILT: true + listen: rebuild-discourse + - name: "๐Ÿ–ฅ๏ธ Handle stack host" include_tasks: stack_host.yml - when: IS_STACK_HOST | bool + vars: + DISCOURSE_LAUNCHER_ACTION: start + when: + - IS_STACK_HOST | bool + - not DISCOURSE_REBUILT | bool listen: recreate-discourse diff --git a/roles/web-app-discourse/handlers/stack_host.yml b/roles/web-app-discourse/handlers/stack_host.yml index 067ad6ac64..e6b013829d 100644 --- a/roles/web-app-discourse/handlers/stack_host.yml +++ b/roles/web-app-discourse/handlers/stack_host.yml @@ -25,9 +25,9 @@ - DISCOURSE_DATABASE_IS_SHARED | bool - DEPLOYMENT_MODE == 'compose' -- name: ๐Ÿ”จ rebuild discourse +- name: "๐Ÿ”จ {{ DISCOURSE_LAUNCHER_ACTION }} discourse" shell: > - ./launcher rebuild {{ DISCOURSE_CONTAINER }} + ./launcher {{ DISCOURSE_LAUNCHER_ACTION }} {{ DISCOURSE_CONTAINER }} {% if DOCKER_IN_CONTAINER | bool %}--skip-prereqs{% endif %} args: executable: /bin/bash diff --git a/roles/web-app-discourse/tasks/03_launcher.yml b/roles/web-app-discourse/tasks/03_launcher.yml index 6a692add06..63187b289d 100644 --- a/roles/web-app-discourse/tasks/03_launcher.yml +++ b/roles/web-app-discourse/tasks/03_launcher.yml @@ -1,4 +1,10 @@ --- +# Exception: set_fact outlives the play, so the guard the recreate handler +# reads has to be cleared per role run or a stale true silently skips it. +- name: "๐Ÿงน Clear the bootstrap marker of an earlier play" + ansible.builtin.set_fact: + DISCOURSE_REBUILT: false + - name: โฌ‡๏ธ Pull Discourse docker repository git: repo: "{{ DISCOURSE_REPOSITORY_URL }}" @@ -10,7 +16,7 @@ retries: 12 delay: 30 until: discourse_repo_pull is succeeded - notify: recreate-discourse + notify: rebuild-discourse become: true - name: ๐Ÿ”ง set chmod 700 for '{{ DISCOURSE_CONTAINERS_DIR }}' @@ -26,6 +32,15 @@ mode: "0640" notify: recreate-discourse +# Exception: launcher reads env: on every docker run but consumes templates, +# params and hooks only during bootstrap, so only their digest may rebuild. +- name: "๐Ÿ”‘ Record the digest of everything the bootstrap consumes" + stack_host_copy: + content: "{{ lookup('template', 'config.yml.j2') | from_yaml | dict2items | rejectattr('key', 'eq', 'env') | items2dict | to_json | hash('sha256') }}" + dest: "{{ DISCOURSE_BOOTSTRAP_DIGEST_DEST }}" + mode: "0640" + notify: rebuild-discourse + - name: "โœ… Verify that '{{ DISCOURSE_CONTAINER }}' is running" ansible.builtin.command: argv: @@ -40,7 +55,7 @@ register: docker_ps changed_when: docker_ps.stdout.strip() == "" failed_when: docker_ps.rc != 0 - notify: recreate-discourse + notify: rebuild-discourse - name: ๐Ÿ“‚ Load discourse handlers explicitly include_tasks: utils/load/handlers.yml diff --git a/roles/web-app-discourse/vars/main.yml b/roles/web-app-discourse/vars/main.yml index 909fb515cc..f768e247aa 100644 --- a/roles/web-app-discourse/vars/main.yml +++ b/roles/web-app-discourse/vars/main.yml @@ -30,6 +30,8 @@ DISCOURSE_CONTAINERS_DIR: "{{ [ DISCOURSE_REPOSITORY_DIR, 'containers' ] | path_ DISCOURSE_APPLICATION_YML_DEST: "{{ [ DISCOURSE_CONTAINERS_DIR, DISCOURSE_CONTAINER ~ '.yml' ] | path_join }}" +DISCOURSE_BOOTSTRAP_DIGEST_DEST: "{{ [ DISCOURSE_CONTAINERS_DIR, DISCOURSE_CONTAINER ~ '.bootstrap.sha256' ] | path_join }}" + DISCOURSE_LDAP_ENABLED: "{{ lookup('config', application_id, 'services.ldap.enabled') }}" DISCOURSE_LITELLM_ENABLED: "{{ lookup('config', application_id, 'services.litellm.enabled') | bool }}"