From 49bdbac6069520b4d8a948fccafa227d8c87ca6d Mon Sep 17 00:00:00 2001 From: Eric Ernst Date: Wed, 10 Feb 2021 12:32:55 -0800 Subject: [PATCH] osbuilder: Allow image registry to be customizable Give the user chance to specify their own registry in event the default provided are not accessible, desirable. Fixes: #1393 Signed-off-by: Eric Ernst --- .../osbuilder/image-builder/image_builder.sh | 23 ++++++++++++------- tools/osbuilder/rootfs-builder/rootfs.sh | 16 ++++++++++--- 2 files changed, 28 insertions(+), 11 deletions(-) diff --git a/tools/osbuilder/image-builder/image_builder.sh b/tools/osbuilder/image-builder/image_builder.sh index a1576cd47..cba3ca1d6 100755 --- a/tools/osbuilder/image-builder/image_builder.sh +++ b/tools/osbuilder/image-builder/image_builder.sh @@ -84,14 +84,15 @@ Options: -r Free space of the root partition in MB ENV: ROOT_FREE_SPACE Extra environment variables: - AGENT_BIN: Use it to change the expected agent binary name - AGENT_INIT: Use kata agent as init process - FS_TYPE: Filesystem type to use. Only xfs and ext4 are supported. - NSDAX_BIN: Use to specify path to pre-compiled 'nsdax' tool. - USE_DOCKER: If set will build image in a Docker Container (requries docker) - DEFAULT: not set - USE_PODMAN: If set and USE_DOCKER not set, will build image in a Podman Container (requries podman) - DEFAULT: not set + AGENT_BIN: Use it to change the expected agent binary name + AGENT_INIT: Use kata agent as init process + IMAGE_REGISTRY: Hostname for the image registry used to pull down the rootfs build image. + FS_TYPE: Filesystem type to use. Only xfs and ext4 are supported. + NSDAX_BIN: Use to specify path to pre-compiled 'nsdax' tool. + USE_DOCKER: If set will build image in a Docker Container (requries docker) + DEFAULT: not set + USE_PODMAN: If set and USE_DOCKER not set, will build image in a Podman Container (requries podman) + DEFAULT: not set Following diagram shows how the resulting image will look like @@ -137,7 +138,13 @@ build_with_container() { image_dir=$(readlink -f "$(dirname "${image}")") image_name=$(basename "${image}") + REGISTRY_ARG="" + if [ -n "${IMAGE_REGISTRY}" ]; then + REGISTRY_ARG="--build-arg IMAGE_REGISTRY=${IMAGE_REGISTRY}" + fi + "${container_engine}" build \ + ${REGISTRY_ARG} \ --build-arg http_proxy="${http_proxy}" \ --build-arg https_proxy="${https_proxy}" \ -t "${container_image_name}" "${script_dir}" diff --git a/tools/osbuilder/rootfs-builder/rootfs.sh b/tools/osbuilder/rootfs-builder/rootfs.sh index 800551502..9fbe49bad 100755 --- a/tools/osbuilder/rootfs-builder/rootfs.sh +++ b/tools/osbuilder/rootfs-builder/rootfs.sh @@ -100,13 +100,13 @@ AGENT_INIT When set to "yes", use ${AGENT_BIN} as init process in place of systemd. Default value: no -AGENT_VERSION Version of the agent to include in the rootfs. - Default value: ${AGENT_VERSION:-} - AGENT_SOURCE_BIN Path to the directory of agent binary. If set, use the binary as agent but not build agent package. Default value: +AGENT_VERSION Version of the agent to include in the rootfs. + Default value: ${AGENT_VERSION:-} + DISTRO_REPO Use host repositories to install guest packages. Default value: @@ -123,6 +123,10 @@ GRACEFUL_EXIT If set, and if the DISTRO configuration specifies a specific distributions. Default value: +IMAGE_REGISTRY Hostname for the image registry used to pull down the rootfs + build image. + Default value: docker.io + KERNEL_MODULES_DIR Path to a directory containing kernel modules to include in the rootfs. Default value: @@ -371,9 +375,15 @@ build_rootfs_distro() image_name="${distro}-rootfs-osbuilder" + REGISTRY_ARG="" + if [ -n "${IMAGE_REGISTRY}" ]; then + REGISTRY_ARG="--build-arg IMAGE_REGISTRY=${IMAGE_REGISTRY}" + fi + # setup to install go or rust here generate_dockerfile "${distro_config_dir}" "$container_engine" build \ + ${REGISTRY_ARG} \ --build-arg http_proxy="${http_proxy}" \ --build-arg https_proxy="${https_proxy}" \ -t "${image_name}" "${distro_config_dir}"