debian: --cache avoid pulling builder images

Changed the "--cache" option to skip pulling images that already exist
locally. Otherwise a locally-built image would be overwritten by a
downloaded one.

TESTS
===============================
Call the script with various permutations of --cache & --rebuild, with &
without deleting cached images prior.

Story: 2009897
Task: 45225

Signed-off-by: Davlet Panech <davlet.panech@windriver.com>
Change-Id: I37435d3d7a6d1a20b87794530cc937d759674685
This commit is contained in:
Davlet Panech 2022-04-29 16:08:15 -04:00
parent 011af73b11
commit c7e4e6b236
1 changed files with 11 additions and 8 deletions

View File

@ -18,10 +18,12 @@ Initialize StarlingX build environment & (re-)start builder pods
--rebuild[=IMG,...]
build specified 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.
--cache when rebuilding, allow docker to use its filesystem cache
when pulling, skip images that already exist locally
CAUTION: this option may not pick up all the changes to
docker source files and is meant for debugging
the build scripts.
END
}
@ -281,20 +283,21 @@ fi
# Pull images that we didn't rebuild
PULL_DOCKER_IMAGES=$(
for img in ${DOCKER_IMAGES} ; do
found=no
built=no
for build_img in ${BUILD_DOCKER_IMAGES} ; do
if [[ "$img" == "$build_img" ]] ; then
found=yes
built=yes
break
fi
done
if [[ "$found" != "yes" ]] ; then
if [[ "$built" != "yes" ]] && \
{ [[ "$USE_DOCKER_CACHE" != 1 ]] || ! docker image inspect ${img}:${DOCKER_TAG_LOCAL} >/dev/null 2>&1 ; } ; then
echo "$img"
fi
done
)
if [[ -n "$PULL_DOCKER_IMAGES" ]] ; then
notice "Pulling docker images"
notice "Pulling docker images: "$PULL_DOCKER_IMAGES
for img in $PULL_DOCKER_IMAGES; do
docker pull ${DOCKER_PREFIX}${img}:${DOCKER_TAG} || exit 1
docker tag ${DOCKER_PREFIX}${img}:${DOCKER_TAG} ${img}:${DOCKER_TAG_LOCAL} || exit 1