From ae592c21c72f520d1873309f2a7959a01bcc1edc Mon Sep 17 00:00:00 2001 From: Michael Schiemer Date: Sat, 8 Nov 2025 15:31:06 +0100 Subject: [PATCH] fix: Add container status check and better error handling - Check if container is running before executing composer - Start container if not running - Display detailed error output for debugging - Fixes composer install failures when container is not running --- .../install-composer-dependencies.yml | 34 ++++++++++++++++--- 1 file changed, 29 insertions(+), 5 deletions(-) diff --git a/deployment/ansible/playbooks/install-composer-dependencies.yml b/deployment/ansible/playbooks/install-composer-dependencies.yml index b24b7068..ac06f151 100644 --- a/deployment/ansible/playbooks/install-composer-dependencies.yml +++ b/deployment/ansible/playbooks/install-composer-dependencies.yml @@ -35,6 +35,26 @@ msg: "composer.json not found at /home/deploy/michaelschiemer/current/composer.json" when: not composer_json_exists.stat.exists + - name: Check if container is running + shell: | + cd {{ application_code_dest }} + docker compose -f docker-compose.base.yml -f docker-compose.{{ application_compose_suffix }} ps {{ php_service_name }} --format json + register: container_status + changed_when: false + failed_when: false + + - name: Display container status + debug: + msg: "Container status: {{ container_status.stdout }}" + + - name: Start container if not running + shell: | + cd {{ application_code_dest }} + docker compose -f docker-compose.base.yml -f docker-compose.{{ application_compose_suffix }} up -d {{ php_service_name }} + when: container_status.rc != 0 or '"State":"running"' not in container_status.stdout + register: container_start + changed_when: container_start.rc == 0 + - name: Install composer dependencies in PHP container shell: | cd {{ application_code_dest }} @@ -43,6 +63,15 @@ changed_when: true failed_when: composer_install.rc != 0 + - name: Display composer install output + debug: + msg: | + Composer Install Output: + stdout: {{ composer_install.stdout }} + stderr: {{ composer_install.stderr }} + rc: {{ composer_install.rc }} + when: composer_install.rc != 0 + - name: Restart queue-worker and scheduler to pick up vendor directory (production only) shell: | cd {{ application_code_dest }} @@ -52,11 +81,6 @@ failed_when: false when: deployment_environment == 'production' - - name: Display composer install output - debug: - msg: | - Composer Install Output: - {{ composer_install.stdout }} - name: Verify vendor/autoload.php exists shell: |