From a3f1769a34f2fd8c8a95b2f26ad028937a4fcb55 Mon Sep 17 00:00:00 2001 From: xumia <59720581+xumia@users.noreply.github.com> Date: Thu, 2 Dec 2021 09:04:40 +0800 Subject: [PATCH] [Build]: Cleanup the reproducible mirrors when build complete (#9132) Why I did it The reproducible build mirrors are only used during the build, the mirrors can be removed after that. --- src/sonic-build-hooks/scripts/buildinfo_base.sh | 17 +++++++++++++++++ .../scripts/post_run_buildinfo | 1 + src/sonic-build-hooks/scripts/pre_run_buildinfo | 1 + 3 files changed, 19 insertions(+) diff --git a/src/sonic-build-hooks/scripts/buildinfo_base.sh b/src/sonic-build-hooks/scripts/buildinfo_base.sh index 0fbcd57393b3..d20d68581533 100755 --- a/src/sonic-build-hooks/scripts/buildinfo_base.sh +++ b/src/sonic-build-hooks/scripts/buildinfo_base.sh @@ -11,6 +11,7 @@ POST_VERSION_PATH=$BUILDINFO_PATH/post-versions VERSION_DEB_PREFERENCE=$BUILDINFO_PATH/versions/01-versions-deb WEB_VERSION_FILE=$VERSION_PATH/versions-web BUILD_WEB_VERSION_FILE=$BUILD_VERSION_PATH/versions-web +REPR_MIRROR_URL_PATTERN='http:\/\/packages.trafficmanager.net\/debian' . $BUILDINFO_PATH/config/buildinfo.config @@ -59,6 +60,22 @@ check_if_url_exist() fi } +# Enable or disable the reproducible mirrors +set_reproducible_mirrors() +{ + # Remove the charater # in front of the line if matched + local expression="s/^#\(.*$REPR_MIRROR_URL_PATTERN\)/\1/" + if [ "$1" = "-d" ]; then + # Add the charater # in front of the line if match + expression="s/^deb.*$REPR_MIRROR_URL_PATTERN/#\0/" + fi + + local mirrors="/etc/apt/sources.list $(ls /etc/apt/sources.list.d/)" + for mirror in $mirrors; do + sed -i "$expression" "$mirror" + done +} + download_packages() { local parameters=("$@") diff --git a/src/sonic-build-hooks/scripts/post_run_buildinfo b/src/sonic-build-hooks/scripts/post_run_buildinfo index a8dab41021b1..614389fd424c 100755 --- a/src/sonic-build-hooks/scripts/post_run_buildinfo +++ b/src/sonic-build-hooks/scripts/post_run_buildinfo @@ -12,3 +12,4 @@ rm -rf $BUILD_VERSION_PATH/* # Disable the build hooks symlink_build_hooks -d +set_reproducible_mirrors -d diff --git a/src/sonic-build-hooks/scripts/pre_run_buildinfo b/src/sonic-build-hooks/scripts/pre_run_buildinfo index a8450690b6ff..3cf0cf7c8dfe 100755 --- a/src/sonic-build-hooks/scripts/pre_run_buildinfo +++ b/src/sonic-build-hooks/scripts/pre_run_buildinfo @@ -10,6 +10,7 @@ mkdir -p $LOG_PATH [ -d $PRE_VERSION_PATH ] && rm -rf $PRE_VERSION_PATH collect_version_files $PRE_VERSION_PATH symlink_build_hooks +set_reproducible_mirrors chmod -R a+rw $BUILDINFO_PATH