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

Support SONiC Reproduceable Build-debian/pip/web packages #5718

Merged
merged 18 commits into from
Dec 17, 2020

Conversation

xumia
Copy link
Collaborator

@xumia xumia commented Oct 26, 2020

- Why I did it
Support SONiC Reproduceable Build, see design doc: sonic-net/SONiC#684
Features:

  1. Collect the version information to the folder target/versions when building any targets
    Sample commands:
    make configure PLATFORM=broadcom
    make target/sonic-aboot-broadcom.swi

  2. Support to freeze the versions after build by command: make freeze
    Sample 1: Initialize the versions or rebuild the versions
    make freeze OPTIONS="-r"
    Sample 2: Freeze and merge the versions to current distribution and the architecture
    make freeze
    Sample 3: Merge the current target versions to all distributions and all architectures
    make freeze OPTIONS="-d -a"

    You can add the version change by: git add files/build/versions
    In most cases, simply run "make freeze" to freeze the versions.

  3. Control the version in build, change the configuration file rules/config
    SONIC_VERSION_CONTROL_COMPONENTS=all

  4. To upgrade the version configuration, just build any targets, then freeze your versions.
    Sample commands:
    make configure SONIC_VERSION_CONTROL_COMPONENTS=none PLATFORM=broadcom
    make SONIC_VERSION_CONTROL_COMPONENTS=none target/sonic-aboot-broadcom.swi
    make freeze OPTIONS="-d -a"

- How I did it

- How to verify it

  1. Make the targets again
    Sample commands:
    make configure PLATFORM=broadcom
    make target/sonic-aboot-broadcom.swi
  2. Freeze the versions again
    make freeze
    You can see no version change in files/build/versions, git status files/build/versions.
    The version files are in target/versions, you can find and verify all the version changes for all the build targets.

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

  • 201811
  • 201911
  • 202006

- Description for the changelog

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

@xumia xumia marked this pull request as draft October 26, 2020 13:48
@lgtm-com
Copy link

lgtm-com bot commented Oct 26, 2020

This pull request introduces 4 alerts when merging 32fa8dc into 7d4ab42 - view on LGTM.com

new alerts:

  • 3 for Unused local variable
  • 1 for Comparison of identical values #Closed

@lgtm-com
Copy link

lgtm-com bot commented Oct 26, 2020

This pull request introduces 1 alert when merging b1443cc into 7d4ab42 - view on LGTM.com

new alerts:

  • 1 for Unused local variable #Closed

@xumia xumia changed the title Support SONiC Reproduceable Build Support SONiC Reproduceable Build-debian/pip/web packages Oct 27, 2020
@lguohan lguohan requested a review from qiluo-msft October 30, 2020 14:21
@@ -0,0 +1,35 @@
#!/bin/bash
Copy link
Collaborator

@qiluo-msft qiluo-msft Nov 17, 2020

Choose a reason for hiding this comment

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

Could you add comments to explain the purpose and usage of this script?
My understanding is that they are hooks based on the vanilla executables. So:

  1. What is the new feature?
  2. Any new command line arguments?
  3. How to call vanilla ones? #Closed

Copy link
Collaborator Author

@xumia xumia Nov 18, 2020

Choose a reason for hiding this comment

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

It should be the old draft script, it will print error message if version control enabled and the version is not set. #Closed

files/build/scripts/pip Outdated Show resolved Hide resolved
@xumia xumia closed this Nov 18, 2020
@xumia
Copy link
Collaborator Author

xumia commented Nov 18, 2020

See #5786 #Resolved

@xumia xumia reopened this Nov 18, 2020
@xumia xumia marked this pull request as ready for review November 18, 2020 06:28
@lgtm-com
Copy link

lgtm-com bot commented Nov 18, 2020

This pull request introduces 1 alert when merging c912a8f into 1ba583c - view on LGTM.com

new alerts:

  • 1 for Unused local variable #Resolved

@lgtm-com
Copy link

lgtm-com bot commented Nov 18, 2020

This pull request introduces 1 alert when merging 5c150bb into 2fe79c2 - view on LGTM.com

new alerts:

  • 1 for Unused local variable #Resolved

build_debian.sh Outdated Show resolved Hide resolved
POST_VERSION_PATH=$BUILDINFO_PATH/post-versions
VERSION_DEB_PREFERENCE=$BUILDINFO_PATH/versions/01-versions-deb

. $BUILDINFO_PATH/config/buildinfo.config
Copy link
Collaborator

@qiluo-msft qiluo-msft Nov 19, 2020

Choose a reason for hiding this comment

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

buildinfo.config [](start = 25, length = 16)

