fix: ensure PostgreSQL Staging Stack runs before app deployment + fix YAML parsing
Some checks failed
🚀 Build & Deploy Image / Determine Build Necessity (push) Successful in 27s
🚀 Build & Deploy Image / Auto-deploy to Staging (push) Failing after 1m6s
🚀 Build & Deploy Image / Auto-deploy to Production (push) Has been skipped
Security Vulnerability Scan / Check for Dependency Changes (push) Successful in 28s
🚀 Build & Deploy Image / Build Runtime Base Image (push) Successful in 10s
🚀 Build & Deploy Image / Run Tests & Quality Checks (push) Has been skipped
Security Vulnerability Scan / Composer Security Audit (push) Has been skipped
🚀 Build & Deploy Image / Build Docker Image (push) Successful in 13s
Some checks failed
🚀 Build & Deploy Image / Determine Build Necessity (push) Successful in 27s
🚀 Build & Deploy Image / Auto-deploy to Staging (push) Failing after 1m6s
🚀 Build & Deploy Image / Auto-deploy to Production (push) Has been skipped
Security Vulnerability Scan / Check for Dependency Changes (push) Successful in 28s
🚀 Build & Deploy Image / Build Runtime Base Image (push) Successful in 10s
🚀 Build & Deploy Image / Run Tests & Quality Checks (push) Has been skipped
Security Vulnerability Scan / Composer Security Audit (push) Has been skipped
🚀 Build & Deploy Image / Build Docker Image (push) Successful in 13s
- Fix YAML parsing error by quoting task name with colon - Add PostgreSQL Staging Stack check and auto-start for staging deployments - Ensures postgres-staging-internal network is created by the stack itself - Network creation remains as fallback if stack doesn't create them - Improves deployment reliability by ensuring dependencies are available This addresses the root cause: PostgreSQL Staging Stack should be running before the application stack tries to use its network.
This commit is contained in:
@@ -259,6 +259,45 @@
|
|||||||
failed_when: false
|
failed_when: false
|
||||||
changed_when: compose_update_alt.changed | default(false)
|
changed_when: compose_update_alt.changed | default(false)
|
||||||
|
|
||||||
|
# Ensure PostgreSQL Staging Stack is running (creates postgres-staging-internal network)
|
||||||
|
- name: Check if PostgreSQL Staging Stack directory exists
|
||||||
|
ansible.builtin.stat:
|
||||||
|
path: "{{ stacks_base_path | default('/home/deploy/deployment/stacks') }}/postgresql-staging/docker-compose.yml"
|
||||||
|
register: postgres_staging_compose_exists
|
||||||
|
changed_when: false
|
||||||
|
when: deployment_environment | default('') == 'staging'
|
||||||
|
|
||||||
|
- name: Check if PostgreSQL Staging Stack is running
|
||||||
|
ansible.builtin.shell: |
|
||||||
|
cd {{ stacks_base_path | default('/home/deploy/deployment/stacks') }}/postgresql-staging
|
||||||
|
docker compose ps --format json 2>/dev/null | grep -q '"State":"running"' && echo "RUNNING" || echo "NOT_RUNNING"
|
||||||
|
register: postgres_staging_status
|
||||||
|
changed_when: false
|
||||||
|
failed_when: false
|
||||||
|
when:
|
||||||
|
- deployment_environment | default('') == 'staging'
|
||||||
|
- postgres_staging_compose_exists.stat.exists | default(false) | bool
|
||||||
|
|
||||||
|
- name: Start PostgreSQL Staging Stack if not running
|
||||||
|
ansible.builtin.shell: |
|
||||||
|
cd {{ stacks_base_path | default('/home/deploy/deployment/stacks') }}/postgresql-staging
|
||||||
|
docker compose up -d
|
||||||
|
register: postgres_staging_start
|
||||||
|
changed_when: postgres_staging_start.rc == 0
|
||||||
|
when:
|
||||||
|
- deployment_environment | default('') == 'staging'
|
||||||
|
- postgres_staging_compose_exists.stat.exists | default(false) | bool
|
||||||
|
- postgres_staging_status.stdout | default('') == 'NOT_RUNNING'
|
||||||
|
|
||||||
|
- name: Wait for PostgreSQL Staging Stack to be ready
|
||||||
|
ansible.builtin.wait_for:
|
||||||
|
timeout: 30
|
||||||
|
delay: 2
|
||||||
|
when:
|
||||||
|
- deployment_environment | default('') == 'staging'
|
||||||
|
- postgres_staging_start.changed | default(false) | bool
|
||||||
|
|
||||||
|
# Extract and create external networks (fallback if PostgreSQL Stack doesn't create them)
|
||||||
- name: Extract external networks from docker-compose files
|
- name: Extract external networks from docker-compose files
|
||||||
ansible.builtin.shell: |
|
ansible.builtin.shell: |
|
||||||
cd {{ application_code_dest }}
|
cd {{ application_code_dest }}
|
||||||
@@ -272,7 +311,7 @@
|
|||||||
changed_when: false
|
changed_when: false
|
||||||
failed_when: false
|
failed_when: false
|
||||||
|
|
||||||
- name: Extract external network names (with name: field)
|
- name: "Extract external network names (with name field)"
|
||||||
ansible.builtin.shell: |
|
ansible.builtin.shell: |
|
||||||
cd {{ application_code_dest }}
|
cd {{ application_code_dest }}
|
||||||
grep -A 2 "external: true" docker-compose.base.yml docker-compose.{{ application_compose_suffix }} 2>/dev/null | \
|
grep -A 2 "external: true" docker-compose.base.yml docker-compose.{{ application_compose_suffix }} 2>/dev/null | \
|
||||||
@@ -294,6 +333,8 @@
|
|||||||
{%- set final_networks = (all_networks + default_networks) | unique | list -%}
|
{%- set final_networks = (all_networks + default_networks) | unique | list -%}
|
||||||
{{ final_networks }}
|
{{ final_networks }}
|
||||||
|
|
||||||
|
# Create external networks (fallback if they weren't created by their respective stacks)
|
||||||
|
# Note: This is a fallback - ideally networks are created by their stacks (e.g., postgres-staging-internal by PostgreSQL Staging Stack)
|
||||||
- name: Ensure Docker networks exist
|
- name: Ensure Docker networks exist
|
||||||
community.docker.docker_network:
|
community.docker.docker_network:
|
||||||
name: "{{ item }}"
|
name: "{{ item }}"
|
||||||
|
|||||||
Reference in New Issue
Block a user