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

07.Version Cache - Support for PIP #14613

Merged

Conversation

Kalimuthu-Velappan
Copy link
Contributor

During build, lots of pip packages are getting installed through pip install command.

This feature adds support for caching all the pip packages into local cache path, so that subsequent build always loads from the cache.

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
  • 202211

Description for the changelog

Ensure to add label/tag for the feature raised. example - PR#2174 under sonic-utilities repo. where, Generic Config and Update feature has been labelled as GCU.

Link to config_db schema for YANG module changes

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

@zhangyanzhao
Copy link
Collaborator

@xumia can you please help to review? Thanks.

@@ -231,6 +250,7 @@ run_pip_command()
([ "$para" == "-c" ] || [ "$para" == "--constraint" ]) && found=y
if [ "$para" == "install" ]; then
install=y
parameters[${count}]="install --trusted-host pypi.org --trusted-host files.pythonhosted.org --index-url https://pypi.org/simple "
Copy link
Collaborator

Choose a reason for hiding this comment

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

Maybe we should not add the hard code reference to the pypi indexes, we want to make sure that the customized config work fine. Some of us have the security requirement to make sure using own pipy index, not pypi.org.

Copy link
Collaborator

Choose a reason for hiding this comment

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

Maybe we should not add the hard code reference to the pypi indexes, we want to make sure that the customized config work fine. Some of us have the security requirement to make sure using own pipy index, not pypi.org.
Can we make it configurable?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

removed the hardcoded reference


if [ ! -x "$REAL_COMMAND" ] && [ " $1" == "freeze" ]; then
return 1
fi

if [ "$ENABLE_VERSION_CONTROL_PY" != "y" ]; then
if [[ "$SKIP_BUILD_HOOK" == Y || "$ENABLE_VERSION_CONTROL_PY" != "y" ]]; then
Copy link
Contributor

Choose a reason for hiding this comment

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

Y instead of y

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

if [ "$ENABLE_VERSION_CONTROL_PY" != "y" ]; then
if [[ "$SKIP_BUILD_HOOK" == Y || "$ENABLE_VERSION_CONTROL_PY" != "y" ]]; then
if [ ! -z "$(get_version_cache_option)" ]; then
mkdir -p ${PIP_CACHE_PATH}
Copy link
Contributor

Choose a reason for hiding this comment

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

Why do we need to use mkdir multiple times: here (line 228) and at line 218 with sudo?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Removed, done

done

if [ "$found" == "n" ] && [ "$install" == "y" ]; then
parameters+=("-c")
parameters+=("${tmp_version_file}")
fi

$REAL_COMMAND "${parameters[@]}"
if [ ! -z "$(get_version_cache_option)" ]; then
Copy link
Contributor

Choose a reason for hiding this comment

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

syntax error: fi for this if is missed

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Fixed

if [[ ! -e ${PIP_CACHE_PATH} ]]; then
${SUDO} mkdir -p ${PIP_CACHE_PATH}
chmod 777 ${PIP_CACHE_PATH}
fi

if [ ! -x "$REAL_COMMAND" ] && [ " $1" == "freeze" ]; then
Copy link
Contributor

Choose a reason for hiding this comment

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

This code was not changed, but probably this condition is wrong dut to whitespace before $1.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Fixed

touch ${PIP_CACHE_PATH}
FUNLOCK ${PIP_CACHE_PATH}
else
$REAL_COMMAND ${parameters[@]}
Copy link
Contributor

Choose a reason for hiding this comment

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

double quotes missed?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

fixed

$REAL_COMMAND "${parameters[@]}"
if [ ! -z "$(get_version_cache_option)" ]; then
FLOCK ${PIP_CACHE_PATH}
$REAL_COMMAND ${PKG_CACHE_OPTION} ${parameters[@]}
Copy link
Contributor

@k-v1 k-v1 May 26, 2023

Choose a reason for hiding this comment

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

double quotes missed?
compare with line 200 e.g.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Fixed

@adyeung
Copy link
Collaborator

adyeung commented May 30, 2023

@xumia @k-v1 pls review the latest patch, signoff you agree with the change.

@@ -231,6 +249,7 @@ run_pip_command()
([ "$para" == "-c" ] || [ "$para" == "--constraint" ]) && found=y
if [ "$para" == "install" ]; then
install=y
parameters[${count}]="install "
Copy link
Contributor