I cannot find this file in this PR, or in the design doc. #Closed

Copy link
Collaborator Author

@xumia xumia Nov 19, 2020

Choose a reason for hiding this comment

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

It is created in scripts/generate_buildinfo_config.sh as the config settings for wget/curl/pip. #Resolved

fi


/usr/bin/apt-get $@
Copy link
Collaborator

@qiluo-msft qiluo-msft Nov 19, 2020

Choose a reason for hiding this comment

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

/usr/bin/apt-get [](start = 0, length = 16)

Could you not hard code this path for vanilla executables? #Closed

fi

sudo LANG=C chroot $FILESYSTEM_ROOT /bin/bash -c "dpkg -i /usr/local/share/buildinfo/sonic-build-hooks_1.0_all.deb"
sudo LANG=C chroot $FILESYSTEM_ROOT /bin/bash -c "apt-mark hold sonic-build-hooks"
Copy link
Collaborator

@qiluo-msft qiluo-msft Dec 10, 2020

Choose a reason for hiding this comment

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

apt-mark hold sonic-build-hooks [](start = 50, length = 31)

I plan to fix the issue in #6159
So you don't need this line after my PR merged. #Closed

@@ -100,6 +98,9 @@ echo '[INFO] Mount all'
## Output all the mounted device for troubleshooting
sudo LANG=C chroot $FILESYSTEM_ROOT mount

