--- # The application container starts through a repo-managed entrypoint so Apache # comes up first and the Ansible bootstrap can run without racing the image's # first-start migration logic. # Keep this wait at the top of the bootstrap flow. The later artisan commands # assume the repo-managed entrypoint has already brought Apache up. - name: "⏳ Wait until Pixelfed application container finished entrypoint bootstrap" ansible.builtin.command: argv: - container - exec - "{{ PIXELFED_LOCAL_CID }}" # nocheck: container-exec-resolver PIXELFED_LOCAL_CID resolved at delegate_to runtime - sh - -lc - 'ps -ef | grep -v grep | grep -q "apache2 -DFOREGROUND"' register: pixelfed_entrypoint_bootstrap changed_when: false retries: 120 delay: 5 until: pixelfed_entrypoint_bootstrap.rc == 0 delegate_to: "{{ PIXELFED_HOST_NODE }}" - name: "🔎 Check whether the Pixelfed bootstrap marker exists" ansible.builtin.command: argv: - container - exec - "{{ PIXELFED_LOCAL_CID }}" # nocheck: container-exec-resolver PIXELFED_LOCAL_CID resolved at delegate_to runtime - sh - -lc - test -e /var/www/storage/.docker.init register: pixelfed_bootstrap_marker_exists changed_when: false failed_when: false delegate_to: "{{ PIXELFED_HOST_NODE }}" - name: "🔎 Check whether the Pixelfed users table exists" database_query: config: "{{ lookup('database', application_id) }}" query_file: "{{ role_path }}/files/sql/select/users-table.sql" named_args: db_name: "{{ PIXELFED_DB_NAME }}" expect_rows: true mask_values: "{{ MASK_CREDENTIALS_IN_LOGS | bool }}" register: pixelfed_bootstrap_users_table changed_when: false retries: 20 delay: 3 until: pixelfed_bootstrap_users_table is success no_log: "{{ MASK_CREDENTIALS_IN_LOGS | bool }}" - name: "👥 Count existing Pixelfed users when the users table already exists" database_query: config: "{{ lookup('database', application_id) }}" query_file: "{{ role_path }}/files/sql/count-users.sql" expect_rows: true mask_values: "{{ MASK_CREDENTIALS_IN_LOGS | bool }}" when: pixelfed_bootstrap_users_table.rows | length > 0 register: pixelfed_bootstrap_user_count changed_when: false retries: 20 delay: 3 until: pixelfed_bootstrap_user_count is success no_log: "{{ MASK_CREDENTIALS_IN_LOGS | bool }}" - name: "🚚 Choose Pixelfed migration strategy" ansible.builtin.set_fact: pixelfed_bootstrap_requires_reset: >- {{ (pixelfed_bootstrap_marker_exists.rc | default(1) | int) != 0 and ((pixelfed_bootstrap_user_count.rows[0][0] | default('0')) | int) == 0 }} pixelfed_migrate_argv: >- {{ ['container', 'exec', '-u', PIXELFED_APP_USER, PIXELFED_LOCAL_CID, 'php', 'artisan'] + ( ['migrate:fresh', '--force'] if ( (pixelfed_bootstrap_marker_exists.rc | default(1) | int) != 0 and ((pixelfed_bootstrap_user_count.rows[0][0] | default('0')) | int) == 0 ) else ['migrate', '--force', '--isolated'] ) }} - name: "▶️ Run Pixelfed migrations" ansible.builtin.command: argv: "{{ pixelfed_migrate_argv }}" register: pixelfed_migrate changed_when: "'Nothing to migrate' not in pixelfed_migrate.stdout" retries: 60 delay: 5 until: pixelfed_migrate.rc == 0 delegate_to: "{{ PIXELFED_HOST_NODE }}" - name: "✅ Ensure Pixelfed Passport keys exist" ansible.builtin.command: argv: - container - exec - -u - "{{ PIXELFED_APP_USER }}" - "{{ PIXELFED_LOCAL_CID }}" # nocheck: container-exec-resolver PIXELFED_LOCAL_CID resolved at delegate_to runtime - sh - -lc - | if [ ! -f /var/www/storage/oauth-private.key ] || [ ! -f /var/www/storage/oauth-public.key ]; then php artisan passport:keys --force fi register: pixelfed_passport_keys changed_when: false retries: 20 delay: 5 until: pixelfed_passport_keys.rc == 0 delegate_to: "{{ PIXELFED_HOST_NODE }}" - name: "✅ Ensure the Pixelfed public storage symlink exists" ansible.builtin.command: argv: - container - exec - -u - "{{ PIXELFED_APP_USER }}" - "{{ PIXELFED_LOCAL_CID }}" # nocheck: container-exec-resolver PIXELFED_LOCAL_CID resolved at delegate_to runtime - sh - -lc - | if [ ! -L /var/www/public/storage ]; then php artisan storage:link fi register: pixelfed_storage_link changed_when: false retries: 20 delay: 5 until: pixelfed_storage_link.rc == 0 delegate_to: "{{ PIXELFED_HOST_NODE }}" - name: "🎬 Initialize the Pixelfed instance actor" ansible.builtin.command: argv: - container - exec - -u - "{{ PIXELFED_APP_USER }}" - "{{ PIXELFED_LOCAL_CID }}" # nocheck: container-exec-resolver PIXELFED_LOCAL_CID resolved at delegate_to runtime - php - artisan - instance:actor register: pixelfed_instance_actor changed_when: false retries: 20 delay: 5 until: pixelfed_instance_actor.rc == 0 delegate_to: "{{ PIXELFED_HOST_NODE }}" - name: "🏷️ Mark Pixelfed bootstrap as complete for the worker container" ansible.builtin.command: argv: - container - exec - -u - "{{ PIXELFED_APP_USER }}" - "{{ PIXELFED_LOCAL_CID }}" # nocheck: container-exec-resolver PIXELFED_LOCAL_CID resolved at delegate_to runtime - sh - -lc - | if [ ! -e /var/www/storage/.docker.init ]; then touch /var/www/storage/.docker.init fi register: pixelfed_bootstrap_marker changed_when: false retries: 20 delay: 5 until: pixelfed_bootstrap_marker.rc == 0 delegate_to: "{{ PIXELFED_HOST_NODE }}"