From b37c5f8ba187ff42878ea8db8ec18f3774b22fea Mon Sep 17 00:00:00 2001 From: David Esparza Date: Wed, 3 Apr 2024 13:11:35 -0600 Subject: [PATCH] metrics:libs: Add HTTPS and HTTP vars to docker build. Include HTTP and HTTPS env variables in the building docker images because they are required to download packages such as Phoronix. Added a restriction that verifies that docker building images is performed as root. Signed-off-by: David Esparza --- tests/metrics/lib/common.bash | 15 +++++++++++++-- 1 file changed, 13 insertions(+), 2 deletions(-) diff --git a/tests/metrics/lib/common.bash b/tests/metrics/lib/common.bash index 86bc87e5b..b16976df5 100755 --- a/tests/metrics/lib/common.bash +++ b/tests/metrics/lib/common.bash @@ -90,10 +90,14 @@ function generate_build_dockerfile() local map_key="$3" local text_to_replace="$4" local regs=(${registries["${map_key}"]}) + for r in ${regs[@]}; do sed 's|'${text_to_replace}'|'${r}'|g' \ "${dockerfile}.in" > "${dockerfile}" - if sudo "${DOCKER_EXE}" build --build-arg http_proxy="${http_proxy}" --build-arg https_proxy="${https_proxy}" --label "$image" --tag "${image}" -f "$dockerfile" "$dockerfile_dir"; then + if sudo -E "${DOCKER_EXE}" build \ + --build-arg http_proxy="${http_proxy}" --build-arg https_proxy="${https_proxy}" \ + --build-arg HTTP_PROXY="${http_proxy}" --build-arg HTTPS_PROXY="${https_proxy}" \ + --label "$image" --tag "${image}" -f "$dockerfile" "$dockerfile_dir"; then return 0 fi done @@ -111,7 +115,10 @@ function build_dockerfile_image() if [ -f "$dockerfile_path" ]; then info "docker building $image" - if ! sudo "${DOCKER_EXE}" build --build-arg http_proxy="${http_proxy}" --build-arg https_proxy="${https_proxy}" --label "$image" --tag "${image}" -f "$dockerfile_path" "$dockerfile_dir"; then + if ! sudo -E "${DOCKER_EXE}" build \ + --build-arg http_proxy="${http_proxy}" --build-arg https_proxy="${https_proxy}" \ + --build-arg HTTP_PROXY="${http_proxy}" --build-arg HTTPS_PROXY="${https_proxy}" \ + --label "$image" --tag "${image}" -f "$dockerfile_path" "$dockerfile_dir"; then die "Failed to docker build image $image" fi return 0 @@ -497,3 +504,7 @@ function get_current_kata_config_file() { current_config_file="${KATA_CONFIG_FNAME}" } + +function check_if_root() { + [ "$EUID" -ne 0 ] && die "Please run as root or use sudo." +}