From 0b98c442b40ec7f1e233ebdd743723d9418f323d Mon Sep 17 00:00:00 2001 From: shilongliu Date: Fri, 15 Jan 2021 05:15:42 +0000 Subject: [PATCH 1/4] support reproduceable build for git clone Signed-off-by: shilongliu --- src/sonic-build-hooks/hooks/git | 76 +++++++++++++++++++++++++++++++++ 1 file changed, 76 insertions(+) create mode 100755 src/sonic-build-hooks/hooks/git diff --git a/src/sonic-build-hooks/hooks/git b/src/sonic-build-hooks/hooks/git new file mode 100755 index 000000000000..f05f5c75714e --- /dev/null +++ b/src/sonic-build-hooks/hooks/git @@ -0,0 +1,76 @@ +#!/bin/bash + +parse_config(){ + . /usr/local/share/buildinfo/scripts/buildinfo_base.sh + [ -z $REAL_COMMAND ] && REAL_COMMAND=$(get_command git) + + version_file=$VERSION_PATH/versions-git + new_version_file=$BUILD_VERSION_PATH/versions-git + + MODE_CLONE=0 + # parse input parameters + for i in "$@" + do + if [[ $i == "clone" ]];then + MODE_CLONE=1 + fi + done +} + +get_clone_path(){ + # get paremater of clone path + while (( "$#" )); do + case $1 in + -b|--branch|--reference|--reference-if-able|-c|--config|--origin|-u|--upload-pack|-j|--jobs|--depth|--dissociate) + shift 2 + ;; + clone|-l|--local|--no-hardlinks|-s|--shared|--dissociate|-q|--quiet|-v|--verbose|--progress|--server-option=*|--bare|--sparse|--filter=*|--template=*|--mirror|--reference|--shallow-*|--no-tags|--recurse-submodules*|--remote-submodules|--no-remote-submodules|--separate-git-dir*) + shift 1 + ;; + *) + if [[ $URL == "" ]];then + URL=$1 + else + clone_PATH=$1 + fi + shift 1 + ;; + esac + done + + # if not specific clone path, get default clone path + [ -z $clone_PATH ] && clone_PATH=`echo $URL | rev | awk -F/ '{print$1}' | rev | awk -F. '{print$1}'` +} + +main(){ + parse_config "$@" + get_clone_path "$@" + + # execute git. + $REAL_COMMAND "$@" + result=$? + + # if sub command is not "clone", exit + if [[ $MODE_CLONE != 1 ]];then + exit $result + fi + + pushd $clone_PATH &> /dev/null + commit_latest=`$REAL_COMMAND log -n 1 | head -n 1| awk '{print$2}'` + [ -f $version_file ] && commit=`grep $URL $version_file | awk -F, '{print$2}'` + + # control version or record version file + if [[ $ENABLE_VERSION_CONTROL_GIT == "y" ]];then + # control version + [ ! -z $commit ] && $REAL_COMMAND reset --hard $commit &> /dev/null + else + # record version file + echo "$URL==$commit_latest" >> $new_version_file + sort $new_version_file -o $new_version_file -u &> /dev/null + fi + popd &> /dev/null + + exit $result +} + +main "$@" From 61bc9378c94b341a0c1ab39a2d84f5510baa3a6d Mon Sep 17 00:00:00 2001 From: shilongliu Date: Wed, 20 Jan 2021 03:05:13 +0000 Subject: [PATCH 2/4] fix --- src/sonic-build-hooks/hooks/git | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/sonic-build-hooks/hooks/git b/src/sonic-build-hooks/hooks/git index f05f5c75714e..b818cbbb16c7 100755 --- a/src/sonic-build-hooks/hooks/git +++ b/src/sonic-build-hooks/hooks/git @@ -44,7 +44,6 @@ get_clone_path(){ main(){ parse_config "$@" - get_clone_path "$@" # execute git. $REAL_COMMAND "$@" @@ -55,6 +54,7 @@ main(){ exit $result fi + get_clone_path "$@" pushd $clone_PATH &> /dev/null commit_latest=`$REAL_COMMAND log -n 1 | head -n 1| awk '{print$2}'` [ -f $version_file ] && commit=`grep $URL $version_file | awk -F, '{print$2}'` From bac9309b950bc1cd6dbf60ac6f084e29b343d01b Mon Sep 17 00:00:00 2001 From: shilongliu Date: Mon, 25 Jan 2021 07:03:16 +0000 Subject: [PATCH 3/4] bug-fix Signed-off-by: shilongliu --- src/sonic-build-hooks/hooks/git | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/sonic-build-hooks/hooks/git b/src/sonic-build-hooks/hooks/git index b818cbbb16c7..644a01d5fe1e 100755 --- a/src/sonic-build-hooks/hooks/git +++ b/src/sonic-build-hooks/hooks/git @@ -2,7 +2,7 @@ parse_config(){ . /usr/local/share/buildinfo/scripts/buildinfo_base.sh - [ -z $REAL_COMMAND ] && REAL_COMMAND=$(get_command git) + REAL_COMMAND=$(get_command git) version_file=$VERSION_PATH/versions-git new_version_file=$BUILD_VERSION_PATH/versions-git From 8756324dc18d872c9b9fa400ba1e47aae64c6baf Mon Sep 17 00:00:00 2001 From: shilongliu Date: Thu, 28 Jan 2021 03:11:28 +0000 Subject: [PATCH 4/4] bug-fix Signed-off-by: shilongliu --- Makefile.work | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Makefile.work b/Makefile.work index 0d7f62af3917..bc92750acd9e 100644 --- a/Makefile.work +++ b/Makefile.work @@ -114,7 +114,7 @@ $(shell CONFIGURED_ARCH=$(CONFIGURED_ARCH) j2 $(SLAVE_DIR)/Dockerfile.user.j2 > $(shell BUILD_SLAVE=y scripts/prepare_docker_buildinfo.sh $(SLAVE_BASE_IMAGE) $(SLAVE_DIR)/Dockerfile $(CONFIGURED_ARCH) "" $(BLDENV)) # Add the versions in the tag, if the version change, need to rebuild the slave -SLAVE_BASE_TAG = $(shell cat $(SLAVE_DIR)/Dockerfile $(SLAVE_DIR)/buildinfo/versions/versions-* | sha1sum | awk '{print substr($$1,0,11);}') +SLAVE_BASE_TAG = $(shell cat $(SLAVE_DIR)/Dockerfile $(SLAVE_DIR)/buildinfo/versions/versions-* src/sonic-build-hooks/hooks/* | sha1sum | awk '{print substr($$1,0,11);}') SLAVE_TAG = $(shell cat $(SLAVE_DIR)/Dockerfile.user $(SLAVE_DIR)/Dockerfile $(SLAVE_DIR)/buildinfo/versions/versions-* | sha1sum | awk '{print substr($$1,0,11);}') OVERLAY_MODULE_CHECK := \