From 68e6fa0f8d2564f22f5c6d87a7fb4d4574db9fb8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Rafael=20Fern=C3=A1ndez=20L=C3=B3pez?= Date: Sat, 1 Dec 2018 19:13:34 +0100 Subject: [PATCH] Allow to build docker images offline (do not always use `docker build --pull`) Passing `KUBE_BUILD_PULL_LATEST_IMAGES=n` will disable building the artifacts with `--pull`, so they can be built in an offline environment. By default, `KUBE_BUILD_PULL_LATEST_IMAGES` is `y`, so the default behavior is kept unchanged. --- build/lib/release.sh | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/build/lib/release.sh b/build/lib/release.sh index 98f6767d958..18e2ca65440 100644 --- a/build/lib/release.sh +++ b/build/lib/release.sh @@ -30,6 +30,7 @@ readonly RELEASE_IMAGES="${LOCAL_OUTPUT_ROOT}/release-images" KUBE_BUILD_HYPERKUBE=${KUBE_BUILD_HYPERKUBE:-y} KUBE_BUILD_CONFORMANCE=${KUBE_BUILD_CONFORMANCE:-y} +KUBE_BUILD_PULL_LATEST_IMAGES=${KUBE_BUILD_PULL_LATEST_IMAGES:-y} # Validate a ci version # @@ -372,7 +373,15 @@ EOF if [[ "${base_image}" =~ busybox ]]; then echo "COPY nsswitch.conf /etc/" >> "${docker_file_path}" fi - "${DOCKER[@]}" build --pull -q -t "${docker_image_tag}" "${docker_build_path}" >/dev/null + + # provide `--pull` argument to `docker build` if `KUBE_BUILD_PULL_LATEST_IMAGES` + # is set to y or Y; otherwise try to build the image without forcefully + # pulling the latest base image. + local -a docker_build_opts=() + if [[ "${KUBE_BUILD_PULL_LATEST_IMAGES}" =~ [yY] ]]; then + docker_build_opts+=("--pull") + fi + "${DOCKER[@]}" build "${docker_build_opts[@]}" -q -t "${docker_image_tag}" "${docker_build_path}" >/dev/null "${DOCKER[@]}" save "${docker_image_tag}" > "${binary_dir}/${binary_name}.tar" echo "${docker_tag}" > "${binary_dir}/${binary_name}.docker_tag" rm -rf "${docker_build_path}"