fix: improve Docker image pull error handling and registry login
Some checks failed
🚀 Build & Deploy Image / Determine Build Necessity (push) Successful in 26s
Security Vulnerability Scan / Check for Dependency Changes (push) Successful in 24s
🚀 Build & Deploy Image / Build Runtime Base Image (push) Successful in 11s
🚀 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 52s
🚀 Build & Deploy Image / Auto-deploy to Production (push) Has been skipped
Some checks failed
🚀 Build & Deploy Image / Determine Build Necessity (push) Successful in 26s
Security Vulnerability Scan / Check for Dependency Changes (push) Successful in 24s
🚀 Build & Deploy Image / Build Runtime Base Image (push) Successful in 11s
🚀 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 52s
🚀 Build & Deploy Image / Auto-deploy to Production (push) Has been skipped
- Add debug output for image pull process - Improve error handling: verify image exists after pull before tagging - Fix registries_to_login Jinja2 template to handle undefined variables - Add explicit failure if image pull fails - Only tag image if it was successfully pulled
This commit is contained in:
@@ -127,6 +127,15 @@
|
||||
ignore_errors: yes
|
||||
register: docker_login_result
|
||||
|
||||
- name: Display image pull information
|
||||
ansible.builtin.debug:
|
||||
msg:
|
||||
- "Attempting to pull image: {{ deploy_image }}"
|
||||
- "Source registry: {{ source_registry }}"
|
||||
- "Local registry: {{ local_registry }}"
|
||||
- "Registry accessible: {{ registry_accessible | default('unknown') }}"
|
||||
when: registry_accessible is defined and registry_accessible == 'true'
|
||||
|
||||
- name: Pull Docker image
|
||||
community.docker.docker_image:
|
||||
name: "{{ deploy_image }}"
|
||||
@@ -137,11 +146,28 @@
|
||||
ignore_errors: yes
|
||||
failed_when: false
|
||||
|
||||
- name: Verify image exists locally
|
||||
- name: Display pull result
|
||||
ansible.builtin.debug:
|
||||
msg:
|
||||
- "Pull result: {{ image_pull_result | default('not executed') }}"
|
||||
- "Pull failed: {{ image_pull_result.failed | default(false) }}"
|
||||
- "Pull changed: {{ image_pull_result.changed | default(false) }}"
|
||||
when: registry_accessible is defined and registry_accessible == 'true'
|
||||
|
||||
- name: Verify image exists locally after pull
|
||||
community.docker.docker_image_info:
|
||||
name: "{{ deploy_image }}"
|
||||
register: image_info
|
||||
failed_when: image_info.failed | default(false)
|
||||
when: registry_accessible is defined and registry_accessible == 'true'
|
||||
ignore_errors: yes
|
||||
failed_when: false
|
||||
|
||||
- name: Fail if image was not pulled successfully
|
||||
ansible.builtin.fail:
|
||||
msg: "Failed to pull image {{ deploy_image }} from registry. Image does not exist locally."
|
||||
when:
|
||||
- registry_accessible is defined and registry_accessible == 'true'
|
||||
- image_info.failed | default(true) | bool
|
||||
|
||||
- name: Tag image for local registry (if source and local registry differ)
|
||||
community.docker.docker_image:
|
||||
@@ -149,7 +175,9 @@
|
||||
repository: "{{ local_image }}"
|
||||
tag: "{{ image_tag }}"
|
||||
source: local
|
||||
when: source_registry != local_registry
|
||||
when:
|
||||
- source_registry != local_registry
|
||||
- image_info.failed is not defined or not image_info.failed
|
||||
register: image_tag_result
|
||||
|
||||
- name: Push image to local registry (if source and local registry differ)
|
||||
@@ -277,10 +305,16 @@
|
||||
- name: Set list of registries to login to (source registry for pulling, local registry for pushing)
|
||||
ansible.builtin.set_fact:
|
||||
registries_to_login: >-
|
||||
{%- set source_list = [source_registry] if source_registry != local_registry else [] -%}
|
||||
{%- set local_list = [local_registry] -%}
|
||||
{%- set all_registries = source_list + local_list -%}
|
||||
{{ all_registries | unique | list }}
|
||||
{%- if source_registry is defined and local_registry is defined -%}
|
||||
{%- if source_registry != local_registry -%}
|
||||
{%- set reg_list = [source_registry, local_registry] -%}
|
||||
{%- else -%}
|
||||
{%- set reg_list = [local_registry] -%}
|
||||
{%- endif -%}
|
||||
{{ reg_list | unique | list }}
|
||||
{%- else -%}
|
||||
{{ [docker_registry] }}
|
||||
{%- endif -%}
|
||||
|
||||
- name: Login to all Docker registries before compose up
|
||||
community.docker.docker_login:
|
||||
|
||||
Reference in New Issue
Block a user