From 0613cfda3189740384b8d094666cedf1d7754131 Mon Sep 17 00:00:00 2001 From: Jeremy Stanley Date: Mon, 22 Nov 2021 15:21:48 +0000 Subject: [PATCH] Cache Ansible Galaxy on CI mirror servers Ansible Galaxy indexes tarballs of Ansible roles and collections at a central site, which in turn points to a dedicated Amazon S3 subdomain. The tools which consume it support overriding the default Galaxy URL with any arbitrary one, so should be able to take advantage of this in CI jobs. Change-Id: Ib5664e5588f7237a19a2cdb6eec3109452e8a107 --- .../roles/mirror/templates/mirror.vhost.j2 | 8 ++++ testinfra/test_mirror.py | 37 +++++++++++++++++++ 2 files changed, 45 insertions(+) diff --git a/playbooks/roles/mirror/templates/mirror.vhost.j2 b/playbooks/roles/mirror/templates/mirror.vhost.j2 index 756b6c51a6..45dbb614e3 100644 --- a/playbooks/roles/mirror/templates/mirror.vhost.j2 +++ b/playbooks/roles/mirror/templates/mirror.vhost.j2 @@ -110,6 +110,14 @@ ErrorLogFormat "[%{cu}t] [%-m:%l] [pid %P:tid %T] %7F: %E: [client\ %a] %M% , \ RewriteCond %{DOCUMENT_ROOT}/%{REQUEST_URI} !-d RewriteRule (.*)-(.*) $1.$2 [N] + # Ansible Galaxy + CacheEnable disk "/galaxy" + ProxyPass "/galaxy/" "https://galaxy.ansible.com/" ttl=120 keepalive=On retry=0 + ProxyPassReverse "/galaxy/" "https://galaxy.ansible.com/" + CacheEnable disk "/galaxy-s3" + ProxyPass "/galaxy-s3/" "https://ansible-galaxy.s3.amazonaws.com/" ttl=120 keepalive=On retry=0 + ProxyPassReverse "/galaxy-s3/" "https://ansible-galaxy.s3.amazonaws.com/" + ErrorLog /var/log/apache2/mirror_$port_error.log LogLevel warn CustomLog /var/log/apache2/mirror_$port_access.log combined-cache diff --git a/testinfra/test_mirror.py b/testinfra/test_mirror.py index 270217ab3e..6891898234 100644 --- a/testinfra/test_mirror.py +++ b/testinfra/test_mirror.py @@ -88,3 +88,40 @@ def test_quay_mirror(host): assert 'quay' in cmd.stdout # TODO test RHRegistryMirror + +def test_galaxy_mirror(host): + for addr in host.addr(host.backend.host).ipv4_addresses: + cmd = host.run( + "wget --no-check-certificate -qO- https://%s/galaxy/" % addr) + assert 'Ansible Galaxy' in cmd.stdout + + cmd = host.run("wget -qO- http://%s/galaxy/" % addr) + assert 'Ansible Galaxy' in cmd.stdout + + cmd = host.run("wget --no-check-certificate -O- " + "https://%s/galaxy/download/community-general-4.0.2.tar.gz" % + addr) + assert '/galaxy-s3/artifact/' in cmd.stderr + + cmd = host.run("wget -O- " + "http://%s/galaxy/download/community-general-4.0.2.tar.gz" % + addr) + assert '/galaxy-s3/artifact/' in cmd.stderr + + for addr in host.addr(host.backend.host).ipv6_addresses: + cmd = host.run("wget --no-check-certificate -qO- " + "https://[%s]/galaxy/" % addr) + assert 'Ansible Galaxy' in cmd.stdout + + cmd = host.run("wget -qO- http://[%s]/galaxy/" % addr) + assert 'Ansible Galaxy' in cmd.stdout + + cmd = host.run("wget --no-check-certificate -O- " + "https://[%s]/galaxy/download/community-general-4.0.2.tar.gz" % + addr) + assert '/galaxy-s3/artifact/' in cmd.stderr + + cmd = host.run("wget -O- " + "http://[%s]/galaxy/download/community-general-4.0.2.tar.gz" % + addr) + assert '/galaxy-s3/artifact/' in cmd.stderr