Skip to content

Commit 2fa4f7e

Browse files
liushilongbuaaderan1980
authored andcommitted
Version control git (sonic-net#6562)
* support reproduceable build for git clone Signed-off-by: shilongliu <[email protected]> * fix * bug-fix Signed-off-by: shilongliu <[email protected]> * bug-fix Signed-off-by: shilongliu <[email protected]> Co-authored-by: shilongliu <[email protected]>
1 parent fefd2b4 commit 2fa4f7e

File tree

2 files changed

+77
-1
lines changed

2 files changed

+77
-1
lines changed

Makefile.work

+1-1
Original file line numberDiff line numberDiff line change
@@ -114,7 +114,7 @@ $(shell CONFIGURED_ARCH=$(CONFIGURED_ARCH) j2 $(SLAVE_DIR)/Dockerfile.user.j2 >
114114
$(shell BUILD_SLAVE=y scripts/prepare_docker_buildinfo.sh $(SLAVE_BASE_IMAGE) $(SLAVE_DIR)/Dockerfile $(CONFIGURED_ARCH) "" $(BLDENV))
115115

116116
# Add the versions in the tag, if the version change, need to rebuild the slave
117-
SLAVE_BASE_TAG = $(shell cat $(SLAVE_DIR)/Dockerfile $(SLAVE_DIR)/buildinfo/versions/versions-* | sha1sum | awk '{print substr($$1,0,11);}')
117+
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);}')
118118
SLAVE_TAG = $(shell cat $(SLAVE_DIR)/Dockerfile.user $(SLAVE_DIR)/Dockerfile $(SLAVE_DIR)/buildinfo/versions/versions-* | sha1sum | awk '{print substr($$1,0,11);}')
119119

120120
OVERLAY_MODULE_CHECK := \

src/sonic-build-hooks/hooks/git

+76
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,76 @@
1+
#!/bin/bash
2+
3+
parse_config(){
4+
. /usr/local/share/buildinfo/scripts/buildinfo_base.sh
5+
REAL_COMMAND=$(get_command git)
6+
7+
version_file=$VERSION_PATH/versions-git
8+
new_version_file=$BUILD_VERSION_PATH/versions-git
9+
10+
MODE_CLONE=0
11+
# parse input parameters
12+
for i in "$@"
13+
do
14+
if [[ $i == "clone" ]];then
15+
MODE_CLONE=1
16+
fi
17+
done
18+
}
19+
20+
get_clone_path(){
21+
# get paremater of clone path
22+
while (( "$#" )); do
23+
case $1 in
24+
-b|--branch|--reference|--reference-if-able|-c|--config|--origin|-u|--upload-pack|-j|--jobs|--depth|--dissociate)
25+
shift 2
26+
;;
27+
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*)
28+
shift 1
29+
;;
30+
*)
31+
if [[ $URL == "" ]];then
32+
URL=$1
33+
else
34+
clone_PATH=$1
35+
fi
36+
shift 1
37+
;;
38+
esac
39+
done
40+
41+
# if not specific clone path, get default clone path
42+
[ -z $clone_PATH ] && clone_PATH=`echo $URL | rev | awk -F/ '{print$1}' | rev | awk -F. '{print$1}'`
43+
}
44+
45+
main(){
46+
parse_config "$@"
47+
48+
# execute git.
49+
$REAL_COMMAND "$@"
50+
result=$?
51+
52+
# if sub command is not "clone", exit
53+
if [[ $MODE_CLONE != 1 ]];then
54+
exit $result
55+
fi
56+
57+
get_clone_path "$@"
58+
pushd $clone_PATH &> /dev/null
59+
commit_latest=`$REAL_COMMAND log -n 1 | head -n 1| awk '{print$2}'`
60+
[ -f $version_file ] && commit=`grep $URL $version_file | awk -F, '{print$2}'`
61+
62+
# control version or record version file
63+
if [[ $ENABLE_VERSION_CONTROL_GIT == "y" ]];then
64+
# control version
65+
[ ! -z $commit ] && $REAL_COMMAND reset --hard $commit &> /dev/null
66+
else
67+
# record version file
68+
echo "$URL==$commit_latest" >> $new_version_file
69+
sort $new_version_file -o $new_version_file -u &> /dev/null
70+
fi
71+
popd &> /dev/null
72+
73+
exit $result
74+
}
75+
76+
main "$@"

0 commit comments

Comments
 (0)