## Install the trusted gpg public keys
[ -d $TRUSTED_GPG_DIR ] && [ ! -z "$(ls $TRUSTED_GPG_DIR)" ] && sudo cp $TRUSTED_GPG_DIR/* ${FILESYSTEM_ROOT}/etc/apt/trusted.gpg.d/
Copy link
Collaborator

@qiluo-msft qiluo-msft Dec 10, 2020

Choose a reason for hiding this comment

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

Is it better to install gpg file by curl | sudo apt-key add -.
There is an example in sonic-slave-buster/Dockerfile.j2 #Closed

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

See another comment in scrpts/prepare_docker_buildinfo.sh


In reply to: 539809352 [](ancestors = 539809352)

build_debian.sh Outdated
@@ -571,6 +572,9 @@ sudo du -hsx $FILESYSTEM_ROOT
sudo mkdir -p $FILESYSTEM_ROOT/var/lib/docker
sudo mksquashfs $FILESYSTEM_ROOT $FILESYSTEM_SQUASHFS -e boot -e var/lib/docker -e $PLATFORM_DIR

scripts/collect_host_image_version_files.sh $TARGET_PATH $FILESYSTEM_ROOT
sudo LANG=C chroot $FILESYSTEM_ROOT set_build_hooks -d
Copy link
Collaborator

@qiluo-msft qiluo-msft Dec 10, 2020

Choose a reason for hiding this comment

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

This line is already covered by above line. #Closed

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Removed.


In reply to: 539813194 [](ancestors = 539813194)

fi
docker create --name $DOCKER_CONTAINER --entrypoint /bin/bash $DOCKER_IMAGE
docker cp -L $DOCKER_CONTAINER:/etc/os-release $TARGET_VERSIONS_PATH/ > /dev/null 2>&1
docker cp -L $DOCKER_CONTAINER:/usr/local/share/buildinfo/pre-versions $TARGET_VERSIONS_PATH/ > /dev/null 2>&1
Copy link
Collaborator

@qiluo-msft qiluo-msft Dec 10, 2020

Choose a reason for hiding this comment

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

/dev/null 2>&1 [](start = 95, length = 16)

Why redirect stdout and stderr? They are useful #Closed

fi
docker create --name $DOCKER_CONTAINER --entrypoint /bin/bash $DOCKER_IMAGE
docker cp -L $DOCKER_CONTAINER:/etc/os-release $TARGET_VERSIONS_PATH/ > /dev/null 2>&1
docker cp -L $DOCKER_CONTAINER:/usr/local/share/buildinfo/pre-versions $TARGET_VERSIONS_PATH/ > /dev/null 2>&1
Copy link
Collaborator

@qiluo-msft qiluo-msft Dec 10, 2020

Choose a reason for hiding this comment

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

pre [](start = 58, length = 3)

{pre,post}- #Closed

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

It is not supported by docker cp.


In reply to: 539814093 [](ancestors = 539814093)

DOCKERFILE_PRE_SCRIPT='# Auto-Generated for buildinfo
COPY ["buildinfo", "/usr/local/share/buildinfo"]
RUN dpkg -i /usr/local/share/buildinfo/sonic-build-hooks_1.0_all.deb
RUN cp -rf /usr/local/share/buildinfo/trusted.gpg.d/* /etc/apt/trusted.gpg.d/
Copy link
Collaborator

@qiluo-msft qiluo-msft Dec 10, 2020

Choose a reason for hiding this comment

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

cp -rf /usr/local/share/buildinfo/trusted.gpg.d/* /etc/apt/trusted.gpg.d/ [](start = 4, length = 73)

Is it better to install gpg file by curl | sudo apt-key add -.
There is an example in sonic-slave-buster/Dockerfile.j2 #Closed

Copy link
Collaborator Author

@xumia xumia Dec 10, 2020

Choose a reason for hiding this comment

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

It is not good enough to copy several time when build each docker image. But it should has less impact. I do not use it for several reasons as below:

  1. The curl is not a required package, as a web package it has lot of dependent packages. We want to control all packages including the curl itself.
  2. We may have several gpg files, any one can add more flexibly.

In reply to: 539815009 [](ancestors = 539815009)

Copy link
Collaborator

Choose a reason for hiding this comment

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

When you enable this feature in future, I think you need a place to download the gpg files sometime during the build process.
I agree we should not install many packages inside a docker image just for a one time curl.
How about download outside docker build, and COPY into the image?


In reply to: 540038466 [](ancestors = 540038466,539815009)

[ -z "$DISTRO" ] && DISTRO=jessie
fi

DOCKERFILE_PRE_SCRIPT='# Auto-Generated for buildinfo
Copy link
Collaborator

@qiluo-msft qiluo-msft Dec 10, 2020

Choose a reason for hiding this comment

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

DOCKERFILE_PRE_SCRIPT [](start = 0, length = 21)

If gpg comment is right, then DOCKERFILE_PRE_SCRIPT has only 2 command lines. Suggest move them into docker-base, docker-slave's Dockerfile as plaintext. No need to manipulate Dockerfile here. #Closed

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

See the comments below in pending.


In reply to: 539816717 [](ancestors = 539816717)

VERSION_DEB_PREFERENCE=$BUILD_VERSIONS_PATH/01-versions-deb

# Enable the build hooks
set_build_hooks
Copy link
Collaborator

@qiluo-msft qiluo-msft Dec 10, 2020

Choose a reason for hiding this comment

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

Better name: symlink_hooks #Closed

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Changed to symlink_build_hooks.


In reply to: 539817491 [](ancestors = 539817491)

DOCKERFILE_PRE_SCRIPT='# Auto-Generated for buildinfo
COPY ["buildinfo", "/usr/local/share/buildinfo"]
RUN dpkg -i /usr/local/share/buildinfo/sonic-build-hooks_1.0_all.deb
COPY ["buildinfo/trusted.gpg.d/*", "/etc/apt/trusted.gpg.d/"]
Copy link
Collaborator

@qiluo-msft qiluo-msft Dec 14, 2020

Choose a reason for hiding this comment

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

COPY [](start = 0, length = 4)

Move the download process into above deb package #Resolved

awk -v text="${DOCKERFILE_PRE_SCRIPT}" -v linenumber=$LINE_NUMBER 'NR==linenumber{print text}1' $DOCKERFILE > $TEMP_FILE

# Append the docker build script at the end of the docker file
echo "RUN post_run_buildinfo" >> $TEMP_FILE
Copy link
Collaborator

@qiluo-msft qiluo-msft Dec 14, 2020

Choose a reason for hiding this comment

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

echo [](start = 4, length = 4)

Corner case: $TEMP_FILE may be not end with \n #Closed

@xumia
Copy link
Collaborator Author

xumia commented Dec 15, 2020

retest vsimage please

4 similar comments
@xumia
Copy link
Collaborator Author

xumia commented Dec 15, 2020

retest vsimage please

@xumia
Copy link
Collaborator Author

xumia commented Dec 16, 2020

retest vsimage please

@xumia
Copy link
Collaborator Author

xumia commented Dec 16, 2020

retest vsimage please

@xumia
Copy link
Collaborator Author

xumia commented Dec 16, 2020

retest vsimage please

@xumia xumia merged commit 55a7075 into sonic-net:master Dec 17, 2020
lguohan added a commit that referenced this pull request Dec 19, 2020
xumia added a commit to xumia/sonic-buildimage-1 that referenced this pull request Dec 20, 2020
xumia added a commit that referenced this pull request Dec 21, 2020
…6255)

* Revert "Revert "Support SONiC Reproduceable Build-debian/pip/web packages (#5718)""

This reverts commit 17497a6.

* Revert "Revert "Remove unnecessary sudo authority in build Makefile (#6237)""

This reverts commit 163b711.
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.

2 participants