fix: Resolve recursive loops and fix registry URL in deploy-image.yml
Some checks failed
🚀 Build & Deploy Image / Determine Build Necessity (push) Successful in 30s
Security Vulnerability Scan / Check for Dependency Changes (push) Successful in 28s
🚀 Build & Deploy Image / Build Runtime Base Image (push) Successful in 12s
🚀 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
🚀 Build & Deploy Image / Auto-deploy to Staging (push) Failing after 1m24s
🚀 Build & Deploy Image / Auto-deploy to Production (push) Has been skipped

- Fix recursive loop in app_name variable
- Set app_name and deploy_image using set_fact tasks
- Replace application_stack_dest with application_code_dest (consistent with other playbooks)
- Change registry URL from HTTP to HTTPS
- Add validate_certs: no for registry accessibility check
- Fixes 'Recursive loop detected' error in image deployment
This commit is contained in:
2025-11-08 15:41:11 +01:00
parent 48e5179bac
commit cf8fea322c

View File

@@ -5,13 +5,8 @@
become: no become: no
vars: vars:
# Determine stack path based on environment # Application code directory (where docker-compose files are located)
application_stack_dest: >- application_code_dest: "/home/deploy/michaelschiemer/current"
{%- if deployment_environment == 'staging' -%}
{{ staging_stack_path | default(stacks_base_path + '/staging') }}
{%- else -%}
{{ app_stack_path | default(stacks_base_path + '/production') }}
{%- endif -%}
application_compose_suffix: >- application_compose_suffix: >-
{%- if deployment_environment == 'staging' -%} {%- if deployment_environment == 'staging' -%}
staging.yml staging.yml
@@ -21,13 +16,19 @@
# Image to deploy (can be overridden via -e image_tag=...) # Image to deploy (can be overridden via -e image_tag=...)
image_tag: "{{ image_tag | default('latest') }}" image_tag: "{{ image_tag | default('latest') }}"
docker_registry: "{{ docker_registry | default('registry.michaelschiemer.de') }}" docker_registry: "{{ docker_registry | default('registry.michaelschiemer.de') }}"
app_name: "{{ app_name | default('framework') }}" app_name_default: "framework"
# Full image URL
deploy_image: "{{ docker_registry }}/{{ app_name }}:{{ image_tag }}"
# Deployment environment (staging or production) # Deployment environment (staging or production)
deployment_environment: "{{ deployment_environment | default('production') }}" deployment_environment: "{{ deployment_environment | default('production') }}"
tasks: tasks:
- name: Set app_name from provided value or default
ansible.builtin.set_fact:
app_name: "{{ app_name if (app_name is defined and app_name != '') else app_name_default }}"
- name: Set deploy_image from registry, app_name and tag
ansible.builtin.set_fact:
deploy_image: "{{ docker_registry }}/{{ app_name }}:{{ image_tag }}"
- name: Determine Docker registry password from vault or extra vars - name: Determine Docker registry password from vault or extra vars
ansible.builtin.set_fact: ansible.builtin.set_fact:
registry_password: >- registry_password: >-
@@ -42,10 +43,11 @@
- name: Check if registry is accessible - name: Check if registry is accessible
ansible.builtin.uri: ansible.builtin.uri:
url: "http://{{ docker_registry }}/v2/" url: "https://{{ docker_registry }}/v2/"
method: GET method: GET
status_code: [200, 401] status_code: [200, 401]
timeout: 5 timeout: 5
validate_certs: no
register: registry_check register: registry_check
ignore_errors: yes ignore_errors: yes
delegate_to: "{{ inventory_hostname }}" delegate_to: "{{ inventory_hostname }}"
@@ -79,7 +81,7 @@
- name: Update docker-compose file with new image tag - name: Update docker-compose file with new image tag
ansible.builtin.replace: ansible.builtin.replace:
path: "{{ application_stack_dest }}/docker-compose.{{ application_compose_suffix }}" path: "{{ application_code_dest }}/docker-compose.{{ application_compose_suffix }}"
regexp: '^(\s+image:\s+)({{ docker_registry }}/{{ app_name }}:)(.*)$' regexp: '^(\s+image:\s+)({{ docker_registry }}/{{ app_name }}:)(.*)$'
replace: '\1\2{{ image_tag }}' replace: '\1\2{{ image_tag }}'
register: compose_update_result register: compose_update_result
@@ -88,7 +90,7 @@
- name: Update docker-compose file with new image (alternative pattern) - name: Update docker-compose file with new image (alternative pattern)
ansible.builtin.replace: ansible.builtin.replace:
path: "{{ application_stack_dest }}/docker-compose.{{ application_compose_suffix }}" path: "{{ application_code_dest }}/docker-compose.{{ application_compose_suffix }}"
regexp: 'image:\s+{{ docker_registry }}/{{ app_name }}:.*' regexp: 'image:\s+{{ docker_registry }}/{{ app_name }}:.*'
replace: 'image: {{ deploy_image }}' replace: 'image: {{ deploy_image }}'
register: compose_update_alt register: compose_update_alt
@@ -107,7 +109,7 @@
- name: Deploy application stack with new image - name: Deploy application stack with new image
shell: | shell: |
cd {{ application_stack_dest }} cd {{ application_code_dest }}
docker compose -f docker-compose.base.yml -f docker-compose.{{ application_compose_suffix }} up -d --pull missing --force-recreate --remove-orphans docker compose -f docker-compose.base.yml -f docker-compose.{{ application_compose_suffix }} up -d --pull missing --force-recreate --remove-orphans
register: compose_deploy_result register: compose_deploy_result
changed_when: true changed_when: true
@@ -118,7 +120,7 @@
- name: Check container status - name: Check container status
shell: | shell: |
cd {{ application_stack_dest }} cd {{ application_code_dest }}
docker compose -f docker-compose.base.yml -f docker-compose.{{ application_compose_suffix }} ps docker compose -f docker-compose.base.yml -f docker-compose.{{ application_compose_suffix }} ps
register: container_status register: container_status
changed_when: false changed_when: false
@@ -132,7 +134,7 @@
Image: {{ deploy_image }} Image: {{ deploy_image }}
Tag: {{ image_tag }} Tag: {{ image_tag }}
Environment: {{ deployment_environment }} Environment: {{ deployment_environment }}
Stack: {{ application_stack_dest }} Stack: {{ application_code_dest }}
Status: SUCCESS Status: SUCCESS
======================================== ========================================