From 74249cc12892ff2daf8420f643d8abfa3e8c8356 Mon Sep 17 00:00:00 2001 From: Edmund Rhudy Date: Thu, 12 Jan 2017 13:58:44 -0500 Subject: [PATCH] Add blocks for Ubuntu apt setup and package installation This adds additional blocks in the base image dockerfile to enable overriding additional sections, as well as doing so in a more fine-grained manner. The main use case here is being able to do Internet-isolated builds of Ubuntu-based Docker images. Change-Id: I9842895a898f6798becc6177aabdf8deffead611 Closes-Bug: #1656069 --- docker/base/Dockerfile.j2 | 24 +++++++++++++++++------- 1 file changed, 17 insertions(+), 7 deletions(-) diff --git a/docker/base/Dockerfile.j2 b/docker/base/Dockerfile.j2 index 9fbde0f1cc..38b9679d10 100644 --- a/docker/base/Dockerfile.j2 +++ b/docker/base/Dockerfile.j2 @@ -207,13 +207,21 @@ ENV DEBIAN_FRONTEND noninteractive # Reducing disk footprint COPY dpkg_reducing_disk_footprint /etc/dpkg/dpkg.cfg.d/dpkg_reducing_disk_footprint -# Need apt-transport-https BEFORE we replace sources.list or apt-get update wont work! +{% block base_ubuntu_package_pre %} +# Need apt-transport-https and ca-certificates before replacing sources.list or +# apt-get update will not work if any repositories are accessed via HTTPS RUN apt-get update \ && apt-get -y install --no-install-recommends apt-transport-https ca-certificates \ && apt-get clean +{% endblock %} +{% block base_ubuntu_package_sources_list %} COPY sources.list.{{ base_distro }} /etc/apt/sources.list +{% endblock %} + +{% block base_ubuntu_package_apt_preferences %} COPY apt_preferences.{{ base_distro }} /etc/apt/preferences +{% endblock %} {% set base_apt_packages = [ 'apt-utils', @@ -257,12 +265,14 @@ COPY apt_preferences.{{ base_distro }} /etc/apt/preferences {% endif %} {% block base_ubuntu_package_installation %} -{%- for key in base_apt_keys | customizable('apt_keys') %} - {%- if loop.first %}RUN {% else %} && {% endif -%} - apt-key adv --recv-keys --keyserver hkp://keyserver.ubuntu.com:80 {{ key }} \ -{% endfor -%} -{%- if base_apt_keys|length ==0 %}RUN {% else %} && {% endif -%} - apt-get update \ + {%- block base_ubuntu_package_key_installation %} + {%- for key in base_apt_keys | customizable('apt_keys') %} + {%- if loop.first %}RUN {% else %} && {% endif %}apt-key adv --recv-keys --keyserver hkp://keyserver.ubuntu.com:80 {{ key }} + {%- if not loop.last %} \ + {% endif -%} + {% endfor %} + {% endblock %} +RUN apt-get update \ && apt-get -y upgrade \ && apt-get -y dist-upgrade \ && apt-get -y install --no-install-recommends \