-
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
06.Version Cache - Support for wget #14612
06.Version Cache - Support for wget #14612
Conversation
670c1e4
to
a72913f
Compare
@xumia can you please help to review? Thanks. |
Could you please clarify how to test a build with version cache correctly?
For DPKG_CACHE it's obvious:
But what options should I choose to enable vcache? |
BTW we already have PR with number 06 for vcache: #13024 |
In order to use version vache(VCACHE), SONIC_VERSION_CACHE_METHOD=cache variable should be used. Here are the recommended settings: For the subsequent build to use the VCACHE, both the version variable needs to be set. DPKG cache can be independent of the version cache and it will superset of VCACHE.
|
continue | ||
fi | ||
FLOCK ${SRC_FILENAME} | ||
cp ${DST_FILENAME} ${SRC_FILENAME} |
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.
Does it work with sonic-slave docker containers?
I mean when we build sonic-slave container we download some files (e.g. golang binaries) using wget.
According to logs it saved something.
#20 88.54 Saving into web cache URL:https://sonicstorage.blob.core.windows.net/public/fips/bullseye/0.1/amd64/golang-1.15-go_1.15.15-1~deb11u4%2Bfips_amd64.deb, DST:/sonic/target/vcache/sonic-slave-bullseye/web/golang-1.15-go_1.15.15-1~deb11u4%2Bfips_amd64.deb-b60f6db62805696b47ab422ab798fe56.tgz, SRC:golang-go.deb
#20 117.0 Saving into web cache URL:https://sonicstorage.blob.core.windows.net/public/fips/bullseye/0.1/amd64/golang-1.15-src_1.15.15-1~deb11u4%2Bfips_amd64.deb, DST:/sonic/target/vcache/sonic-slave-bullseye/web/golang-1.15-src_1.15.15-1~deb11u4%2Bfips_amd64.deb-1c920937aa49b602a1bfec3c49747131.tgz, SRC:golang-src.deb
#61 2.627 Saving into web cache URL:https://github.com/bazelbuild/bazelisk/releases/latest/download/bazelisk-linux-amd64, DST:/sonic/target/vcache/sonic-slave-bullseye/web/bazelisk-linux-amd64-d9f6a4c3197625b1835b523697eb953e.tgz, SRC:/usr/local/bin/bazel
But there are no files in vcache directory.
➜ vcache tree
.
├── sonic-slave-bullseye
└── sonic-slave-buster
2 directories, 0 files
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.
Yes, it works for slave containers as well
Vcache is disabled for now, it will get enabled once everything is done.
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.
I tried to build your branch VERSION_CACHE_WGET
with SONIC_VERSION_CACHE_METHOD=cache
enabled.
But I didn't find files like golang binaries from sonic-slaves in vcache directory (SONIC_VERSION_CACHE_SOURCE
) after build finished.
Is it expected behaviour?
I can retest this. I'll provide build logs if this bug is duplicated.
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.
Seems like these files are extracted as part of cache.tgz.
So we can ignore this issue for now and retest it lately when all parts of vcache are merged.
real_version=$(get_url_version $url) || { echo "get_url_version $url failed"; exit 1; } | ||
if [ "$real_version" != "$version" ]; then | ||
log_err "Failed to verify url: $url, real hash value: $real_version, expected value: $version_filename" 1>&2 | ||
real_version=$(get_url_version $url) |
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.
Why do you call get_url_version two times: line 215 and 218?
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.
done
SRC_FILENAME=${WEB_CACHE_PATH}/${WEB_FILENAME}-${VERSION}.tgz | ||
if [ -f ${SRC_FILENAME} ]; then | ||
log_info "Loading from web cache URL:${url}, SRC:${SRC_FILENAME}, DST:${DST_FILENAME}" | ||
cp ${SRC_FILENAME} ${DST_FILENAME} |
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.
Maybe need to add double quote around SRC_FILENAME and DST_FILENAME variables.
Filenames unlike urls can contain whitespaces.
So need to check if vcache works correctly in this case:
wget $url -o "my file"
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.
done
for (( i=0; i<${#parameters[@]}; i++ )) | ||
do | ||
local para=${parameters[$i]} | ||
local nexti=$((i+1)) | ||
if [[ "$para" == *://* ]]; then | ||
if [[ "$para" == -o || "$para" == -O ]]; then |
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.
You can find in SONiC Makefiles something like this:
sonic-buildimage/src/lldpd/Makefile
Line 23 in a09048a
wget -NO "$(DSC_FILE)" $(DSC_FILE_URL) |
Probably this code won't be able to parse
-NO
correctly.
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 -NO
is not correct combination. I got warning WARNING: timestamping does nothing in combination with -O. See the manual for details.
I don't know why this is used in Makefiles.
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.
Done
be60409
to
99e9fee
Compare
for (( i=0; i<${#parameters[@]}; i++ )) | ||
do | ||
local para=${parameters[$i]} | ||
local nexti=$((i+1)) | ||
if [[ "$para" == *://* ]]; then | ||
if [[ "$para" =~ -[^-]*o.* || "$para" =~ -[^-]*O.* ]]; then |
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.
Still need to fix this regex.
My test build failed with this error:
#20 30.32 dpkg: error: cannot access archive 'golang-go.deb': No such file or directory
And I decided to test the regex using simple bash script:
#!/bin/bash
[[ "$1" =~ -[^-]*o || "$1" =~ -[^-]*O.* ]] && echo true || echo false
As a result many false positive:
./1.sh -o
true
./1.sh golang.deb
false
./1.sh golang-go.deb
true
./1.sh www.test-url.com
true
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.
Fixed
99e9fee
to
5499c4e
Compare
One question about implementation. What I mean: cache/vcache/sonic-slave-buster/web:
cache/vcache/sonic-slave-bullseye/web:
Probably we can save some space if we use a single directory |
[ -f ${BUILD_WEB_VERSION_FILE} ] && build_version=$(grep "^${url}==${real_version}" ${BUILD_WEB_VERSION_FILE} | awk -F"==" '{print $NF}') | ||
if [ -z ${build_version} ]; then | ||
echo "$url==$real_version" >> ${BUILD_WEB_VERSION_FILE} | ||
sort ${BUILD_WEB_VERSION_FILE} -o ${BUILD_WEB_VERSION_FILE} -u &> /dev/null |
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 append "$url==$real_version"
to the file ${BUILD_WEB_VERSION_FILE}
on the line 227 if $real_version
is valid (not md5sum of empty string).
So I don't understand what we exactly do here (lines 233-236). Why do we need to save this info again.
Moreover if ${BUILD_WEB_VERSION_FILE}
contains duplicated lines for ${url}==${real_version}
then ${build_version}
will contain multiple hashes and condition on the line 234 will failed: line 234: [: c1c557036197188a22ec285fa53149d8: binary operator expected
.
Example:
1. wget www.url.com/file.tar.gz -O file
(line 227: append url==real-version to the web_version_file)
2. wget www.url.com/file.tar.gz -O file2
(line 227: append url==real-version to the web_version_file)
3. get error on line 233-234 due to duplicated strings in web_version_file
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.
Basically, we add the ${url}==${real_version} combination into the file ${BUILD_WEB_VERSION_FILE} if the entry does not exist already and also remove any duplicate entry in the file ${BUILD_WEB_VERSION_FILE}.
line 234: [: => error is due to different shell version, I have fixed it.
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.
I can clarify this.
Line 227:
[[ $real_version == "d41d8cd98f00b204e9800998ecf8427e" ]] || echo "$url==$real_version" >> ${BUILD_WEB_VERSION_FILE}
We add this entry (url==real_version) into the file unconditionally. The only condition here is comparison with a hash of empty string. If real_version
is equal to the hash of empty string then probably there no reason to add this entry into the file.
You say if the entry does not exist already
. But I don't understand how it's possible if the entry has a valid real_version
and doesn't exist in file if we just added it at line 227. Probably we can remove all this fragment of code where you extract build_version and keep only line 236 where you remove possible duplicate entries from file.
That's my opinion. Maybe I missed something.
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.
Probably it's last question that should be resolved before merge this PR.
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 the clarification. I realized the empty HASH part and thanks for pointing it out.
It will add the entry only when it is not empty or valid but not exists in the version file.
Let me know if this is OK.
for (( i=0; i<${#parameters[@]}; i++ )) | ||
do | ||
local para=${parameters[$i]} | ||
local nexti=$((i+1)) | ||
if [[ "$para" == *://* ]]; then | ||
if [[ "$para" =~ ^-[^-]*o.* || "$para" =~ ^-[^-]*O.* ]]; then |
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.
Also possible:
wget www.url.com/file.tar.gz -P directory
wget www.url.com/file.tar.gz -O directory/filename.tar.gz
- (only for curl)
curl www.url.com/file.tar.gz > filename.tar.gz
wget www.url.com/file.tar.gz -O "file name.tar.gz"
- not sure, but probably need to recheck this too.curl -O www.url.com/file.tar.gz
curl -O www.url.com/file.tar.gz --output-dir test
I'm not sure should we try to fix this or not. I didn't find such a code in current SONiC codebase.
Maybe @xumia can help here and say should we fix or ignore this.
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.
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.
As we ran out of time for the current release, we can take this up on the subsequent release.
Please approve the PR if there are no further changes.
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.
Yes, we can ignore this for now and retest again when all parts of vcache are merged.
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.
Agree to ignore for now. It may be a little hard to cover all the scenarios, covering the current used scenarios should be good enough.
Yes, we need to keep the separate cache contents for each slave container build, because the docker builder doesn't use shared volume mount during the build, like So we need to export these contents inside the docker builder as a context file. So this needs to be packed as a separate tgz file. |
c6062bf
to
f1a7e59
Compare
[ -f ${BUILD_WEB_VERSION_FILE} ] && build_version=$(grep "^${url}==${real_version}" ${BUILD_WEB_VERSION_FILE} | awk -F"==" '{print $NF}') | ||
if [ ! -z "${build_version}" ]; then | ||
echo "$url==$real_version" >> ${BUILD_WEB_VERSION_FILE} | ||
sort ${BUILD_WEB_VERSION_FILE} -o ${BUILD_WEB_VERSION_FILE} -u &> /dev/null | ||
fi |
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.
Now we have incorrect logic:
- download new file from some url
- try to extract
build_version
from ${BUILD_WEB_VERSION_FILE} build_version
is empty because it was 1st download from this url- condition
[ ! -z "${build_version}" ];
failed becausebuild_version
is empty, but you check if this is not empty using! -z
(it means not has no value). - you never add new entry to this file
Maybe just replace this code with
echo "$url==$real_version" >> ${BUILD_WEB_VERSION_FILE}
sort ${BUILD_WEB_VERSION_FILE} -o ${BUILD_WEB_VERSION_FILE} -u
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.
My bad, I forgot to remove ! in the if condition. Thanks for catching this.
I modified the code as you suggested.
When a package is referenced from the web through wget command, it downloads the package for every build. This feature caches all the packages that are being downloaded from the web, so that subsequent build always loads the cache instead of from web.
f1a7e59
to
3a0bc39
Compare
When a package is referenced from the web through wget command, it downloads the package for every build. This feature caches all the packages that are being downloaded from the web, so that subsequent build always loads the cache instead of from web.
When a package is referenced from the web through wget command, it downloads the package for every build.
This feature caches all the packages that are being downloaded from the web, so that subsequent build always loads the cache instead of from web.
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
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)