This repository has been archived on 2025-03-20. You can view files and clone it, but cannot push or open issues or pull requests.
sonic-buildimage/src/sonic-build-hooks/scripts/collect_version_files
xumia c9806ec3c3
[Build][202211] Support Debian snapshot mirror to improve build stability (#13371) (#13382)
Why I did it
Cherry pick from #13097
[Build] Support Debian snapshot mirror to improve build stability

It is to enhance the reproducible build, supports the Debian snapshot mirror. It guarantees all the docker images using the same Debian mirror snapshot and fixes the temporary build failure which is caused by remote Debain mirror indexes changed during the build. It is also to fix the version conflict issue caused by no fixed versions of some of the Debian packages.

How I did it
Add a new feature to support the Debian snapshot mirror.

How to verify it
2023-02-10 09:33:54 -08:00

41 lines
1.8 KiB
Bash
Executable File

#!/bin/bash
. /usr/local/share/buildinfo/scripts/buildinfo_base.sh
TARGET_PATH=$1
[ -z "$TARGET_PATH" ] && TARGET_PATH=$POST_VERSION_PATH
ARCH=$(dpkg --print-architecture)
DIST=$(grep VERSION_CODENAME /etc/os-release | cut -d= -f2)
([ -z "$DIST" ] && grep -q jessie /etc/os-release) && DIST=jessie
mkdir -p $TARGET_PATH
chmod a+rw $TARGET_PATH
dpkg-query -W -f '${Package}==${Version}\n' >> "${TARGET_PATH}/versions-deb-${DIST}-${ARCH}"
([ -x "/usr/local/bin/pip2" ] || [ -x "/usr/bin/pip2" ]) && pip2 freeze >> "${TARGET_PATH}/versions-py2-${DIST}-${ARCH}"
([ -x "/usr/local/bin/pip3" ] || [ -x "/usr/bin/pip3" ]) && pip3 freeze >> "${TARGET_PATH}/versions-py3-${DIST}-${ARCH}"
## Add the the packages purged
[ -f $POST_VERSION_PATH/purge-versions-deb ] && cat $POST_VERSION_PATH/purge-versions-deb >> "${TARGET_PATH}/versions-deb-${DIST}-${ARCH}"
## Add mirror versions
while read -r line; do
mirror=$(echo "$line" | sed "s/.*\///" | sed "s/_InRelease.*//")
date=$(date --date="$(echo "$line" | cut -d: -f3-)" +%Y-%m-%dT%H:%M:%SZ)
echo "$mirror==$date" >> ${TARGET_PATH}/versions-mirror
done < <(grep Date: /var/lib/apt/lists/*_InRelease 2>/dev/null)
## Print the unique and sorted result
sort -u "${TARGET_PATH}/versions-deb-${DIST}-${ARCH}" -o "${TARGET_PATH}/versions-deb-${DIST}-${ARCH}"
if [ -e "${TARGET_PATH}/versions-py2-${DIST}-${ARCH}" ]; then
sort -u "${TARGET_PATH}/versions-py2-${DIST}-${ARCH}" -o "${TARGET_PATH}/versions-py2-${DIST}-${ARCH}"
fi
if [ -e "${TARGET_PATH}/versions-py3-${DIST}-${ARCH}" ]; then
sort -u "${TARGET_PATH}/versions-py3-${DIST}-${ARCH}" -o "${TARGET_PATH}/versions-py3-${DIST}-${ARCH}"
fi
if [ -e "${TARGET_PATH}/versions-mirror" ]; then
sort -u "${TARGET_PATH}/versions-mirror" -o "${TARGET_PATH}/versions-mirror"
fi
exit 0