[build] Fix reproducible build issues (#8548)

* [build] Fix reproducible build issues
This commit is contained in:
Shilong Liu 2021-08-26 18:21:18 +08:00 committed by GitHub
parent ed64eb94d9
commit c44dbf0fe0
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 12 additions and 7 deletions

View File

@ -46,9 +46,9 @@ parameters:
default: sonicdev default: sonicdev
variables: variables:
- ${{ if and(startsWith(variables['Build.SourceBranchName'], '202'), eq(length(variables['Build.SourceBranchName']), 6)) }}: - ${{ if eq(variables['Build.SourceBranchName'], '202012' }}:
- name: BUILD_OPTIONS - name: BUILD_OPTIONS
value: 'SONIC_VERSION_CONTROL_COMPONENTS=deb,py2,py3,web' value: 'SONIC_VERSION_CONTROL_COMPONENTS=deb,py2,py3,web,git,docker'
stages: stages:
- stage: Build - stage: Build

View File

@ -37,7 +37,7 @@ stages:
variables: variables:
CACHE_MODE: rcache CACHE_MODE: rcache
${{ if eq(variables['Build.SourceBranchName'], '202012') }}: ${{ if eq(variables['Build.SourceBranchName'], '202012') }}:
VERSION_CONTROL_OPTIONS: 'SONIC_VERSION_CONTROL_COMPONENTS=deb,py2,py3,web' VERSION_CONTROL_OPTIONS: 'SONIC_VERSION_CONTROL_COMPONENTS=deb,py2,py3,web,git,docker'
jobs: jobs:
- template: .azure-pipelines/azure-pipelines-build.yml - template: .azure-pipelines/azure-pipelines-build.yml
parameters: parameters:

View File

@ -21,7 +21,7 @@ tag=`echo $image_tag | cut -f2 -d:`
if [[ ",$SONIC_VERSION_CONTROL_COMPONENTS," == *,all,* ]] || [[ ",$SONIC_VERSION_CONTROL_COMPONENTS," == *,docker,* ]]; then if [[ ",$SONIC_VERSION_CONTROL_COMPONENTS," == *,all,* ]] || [[ ",$SONIC_VERSION_CONTROL_COMPONENTS," == *,docker,* ]]; then
# if docker image not in white list, exit # if docker image not in white list, exit
if [[ "$IMAGENAME" != sonic-slave-* ]] && [[ "$IMAGENAME" != docker-base* ]] && [[ "$IMAGENAME" != debian:* ]] && [[ "$IMAGENAME" != multiarch/debian-debootstrap:* ]];then if [[ "$image_tag" != */debian:* ]] && [[ "$image_tag" != multiarch/debian-debootstrap:* ]];then
exit 0 exit 0
fi fi
if [ -f $version_file ];then if [ -f $version_file ];then
@ -29,12 +29,15 @@ if [[ ",$SONIC_VERSION_CONTROL_COMPONENTS," == *,all,* ]] || [[ ",$SONIC_VERSION
fi fi
if [ -z $hash_value ];then if [ -z $hash_value ];then
hash_value=unknown hash_value=unknown
echo "$image_tag sha256 value is unknown" >> ${new_version_file}.log
exit 0
fi fi
oldimage=${image_tag//\//\\/} oldimage=${image_tag//\//\\/}
newimage="${oldimage}@$hash_value" newimage="${oldimage}@$hash_value"
echo "sed -i \"s/$oldimage/$newimage/\" $DOCKERFILE" >> ${new_version_file}.log
sed -i "s/$oldimage/$newimage/" $DOCKERFILE sed -i "s/$oldimage/$newimage/" $DOCKERFILE
else else
hash_value=`docker pull $image_tag | grep Digest | awk '{print$2}'` hash_value=`docker pull $image_tag 2> ${new_version_file}.log | grep Digest | awk '{print$2}'`
if [ -z hash_value ];then if [ -z hash_value ];then
hash_value=unknown hash_value=unknown
fi fi

View File

@ -39,7 +39,8 @@ get_clone_path(){
done done
# if not specific clone path, get default clone path # 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}'` # 1. trim tail slash sign. 2. trim all charactors before the last slash. 3.trim tail '.git'
[ -z $clone_PATH ] && clone_PATH=`echo $URL | sed 's/\/$//' | awk -F/ '{print$NF}' | awk -F. '{print$1}'`
} }
main(){ main(){
@ -62,7 +63,8 @@ main(){
# control version or record version file # control version or record version file
if [[ $ENABLE_VERSION_CONTROL_GIT == "y" ]];then if [[ $ENABLE_VERSION_CONTROL_GIT == "y" ]];then
# control version # control version
[ ! -z $commit ] && $REAL_COMMAND reset --hard $commit &> /dev/null [ -n $commit ] && echo "git reset --hard $commit" >> ${new_version_file}.log
[ -n $commit ] && $REAL_COMMAND reset --hard $commit &> ${new_version_file}.log
else else
# record version file # record version file
echo "$URL==$commit_latest" >> $new_version_file echo "$URL==$commit_latest" >> $new_version_file