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