From c207f92c90108a1375b9a23e6b7a53bc959ffe34 Mon Sep 17 00:00:00 2001 From: Mark Goddard Date: Mon, 9 Nov 2020 14:07:37 +0000 Subject: CI: revert to public package mirrors after build When building images in CI, we use local package mirrors to reduce external network traffic. These mirrors are not necessarily reliable nor are they guaranteed to be accessible outside of the CI environment (although many are). While it is an antipattern to install packages in containers at runtime, the Bifrost container does just that. If the mirrors configured in the image are unavailable, Bifrost deployment can fail. This change fixes the issue by reverting to public package mirrors as a final step of the image build process. Closes-Bug: #1902101 Change-Id: I2592a736206eaec811290e9fbdbf2540c0518ffe (cherry picked from commit 0fc464332c789ce05e9d6442726ada84ce7fc65a) --- tests/templates/template_overrides.j2 | 62 +++++++++++++++++++++++++++++++++-- 1 file changed, 59 insertions(+), 3 deletions(-) diff --git a/tests/templates/template_overrides.j2 b/tests/templates/template_overrides.j2 index b6c823cf5..43c9c0e54 100644 --- a/tests/templates/template_overrides.j2 +++ b/tests/templates/template_overrides.j2 @@ -28,9 +28,10 @@ RUN echo 'APT::Get::AllowUnauthenticated "true";' > /etc/apt/apt.conf.d/99allow- {% endraw %} RUN sed -i \ - -e "/^mirrorlist/ d" \ + -e "s|^\(mirrorlist.*\)|#\1|" \ -e "s|^#baseurl=http://mirror.centos.org|baseurl=http://{{ nodepool_mirror_host }}|" \ /etc/yum.repos.d/CentOS-*.repo + {% raw %} {% if distro_package_manager == 'yum' %} {% endraw %} @@ -57,14 +58,14 @@ RUN sed -i \ {% block base_centos_repo_overrides_post_yum %} {% endraw %} && sed -i \ - -e "/^mirrorlist/ d" \ + -e "s|^\(mirrorlist.*\)|#\1|" \ -e "s|^#baseurl=http://mirror.centos.org|baseurl=http://{{ nodepool_mirror_host }}|" \ -e "s|^#baseurl=https://mirror.centos.org|baseurl=http://{{ nodepool_mirror_host }}|" \ -e "s|^baseurl=http://mirror.centos.org|baseurl=http://{{ nodepool_mirror_host }}|" \ -e "s|^baseurl=https://mirror.centos.org|baseurl=http://{{ nodepool_mirror_host }}|" \ /etc/yum.repos.d/CentOS-*.repo \ && sed -i \ - -e "/^metalink/ d" \ + -e "s|^\(metalink.*\)|#\1|" \ -e "s|^#baseurl=http://download.fedoraproject.org/pub|baseurl=http://{{ nodepool_mirror_host }}|" \ -e "s|^#baseurl=https://download.fedoraproject.org/pub|baseurl=http://{{ nodepool_mirror_host }}|" \ /etc/yum.repos.d/epel*.repo \ @@ -84,4 +85,59 @@ RUN sed -i -e "s|http://archive.ubuntu.com|http://{{ nodepool_mirror_host }}|" \ {% raw %} {% endif %} {% endblock %} + +{# Revert to upstream mirrors after build is complete #} + +{% block footer %} +{% endraw %} + +ENV PIP_INDEX_URL= +ENV PIP_TRUSTED_HOST= +{% if use_infra_wheels_mirror | default(true) %} +ENV PIP_EXTRA_INDEX_URL= +{% endif %} + +RUN if [[ -f /usr/etc/npmrc ]]; then \ + unlink /usr/etc/npmrc; \ + fi \ + && rm -f /etc/npmrc + +{% raw %} +{% if base_package_type == 'rpm' %} +{% endraw %} +RUN sed -i \ + -e "s|^#\(mirrorlist.*\)|\1|" \ + -e "s|^baseurl=http://{{ nodepool_mirror_host }}|#baseurl=http://mirror.centos.org|" \ + /etc/yum.repos.d/CentOS-*.repo \ + && sed -i \ + -e "s|^#\(metalink.*\)|\1|" \ + -e "s|^baseurl=http://{{ nodepool_mirror_host }}|baseurl=http://download.fedoraproject.org/pub|" \ + /etc/yum.repos.d/epel*.repo +{% raw %} +{% if distro_package_manager == 'yum' %} +{% endraw %} +RUN sed -i \ + -e "s|http://{{ nodepool_mirror_host }}/opensuse|http://download.opensuse.org|" \ + /etc/yum.repos.d/crmsh.repo \ + && sed -i \ + -e "s|{{ nodepool_cbs_centos_proxy }}|https://cbs.centos.org/repos|g" \ + /etc/yum.repos.d/opendaylight.repo \ + && sed -i \ + -e "s|^#baseurl|baseurl|g" \ + /etc/yum.repos.d/CentOS-OpsTools.repo +{% raw %} +{% endif %} +{% elif base_package_type == 'deb' %} +{% endraw %} +RUN rm -f /etc/apt/apt.conf.d/99allow-unauthenticated /etc/apt/apt.conf.d/99allow-insecure-repos +{% raw %} +{% if base_distro == "ubuntu" %} +{% endraw %} +RUN sed -i -e "s|http://{{ nodepool_mirror_host }}/ubuntu-cloud-archive|http://ubuntu-cloud.archive.canonical.com/ubuntu|" \ + -e "s|http://{{ nodepool_mirror_host }}|http://archive.ubuntu.com|" \ + /etc/apt/sources.list +{% raw %} +{% endif %} +{% endif %} +{% endblock %} {% endraw %} -- cgit v1.2.3