Choose a reason for hiding this comment

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

build failed:

#20 [16/73] RUN pip3 install --upgrade pip
#20 0.829 ERROR: unknown command "install " - maybe you meant "install"
#20 ERROR: process "/bin/sh -c pip3 install --upgrade pip" did not complete successfully: exit code: 1

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I didn't hit this issue in my local build. Looks like some ENV setting is causing the issue.
Expand as :
"install " => install ( local build)
"install " => "install " ( community build)

Anyway, I have fixed it by removing the quotes.

During build, lots of pip packages are getting installed through pip
install command.

This feature adds support for caching all the pip packages into local
cache path, so that subsequent build always loads from the cache.
@k-v1
Copy link
Contributor

k-v1 commented Jun 1, 2023

  1. Sometimes pip with option --no-cache-dir is called:

    RUN pip3 install --no-cache-dir \

    Maybe we should remove this option (not necessarily in this PR) because we use --cache-dir.

  2. I'm not sure caching for pip is really working now.
    E.g there are logs from 2nd build when version control is enabled for py2,py3 and version cache is enabled.
    a) sonic-broadcom.log:

Collecting docker==6.1.1
  Downloading docker-6.1.1-py3-none-any.whl (147 kB)
     ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ 147.9/147.9 kB 1.0 MB/s eta 0:00:00
Collecting packaging>=14.0 (from docker==6.1.1)
  Downloading packaging-23.1-py3-none-any.whl (48 kB)
     ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ 48.9/48.9 kB 2.7 MB/s eta 0:00:00
Collecting requests>=2.26.0 (from docker==6.1.1)
  Downloading requests-2.31.0-py3-none-any.whl (62 kB)
     ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ 62.6/62.6 kB 3.2 MB/s eta 0:00:00

b) docker-sonic-mgmt-framework.gz.log

Collecting connexion==2.7.0
  Downloading connexion-2.7.0-py2.py3-none-any.whl (77 kB)
     ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ 77.3/77.3 kB 1.0 MB/s eta 0:00:00
Collecting setuptools==21.0.0
  Downloading setuptools-21.0.0-py2.py3-none-any.whl (509 kB)
     ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ 509.2/509.2 kB 4.5 MB/s eta 0:00:00
Collecting grpcio-tools==1.20.0
  Downloading grpcio_tools-1.20.0-cp37-cp37m-manylinux1_x86_64.whl (2.3 MB)
     ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ 2.3/2.3 MB 22.7 MB/s eta 0:00:00

If it's working for you then we can merge this PR and I'll just retest this later and provide feedback then.

For additional information how do I test this:

  1. use git branch VERSION_CACHE_PIP
  2. mkdir ~/cache
  3. change in rules/config:
SONIC_CONFIG_BUILD_JOBS = 20
SONIC_DPKG_CACHE_SOURCE ?= /home/konstantin/cache
SONIC_VERSION_CACHE_METHOD ?= cache
SONIC_VERSION_CACHE_SOURCE ?= $(SONIC_DPKG_CACHE_SOURCE)/vcache
  1. make init && make configure PLATFORM=broadcom && make target/sonic-broadcom.bin
  2. rm -rf files/build/versions
  3. make freeze
  4. git add files/build/versions && git commit -m "test"
  5. make reset
  6. change in rules/config:
SONIC_CONFIG_BUILD_JOBS = 20
SONIC_DPKG_CACHE_SOURCE ?= /home/konstantin/cache
SONIC_VERSION_CACHE_METHOD ?= cache
SONIC_VERSION_CACHE_SOURCE ?= $(SONIC_DPKG_CACHE_SOURCE)/vcache
SONIC_VERSION_CONTROL_COMPONENTS ?= py2,py3
  1. make init && make configure PLATFORM=broadcom && make target/sonic-broadcom.bin

@Praveen-Brcm Praveen-Brcm merged commit 2627dcc into sonic-net:master Jun 5, 2023
sonic-otn pushed a commit to sonic-otn/sonic-buildimage that referenced this pull request Sep 20, 2023
During build, lots of pip packages are getting installed through pip
install command.

This feature adds support for caching all the pip packages into local
cache path, so that subsequent build always loads from the cache.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants