fix: login to correct Docker registry from docker-compose files
Some checks failed
🚀 Build & Deploy Image / Build Runtime Base Image (push) Successful in 12s
🚀 Build & Deploy Image / Run Tests & Quality Checks (push) Has been skipped
🚀 Build & Deploy Image / Build Docker Image (push) Successful in 12s
🚀 Build & Deploy Image / Auto-deploy to Production (push) Has been skipped
🚀 Build & Deploy Image / Determine Build Necessity (push) Successful in 27s
Security Vulnerability Scan / Check for Dependency Changes (push) Successful in 31s
Security Vulnerability Scan / Composer Security Audit (push) Has been skipped
🚀 Build & Deploy Image / Auto-deploy to Staging (push) Failing after 1m7s
Some checks failed
🚀 Build & Deploy Image / Build Runtime Base Image (push) Successful in 12s
🚀 Build & Deploy Image / Run Tests & Quality Checks (push) Has been skipped
🚀 Build & Deploy Image / Build Docker Image (push) Successful in 12s
🚀 Build & Deploy Image / Auto-deploy to Production (push) Has been skipped
🚀 Build & Deploy Image / Determine Build Necessity (push) Successful in 27s
Security Vulnerability Scan / Check for Dependency Changes (push) Successful in 31s
Security Vulnerability Scan / Composer Security Audit (push) Has been skipped
🚀 Build & Deploy Image / Auto-deploy to Staging (push) Failing after 1m7s
- Extract actual registry URLs from docker-compose files - Login to all registries found in compose files (e.g. git.michaelschiemer.de:5000) - This fixes the 'no basic auth credentials' error when pulling images - The playbook now automatically detects which registry is used in compose files - Falls back to docker_registry variable if no registry found in compose files
This commit is contained in:
@@ -224,23 +224,56 @@
|
||||
ignore_errors: yes
|
||||
|
||||
- name: Wait for Docker daemon to be ready
|
||||
wait_for:
|
||||
path: /var/run/docker.sock
|
||||
timeout: 10
|
||||
shell: docker ps > /dev/null 2>&1
|
||||
register: docker_ready
|
||||
until: docker_ready.rc == 0
|
||||
retries: 30
|
||||
delay: 2
|
||||
when: docker_daemon_updated.changed | default(false)
|
||||
ignore_errors: yes
|
||||
become: no
|
||||
changed_when: false
|
||||
|
||||
- name: Login to Docker registry before compose up
|
||||
- name: Determine actual registry URLs from docker-compose files
|
||||
ansible.builtin.shell: |
|
||||
cd {{ application_code_dest }}
|
||||
grep -h "image:" docker-compose.base.yml docker-compose.{{ application_compose_suffix }} 2>/dev/null | sed -E 's/.*image:\s*([^\/]+).*/\1/' | sed 's/:.*//' | sort -u || echo ""
|
||||
register: actual_registry_urls
|
||||
changed_when: false
|
||||
failed_when: false
|
||||
|
||||
- name: Set list of registries to login to
|
||||
ansible.builtin.set_fact:
|
||||
registries_to_login: >-
|
||||
{%- set found_registries = actual_registry_urls.stdout | trim | split('\n') | select('match', '.+') | list -%}
|
||||
{%- set default_registry = [docker_registry] -%}
|
||||
{%- if found_registries | length > 0 -%}
|
||||
{{ found_registries | unique | list }}
|
||||
{%- else -%}
|
||||
{{ default_registry }}
|
||||
{%- endif -%}
|
||||
|
||||
- name: Login to all Docker registries before compose up
|
||||
community.docker.docker_login:
|
||||
registry_url: "{{ docker_registry }}"
|
||||
registry_url: "{{ item }}"
|
||||
username: "{{ docker_registry_username | default('admin') }}"
|
||||
password: "{{ registry_password }}"
|
||||
when:
|
||||
- registry_password | string | trim != ''
|
||||
- registry_accessible == 'true'
|
||||
loop: "{{ registries_to_login }}"
|
||||
no_log: yes
|
||||
ignore_errors: yes
|
||||
register: docker_login_results
|
||||
failed_when: false
|
||||
|
||||
- name: Display login results
|
||||
ansible.builtin.debug:
|
||||
msg: "Docker login to {{ item.item }}: {% if item.failed %}FAILED{% else %}SUCCESS{% endif %}"
|
||||
when:
|
||||
- registry_password | string | trim != ''
|
||||
- registry_accessible == 'true'
|
||||
loop: "{{ docker_login_results.results | default([]) }}"
|
||||
loop_control:
|
||||
label: "{{ item.item }}"
|
||||
|
||||
- name: Deploy application stack with new image
|
||||
shell: |
|
||||
|
||||
Reference in New Issue
Block a user