-
Notifications
You must be signed in to change notification settings - Fork 1.4k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
02.Version cache - docker cache build framework #12001
Conversation
/azpw run Azure.sonic-buildimage |
/AzurePipelines run Azure.sonic-buildimage |
Azure Pipelines successfully started running 1 pipeline(s). |
/azpw run Azure.sonic-buildimage |
/AzurePipelines run Azure.sonic-buildimage |
Azure Pipelines successfully started running 1 pipeline(s). |
/azpw run Azure.sonic-buildimage |
/AzurePipelines run Azure.sonic-buildimage |
Azure Pipelines successfully started running 1 pipeline(s). |
/azpw run Azure.sonic-buildimage |
/AzurePipelines run Azure.sonic-buildimage |
Azure Pipelines successfully started running 1 pipeline(s). |
@xumia @liushilongbuaa submitter has taken the time to split the original code PR to smaller submissions for review, pls help take a look |
Makefile.cache provides the same feature. |
Yes, it is an extension of the DPKG caching framework. |
/azpw run Azure.sonic-buildimage |
/AzurePipelines run Azure.sonic-buildimage |
Azure Pipelines successfully started running 1 pipeline(s). |
c556ba9
to
789f8e2
Compare
|
It is just a framework to copy files from the docker builder to the host. Currently, In this patch, nothing has been added to this file. This PR has only the framework part of the version cache framework. The following patches in this series will add files to it. and more coming on. |
tried the below commands, but it doesn't generate the expected out file in the host. #cat Dockerfile FROM scratch AS export-stage #docker build --no-cache -o out . |
tar -C ${PKG_CACHE_PATH} --exclude=cache.tgz -zcvf ${PKG_CACHE_FILE_NAME} . | ||
#set +x | ||
if [[ ! ${IMAGENAME} =~ host-image ]]; then | ||
sleep 1;echo -e "\n_VCSTART_"; (cat ${PKG_CACHE_FILE_NAME} | base64); echo -e "_VCEND_\n";sleep 1 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is it possible to use the scp command or the other RPC APIs to copy the content to the slave container? It is a little workaround to copy content by log.
Azure Pipelines successfully started running 1 pipeline(s). |
@Kalimuthu-Velappan , the solution is good. Can we only use two docker build steps? Split the Dockerfile into two parts, Dockerfile1 and Dockerfile2, Dockerfile1 is to do the normal installation without cleanup, Dockerfile2 is only to do the cleanup, it can be generated from a common j2 template for all docker builds. We can add a step to copy the content from the image. It is not necessary to depend on DOCKER_BUILDKIT, and makes the copy steps more controllable not in the Dockerfile. But I think the solution you provided is good enough. |
I split them into two docker files as you suggested. Could you just take look at the sequence and let me know your thoughts? cat Dockerfile
cat Dockerfile.cleanup
cat build.sh#!/bin/bash
./build.sh
|
54dfff0
to
f51a117
Compare
/azpw run Azure.sonic-buildimage |
/AzurePipelines run Azure.sonic-buildimage |
Azure Pipelines successfully started running 1 pipeline(s). |
DISTRO=${DISTRO} apt-get update && apt-get install -y rsync | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We do not need it (line 32), we do not need to install rsync, right?
f51a117
to
d058dc2
Compare
@Kalimuthu-Velappan , looks good to me, only left one comment, do we need to install rsync? |
rsync is required for go module sync and it is being used by other PRs. I will find better way to remove this and will on it. |
@Kalimuthu-Velappan , could you please fix the code conflicts? |
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 uses the multi-stage docker file to copy the cache content, cleanup the temporary files and creates the final sonic docker image.
d058dc2
to
d5edc7b
Compare
[ -d $BUILD_VERSION_PATH ] && [ ! -z "$(ls -A $BUILD_VERSION_PATH)" ] && cp -rf $BUILD_VERSION_PATH/* $POST_VERSION_PATH | ||
rm -rf $BUILD_VERSION_PATH/* | ||
#Save the cache file for exporting it to host. | ||
tar -C ${PKG_CACHE_PATH} --exclude=cache.tgz -zcvf /cache.tgz . |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
BTW, what do you think about using pigz here?
In my tests I get a big improvements in time when use it instead of gzip:
#12825
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for your suggestion.
As you said, I have already used this in the binary optimization PR.
#10718
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
Cherry-pick PR to 202211: #13771 |
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
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.
Why I did it
How I did it
How to verify it
Which release branch to backport (provide reason below if selected)
Description for the changelog
Link to config_db schema for YANG module changes
A picture of a cute animal (not mandatory but encouraged)