From cfe2abcb6b083e83a3dca6db7d5ecf837aa4beb2 Mon Sep 17 00:00:00 2001 From: Davlet Panech Date: Wed, 20 Apr 2022 14:53:17 -0400 Subject: [PATCH] debian: stx-init-env: option to use docker cache By default we use the "--no-cache" option when building containers. Add a command-line option to avoid this, to make testing this script easier. TESTS ===================== Rebuild containers with and without the "--cache" option Story: 2008846 Task: 45124 Signed-off-by: Davlet Panech Change-Id: I79d61cc9a7606d6de65478ced5bab325f7264278 --- stx-init-env | 18 ++++++++++++++++-- 1 file changed, 16 insertions(+), 2 deletions(-) diff --git a/stx-init-env b/stx-init-env index d1d18e76e..89b11d096 100755 --- a/stx-init-env +++ b/stx-init-env @@ -17,6 +17,11 @@ Initialize StarlingX build environment & (re-)start builder pods --rebuild build pod images instead of downloading them + --cache allow docker to use its filesystem cache (with --rebuild) + CAUTION: this option may not pick up all the changes to + docker source files and is meant for debugging + the build scripts. + END } @@ -43,6 +48,7 @@ BUILD_DOCKER=0 DELETE_ENV=0 RESTART_MINIKUBE=0 CLEAN_CONFIG=0 +USE_DOCKER_CACHE=0 minikube_started() { docker ps | grep kicbase | grep -q $MINIKUBENAME @@ -74,7 +80,7 @@ cmdline_error() { } # process command line -temp=$(getopt -o hR --long help,clean,restart-minikube,rebuild,nuke -n "$PROGNAME" -- "$@") || cmdline_error +temp=$(getopt -o hR --long help,clean,restart-minikube,rebuild,cache,nuke -n "$PROGNAME" -- "$@") || cmdline_error eval set -- "$temp" while true ; do case "$1" in @@ -94,6 +100,10 @@ while true ; do BUILD_DOCKER=1 shift ;; + --cache) + USE_DOCKER_CACHE=1 + shift + ;; --nuke) DELETE_ENV=1 shift @@ -242,8 +252,12 @@ fi # Build container images if [[ $BUILD_DOCKER -eq 1 ]] ; then notice "Building docker images" + declare -a docker_build_args + if [[ "$USE_DOCKER_CACHE" != "1" ]] ; then + docker_build_args+=("--no-cache") + fi for img in $DOCKER_IMAGES; do - docker build --no-cache -t $img:$DOCKER_TAG_LOCAL -f stx/dockerfiles/$img.Dockerfile . || exit 1 + docker build "${docker_build_args[@]}" -t $img:$DOCKER_TAG_LOCAL -f stx/dockerfiles/$img.Dockerfile . || exit 1 done # else: download and retag else