fix: use registry from docker-compose file for image deployment
Some checks failed
🚀 Build & Deploy Image / Determine Build Necessity (push) Successful in 30s
🚀 Build & Deploy Image / Build Runtime Base Image (push) Has been cancelled
🚀 Build & Deploy Image / Build Docker Image (push) Has been cancelled
🚀 Build & Deploy Image / Auto-deploy to Staging (push) Has been cancelled
🚀 Build & Deploy Image / Auto-deploy to Production (push) Has been cancelled
🚀 Build & Deploy Image / Run Tests & Quality Checks (push) Has been cancelled
Security Vulnerability Scan / Composer Security Audit (push) Has been cancelled
Security Vulnerability Scan / Check for Dependency Changes (push) Has been cancelled
Some checks failed
🚀 Build & Deploy Image / Determine Build Necessity (push) Successful in 30s
🚀 Build & Deploy Image / Build Runtime Base Image (push) Has been cancelled
🚀 Build & Deploy Image / Build Docker Image (push) Has been cancelled
🚀 Build & Deploy Image / Auto-deploy to Staging (push) Has been cancelled
🚀 Build & Deploy Image / Auto-deploy to Production (push) Has been cancelled
🚀 Build & Deploy Image / Run Tests & Quality Checks (push) Has been cancelled
Security Vulnerability Scan / Composer Security Audit (push) Has been cancelled
Security Vulnerability Scan / Check for Dependency Changes (push) Has been cancelled
The playbook was using docker_registry (registry.michaelschiemer.de) but docker-compose.staging.yml uses git.michaelschiemer.de:5000. Now the playbook: - Extracts the actual registry URL from docker-compose files - Uses that registry for deploy_image - Updates docker-compose file with the correct registry This ensures the image is pulled from and deployed to the correct registry.
This commit is contained in:
@@ -41,9 +41,24 @@
|
|||||||
ansible.builtin.set_fact:
|
ansible.builtin.set_fact:
|
||||||
app_name: "{{ app_name if (app_name is defined and app_name != '') else app_name_default }}"
|
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
|
- name: Extract registry URL from docker-compose file (for image deployment)
|
||||||
|
ansible.builtin.shell: |
|
||||||
|
cd {{ application_code_dest }}
|
||||||
|
grep -h "image:" docker-compose.base.yml docker-compose.{{ application_compose_suffix }} 2>/dev/null | \
|
||||||
|
grep -E "{{ app_name }}" | head -1 | \
|
||||||
|
sed -E 's/.*image:\s*([^\/]+).*/\1/' | \
|
||||||
|
sed -E 's/\/.*$//' || echo "{{ docker_registry }}"
|
||||||
|
register: compose_registry_url
|
||||||
|
changed_when: false
|
||||||
|
failed_when: false
|
||||||
|
|
||||||
|
- name: Set actual registry from compose file or use default
|
||||||
ansible.builtin.set_fact:
|
ansible.builtin.set_fact:
|
||||||
deploy_image: "{{ docker_registry }}/{{ app_name }}:{{ image_tag }}"
|
actual_registry: "{{ (compose_registry_url.stdout | trim) if (compose_registry_url.stdout | trim != '' and compose_registry_url.stdout | trim != docker_registry) else docker_registry }}"
|
||||||
|
|
||||||
|
- name: Set deploy_image from actual registry, app_name and tag
|
||||||
|
ansible.builtin.set_fact:
|
||||||
|
deploy_image: "{{ actual_registry }}/{{ app_name }}:{{ image_tag }}"
|
||||||
|
|
||||||
- name: Set database and MinIO variables from vault or defaults
|
- name: Set database and MinIO variables from vault or defaults
|
||||||
ansible.builtin.set_fact:
|
ansible.builtin.set_fact:
|
||||||
@@ -123,21 +138,22 @@
|
|||||||
- 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_code_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+)({{ actual_registry }}/{{ app_name }}:)(.*)$'
|
||||||
replace: '\1\2{{ image_tag }}'
|
replace: '\1\2{{ image_tag }}'
|
||||||
register: compose_update_result
|
register: compose_update_result
|
||||||
failed_when: false
|
failed_when: false
|
||||||
changed_when: compose_update_result.changed | default(false)
|
changed_when: compose_update_result.changed | default(false)
|
||||||
|
|
||||||
- name: Update docker-compose file with new image (alternative pattern)
|
- name: Update docker-compose file with new image (alternative pattern - any registry)
|
||||||
ansible.builtin.replace:
|
ansible.builtin.replace:
|
||||||
path: "{{ application_code_dest }}/docker-compose.{{ application_compose_suffix }}"
|
path: "{{ application_code_dest }}/docker-compose.{{ application_compose_suffix }}"
|
||||||
regexp: 'image:\s+{{ docker_registry }}/{{ app_name }}:.*'
|
regexp: '^(\s+image:\s+)([^\/]+\/{{ app_name }}:)(.*)$'
|
||||||
replace: 'image: {{ deploy_image }}'
|
replace: '\1{{ actual_registry }}/{{ app_name }}:{{ image_tag }}'
|
||||||
register: compose_update_alt
|
register: compose_update_alt
|
||||||
when: compose_update_result.changed == false
|
when: compose_update_result.changed == false
|
||||||
failed_when: false
|
failed_when: false
|
||||||
changed_when: compose_update_alt.changed | default(false)
|
changed_when: compose_update_alt.changed | default(false)
|
||||||
|
changed_when: compose_update_alt.changed | default(false)
|
||||||
|
|
||||||
- name: Ensure Docker networks exist
|
- name: Ensure Docker networks exist
|
||||||
community.docker.docker_network:
|
community.docker.docker_network:
|
||||||
|
|||||||
Reference in New Issue
Block a user