From b007e86a0fb8f7bec226ee4fe47ae97e9a4699eb Mon Sep 17 00:00:00 2001 From: Clark Boylan Date: Tue, 19 Nov 2024 13:54:24 -0800 Subject: [PATCH] Support new style mirror_info in use-docker-mirror This adds new style mirror_info handling to use-docker-mirror to give us greater control over whether or not docker hub should be mirrored. We ignore old style configuration if new style is present which gives us this control. Otherwise we fallback to the old behavior. We also update the ensure-docker test jobs to be triggered by updates to the use-docker-mirror roles as ensure-docker includes this role. We should get decent functional testing coverage this way. Change-Id: Ia1b216a6dd68bcafbe599777037c5d7b1b3e8201 --- roles/use-docker-mirror/tasks/main.yaml | 32 +++++++++++++++++++---- roles/use-docker-mirror/tasks/mirror.yaml | 9 ------- zuul-tests.d/container-roles-jobs.yaml | 1 + 3 files changed, 28 insertions(+), 14 deletions(-) diff --git a/roles/use-docker-mirror/tasks/main.yaml b/roles/use-docker-mirror/tasks/main.yaml index 6f5a8849a..06d64f93d 100644 --- a/roles/use-docker-mirror/tasks/main.yaml +++ b/roles/use-docker-mirror/tasks/main.yaml @@ -1,10 +1,32 @@ -- name: Set mirror_fqdn fact +- name: Set docker_mirror fact from mirror_info when: - - mirror_fqdn is not defined - - zuul_site_mirror_fqdn is defined + - docker_mirror is not defined + - mirror_info is defined + - dockerhub is in mirror_info set_fact: - mirror_fqdn: "{{ zuul_site_mirror_fqdn }}" + docker_mirror: mirror_info.dockerhub.url +- name: Set docker_mirror fact from zuul_site_mirror_info + when: + - docker_mirror is not defined + - zuul_site_mirror_info is defined + - dockerhub is in zuul_site_mirror_info + set_fact: + docker_mirror: zuul_site_mirror_info.dockerhub.url + +# Backward compat fallback to old style mirror_fqdn based url derivation. +- name: Set docker_mirror fact + when: + - docker_mirror is not defined + - mirror_info is not defined + - zuul_site_mirror_info is not defined + - mirror_fqdn is defined or zuul_site_mirror_fqdn is defined + set_fact: + docker_mirror: "http://{{ mirror_fqdn | default(zuul_site_mirror_fqdn) }}:8082" + +# Only run when new style mirror_info is defined or old style mirror +# info is defined and not new style. This forces people using new +# style to configure dockerhub mirroring there. - name: Set up docker mirrors include_tasks: mirror.yaml - when: mirror_fqdn is defined or docker_mirror is defined + when: docker_mirror is defined diff --git a/roles/use-docker-mirror/tasks/mirror.yaml b/roles/use-docker-mirror/tasks/mirror.yaml index d845bae55..a39eba250 100644 --- a/roles/use-docker-mirror/tasks/mirror.yaml +++ b/roles/use-docker-mirror/tasks/mirror.yaml @@ -5,17 +5,8 @@ path: /etc/docker mode: 0755 -- name: Set docker_mirror fact - when: - - docker_mirror is not defined - - mirror_fqdn is defined - set_fact: - docker_mirror: "http://{{ mirror_fqdn }}:8082" - - name: Install dockerhub proxy configuration become: yes - when: - - docker_mirror is defined template: dest: /etc/docker/daemon.json group: root diff --git a/zuul-tests.d/container-roles-jobs.yaml b/zuul-tests.d/container-roles-jobs.yaml index 7cb718286..3925f8590 100644 --- a/zuul-tests.d/container-roles-jobs.yaml +++ b/zuul-tests.d/container-roles-jobs.yaml @@ -4,6 +4,7 @@ abstract: true files: - .*ensure-docker.* + - roles/use-docker-mirror/.* - roles/ensure-package-repositories/.* - test-requirements.txt run: test-playbooks/ensure-docker.yaml