Skip to content
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

05.Version cache - docker dpkg caching support #12005

Merged

Conversation

Kalimuthu-Velappan
Copy link
Contributor

This feature caches all the deb files during docker build and stores them
into version cache.

It loads the cache file if already exists in the version cache and copies the extracted
deb file from cache file into Debian cache path( /var/cache/apt/archives).

The apt-install always installs the deb file from the cache if exists, this
avoid unnecessary package download from the repo and speeds up the overall build.

The cache file is selected based on the SHA value of version dependency
files.

Why I did it

How I did it

How to verify it

Which release branch to backport (provide reason below if selected)

  • 201811
  • 201911
  • 202006
  • 202012
  • 202106
  • 202111
  • 202205

Description for the changelog

Link to config_db schema for YANG module changes

A picture of a cute animal (not mandatory but encouraged)

@lgtm-com
Copy link

lgtm-com bot commented Sep 8, 2022

This pull request introduces 1 alert when merging a7949e321850d73be472e832a750aeb9d102cf16 into 38cc35f - view on LGTM.com

new alerts:

  • 1 for Modification of parameter with default

@Kalimuthu-Velappan
Copy link
Contributor Author

/azpw run Azure.sonic-buildimage

@mssonicbld
Copy link
Collaborator

/AzurePipelines run Azure.sonic-buildimage

@azure-pipelines
Copy link

Azure Pipelines successfully started running 1 pipeline(s).

@adyeung
Copy link
Collaborator

adyeung commented Sep 14, 2022

@xumia @liushilongbuaa submitter has taken the time to split the original code PR to smaller submissions for review, pls help take a look

@zhangyanzhao
Copy link
Collaborator

@xumia @liushilongbuaa can you please review the PR? Thanks.

Makefile.work Outdated
@@ -217,15 +230,21 @@ SLAVE_TAG = $(shell \
(cat $(SLAVE_DIR)/Dockerfile.user \
$(SLAVE_DIR)/Dockerfile \
$(SLAVE_DIR)/buildinfo/versions/versions-* \
.git/HEAD \
.git/HEAD 2>/dev/null \
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

.git/HEAD

PR build will not have chance to use cache, can we remove it?

/_work/27/s$ cat .git/HEAD
ref: refs/heads/master-12001

In current PR build, it will use the - as the name.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done

#echo ${!lock_fd}
if ! flock -x -w ${timeout} "${!lock_fd}" ; then
echo "ERROR: Lock timeout trying to access ${filename}.flock";
exit 1;
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

How about printing to stderr

echo "ERROR: Lock timeout trying to access ${filename}.flock" 1>&2;

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done

APT::Keep-Downloaded-Packages "true";
EOF

fi
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please remove the empty line

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done

# Extract the cache inside the docker build.
if [ -f ${PKG_CACHE_FILE_NAME} ]; then
tar -C ${PKG_CACHE_PATH} -xvf ${PKG_CACHE_FILE_NAME}
test -e ${PKG_CACHE_PATH}/deb && cp ${PKG_CACHE_PATH}/deb/* /var/cache/apt/archives/
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please remove the additional space character at the end of line 40, thanks.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done

@Kalimuthu-Velappan Kalimuthu-Velappan force-pushed the DOCKER_DPKG_CACHE_FRAMEWORK branch from 715bbc5 to 68ed10e Compare November 23, 2022 13:43
@Kalimuthu-Velappan Kalimuthu-Velappan force-pushed the DOCKER_DPKG_CACHE_FRAMEWORK branch from 68ed10e to b041acb Compare December 1, 2022 04:16
It defines and passes the necessary version cache environment variables
to the caching framework.

It adds the utils script for shared cache file access.

It also adds the post-cleanup logic for cleaning the unwanted files from
the docker/image after the version cache creation.
Added DBGOPT Make variable to enable the cache framework
scripts in trace mode. This option takes the part name of the script to
enable the particular shell script in trace mode.

Multiple shell script names can also be given.

	Eg: make DBGOPT="image|docker"

Added verbose mode to dump the version merge details during
build/dry-run mode.
	Eg: scripts/versions_manager.py freeze -v \
		'dryrun|cmod=docker-swss|cfile=versions-deb|cname=all|stage=sub|stage=add'
This feature caches all the deb files during docker build and stores them
into version cache.

It loads the cache file if already exists in the version cache and copies the extracted
deb file from cache file into Debian cache path( /var/cache/apt/archives).

The apt-install always installs the deb file from the cache if exists, this
avoid unnecessary package download from the repo and speeds up the overall build.

The cache file is selected based on the SHA value of version dependency
files.
@xumia xumia merged commit 0dc22bd into sonic-net:master Dec 12, 2022
@kv-y kv-y mentioned this pull request Dec 14, 2022
@mssonicbld
Copy link
Collaborator

@Kalimuthu-Velappan PR conflicts with 202211 branch

@saiarcot895
Copy link
Contributor

@Kalimuthu-Velappan can this be cherry-picked to the 202211 and 202205 branches? This will save about 100MB of disk space, which will be immensely helpful on low-storage platforms.

@yxieca
Copy link
Contributor

yxieca commented Mar 13, 2023

@Kalimuthu-Velappan this change is desired for 202205 branch to help reduce image size and installation footprint. Please help create PR for 202205 branch.

@mssonicbld
Copy link
Collaborator

@Kalimuthu-Velappan PR conflicts with 202205 branch

oleksandrivantsiv added a commit to oleksandrivantsiv/sonic-buildimage that referenced this pull request Apr 11, 2023
oleksandrivantsiv added a commit to oleksandrivantsiv/sonic-buildimage that referenced this pull request Apr 11, 2023
    Revert "05.Version cache - docker dpkg caching support (sonic-net#12005)"

    This reverts commit 0dc22bd.
oleksandrivantsiv added a commit to oleksandrivantsiv/sonic-buildimage that referenced this pull request Apr 11, 2023
liushilongbuaa pushed a commit to liushilongbuaa/sonic-buildimage that referenced this pull request Jun 19, 2023
This feature caches all the deb files during docker build and stores them
into version cache.

It loads the cache file if already exists in the version cache and copies the extracted
deb file from cache file into Debian cache path( /var/cache/apt/archives).

The apt-install always installs the deb file from the cache if exists, this
avoid unnecessary package download from the repo and speeds up the overall build.

The cache file is selected based on the SHA value of version dependency
files.

Why I did it
How I did it
How to verify it

* 03.Version-cache - framework environment settings

It defines and passes the necessary version cache environment variables
to the caching framework.

It adds the utils script for shared cache file access.

It also adds the post-cleanup logic for cleaning the unwanted files from
the docker/image after the version cache creation.

* 04.Version cache - debug framework

Added DBGOPT Make variable to enable the cache framework
scripts in trace mode. This option takes the part name of the script to
enable the particular shell script in trace mode.

Multiple shell script names can also be given.

	Eg: make DBGOPT="image|docker"

Added verbose mode to dump the version merge details during
build/dry-run mode.
	Eg: scripts/versions_manager.py freeze -v \
		'dryrun|cmod=docker-swss|cfile=versions-deb|cname=all|stage=sub|stage=add'

* 05.Version cache - docker dpkg caching support

This feature caches all the deb files during docker build and stores them
into version cache.

It loads the cache file if already exists in the version cache and copies the extracted
deb file from cache file into Debian cache path( /var/cache/apt/archives).

The apt-install always installs the deb file from the cache if exists, this
avoid unnecessary package download from the repo and speeds up the overall build.

The cache file is selected based on the SHA value of version dependency
files.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

8 participants