mirror of
https://github.com/Telecominfraproject/ols-nos.git
synced 2025-11-01 02:27:58 +00:00
02.Version cache - docker cache build framework (#12001)
During docker build, host files can be passed to the docker build through
docker context files. But there is no straightforward way to transfer
the files from docker build to host.
This feature provides a tricky way to pass the cache contents from docker
build to host. It tar's the cached content and encodes them as base64 format
and passes it through a log file with a special tag as 'VCSTART and VCENT'.
Slave.mk in the host, it extracts the cache contents from the log and stores them
in the cache folder. Cache contents are encoded as base64 format for
easy passing.
<!--
Please make sure you've read and understood our contributing guidelines:
https://github.com/Azure/SONiC/blob/gh-pages/CONTRIBUTING.md
** Make sure all your commits include a signature generated with `git commit -s` **
If this is a bug fix, make sure your description includes "fixes #xxxx", or
"closes #xxxx" or "resolves #xxxx"
Please provide the following information:
-->
#### Why I did it
#### How I did it
#### How to verify it
This commit is contained in:
committed by
GitHub
parent
7a0152ad15
commit
aaeafa8411
@@ -1,12 +1,17 @@
|
||||
#!/bin/bash
|
||||
|
||||
set -x
|
||||
DOCKER_IMAGE=$1
|
||||
TARGET_PATH=$2
|
||||
DOCKER_IMAGE_TAG=$3
|
||||
DOCKER_PATH=$4
|
||||
DOCKER_FILE=$5
|
||||
|
||||
[ -z "$TARGET_PATH" ] && TARGET_PATH=./target
|
||||
|
||||
DOCKER_IMAGE_NAME=$(echo $DOCKER_IMAGE | cut -d: -f1 | sed "s/-$DOCKER_USERNAME\$//")
|
||||
DOCKER_CONTAINER=$DOCKER_IMAGE_NAME
|
||||
#Create the container specific to the user tag and slave tag
|
||||
DOCKER_CONTAINER=${DOCKER_IMAGE_TAG/:/-}
|
||||
TARGET_VERSIONS_PATH=$TARGET_PATH/versions/dockers/$DOCKER_IMAGE_NAME
|
||||
|
||||
[ -d $TARGET_VERSIONS_PATH ] && rm -rf $TARGET_VERSIONS_PATH
|
||||
@@ -18,8 +23,16 @@ export DOCKER_CLI_EXPERIMENTAL=enabled
|
||||
if docker container inspect $DOCKER_IMAGE > /dev/null 2>&1; then
|
||||
docker container rm $DOCKER_IMAGE > /dev/null
|
||||
fi
|
||||
docker create --name $DOCKER_CONTAINER --entrypoint /bin/bash $DOCKER_IMAGE
|
||||
docker create --name $DOCKER_CONTAINER --entrypoint /bin/bash $DOCKER_IMAGE_TAG
|
||||
docker cp -L $DOCKER_CONTAINER:/etc/os-release $TARGET_VERSIONS_PATH/
|
||||
docker cp -L $DOCKER_CONTAINER:/usr/local/share/buildinfo/pre-versions $TARGET_VERSIONS_PATH/
|
||||
docker cp -L $DOCKER_CONTAINER:/usr/local/share/buildinfo/post-versions $TARGET_VERSIONS_PATH/
|
||||
|
||||
# Save the cache contents from docker build
|
||||
IMAGENAME=${DOCKER_IMAGE_TAG} j2 files/build_templates/build_docker_cache.j2 > ${DOCKER_FILE}.cleanup
|
||||
docker tag ${DOCKER_IMAGE_TAG} tmp-${DOCKER_IMAGE_TAG}
|
||||
DOCKER_BUILDKIT=1 docker build -f ${DOCKER_PATH}/Dockerfile.cleanup --target output -o target/vcache/${DOCKER_IMAGE_NAME} ${DOCKER_PATH}
|
||||
DOCKER_BUILDKIT=1 docker build -f ${DOCKER_PATH}/Dockerfile.cleanup --no-cache --target final --tag ${DOCKER_IMAGE_TAG} ${DOCKER_PATH}
|
||||
docker rmi tmp-${DOCKER_IMAGE_TAG}
|
||||
|
||||
docker container rm $DOCKER_CONTAINER
|
||||
|
||||
Reference in New Issue
Block a user