Skip to content

Commit 7e525d9

Browse files
authored
[Build] Use apt-get to predictably support dependency ordered configuration of lazy packages (#12164)
Why I did it The current lazy installer relies on a filename sort for both unpack and configuration steps. When systemd services are configured [started] by multiple packages the order is by filename not by the declared package dependencies. This can cause the start order of services to differ between first-boot and subsequent boots. Declared systemd service dependencies further exacerbate the issue (e.g. blocking the first-boot script). The current installer leaves packages un-configured if the package dependency order does not match the filename order. This also fixes a trivial bug in [Build]: Support to use symbol links for lazy installation targets to reduce the image size #10923 where externally downloaded dependencies are duplicated across lazy package device directories. How I did it Changed the staging and first-boot scripts to use apt-get: dpkg -i /host/image-$SONIC_VERSION/platform/$platform/*.deb becomes apt-get -y install /host/image-$SONIC_VERSION/platform/$platform/*.deb when dependencies are detected during image staging. How to verify it Apt-get critical rules Add a Depends= to the control information of a package. Grep the syslog for rc.local between images and observe the configuration order of packages change.
1 parent f9578c5 commit 7e525d9

File tree

2 files changed

+22
-2
lines changed

2 files changed

+22
-2
lines changed

files/build_templates/sonic_debian_extension.j2

+8-1
Original file line numberDiff line numberDiff line change
@@ -646,12 +646,19 @@ sudo mkdir -p $FILESYSTEM_ROOT/$PLATFORM_DIR/common
646646
sudo cp {{ deb }} $FILESYSTEM_ROOT/$PLATFORM_DIR/common/
647647
sudo ln -sf "../common/{{ debfilename }}" "$FILESYSTEM_ROOT/$PLATFORM_DIR/{{dev}}/{{ debfilename }}"
648648
for f in $(find $FILESYSTEM_ROOT/var/cache/apt/archives -name "*.deb"); do
649-
sudo mv $f $FILESYSTEM_ROOT/$PLATFORM_DIR/{{dev}}/
649+
sudo mv $f $FILESYSTEM_ROOT/$PLATFORM_DIR/common/
650+
sudo ln -sf "../common/$(basename $f)" "$FILESYSTEM_ROOT/$PLATFORM_DIR/{{dev}}/$(basename $f)"
650651
done
651652

652653
sudo dpkg --root=$FILESYSTEM_ROOT -P {{ debname }}
653654

654655
{% endfor %}
656+
# create a trivial apt repo if any of the debs have dependencies, including between lazy debs
657+
if [ $(for f in $FILESYSTEM_ROOT/$PLATFORM_DIR/common/*.deb; do \
658+
sudo dpkg -I $f | grep "Depends:\|Pre-Depends:"; done | wc -l) -gt 0 ]; then
659+
(cd $FILESYSTEM_ROOT/$PLATFORM_DIR/common && sudo dpkg-scanpackages . | \
660+
sudo gzip | sudo tee Packages.gz > /dev/null)
661+
fi
655662
{% endif %}
656663

657664
# Remove sshd host keys, and will regenerate on first sshd start. This needs to be

files/image_config/platform/rc.local

+14-1
Original file line numberDiff line numberDiff line change
@@ -284,7 +284,20 @@ if [ -f $FIRST_BOOT_FILE ]; then
284284
fi
285285

286286
if [ -d /host/image-$SONIC_VERSION/platform/$platform ]; then
287-
dpkg -i /host/image-$SONIC_VERSION/platform/$platform/*.deb
287+
if [ -f /host/image-$SONIC_VERSION/platform/common/Packages.gz ]; then
288+
# Use only the trivial repo and apt to support lazy package dependencies
289+
mv /etc/apt/sources.list /etc/apt/sources.list.rc-local
290+
echo "deb [trusted=yes] file:///host/image-$SONIC_VERSION/platform/common /" > /etc/apt/sources.list.d/sonic_debian_extension.list
291+
LANG=C DEBIAN_FRONTEND=noninteractive apt-get update
292+
LANG=C DEBIAN_FRONTEND=noninteractive apt-get -y install /host/image-$SONIC_VERSION/platform/$platform/*.deb
293+
# Cleanup
294+
rm -f /etc/apt/sources.list.d/sonic_debian_extension.list
295+
rm -f /var/lib/apt/lists/_host_image-${SONIC_VERSION}_platform_common_Packages.lz4
296+
# This is first boot so there should be no package lists or indices to restore, just the sources
297+
mv /etc/apt/sources.list.rc-local /etc/apt/sources.list
298+
else
299+
dpkg -i /host/image-$SONIC_VERSION/platform/$platform/*.deb
300+
fi
288301
fi
289302

290303
sync

0 commit comments

Comments
 (0)