@@ -88,9 +88,14 @@ apt-get update
8888# Point apt at the empty target dpkg status so it thinks nothing is installed,
8989# which makes it download the full dependency tree and resolve conflicts properly.
9090essential=$(dpkg-query -Wf '${Package} ${Essential}\n' | awk '$2 == "yes" {print $1}')
91+ # Get names of local packages so we can exclude them from apt-get install
92+ local_pkgs=$(for f in /var/cache/apt/archives/*.deb; do dpkg-deb -f "$f" Package 2>/dev/null; done | sort -u)
9193local_deps=$(for f in /var/cache/apt/archives/*.deb; do dpkg-deb -f "$f" Depends 2>/dev/null; done | tr ',' '\n' | sed 's/([^)]*)//g; s/|.*//; s/ //g' | grep -v '^$' | sort -u)
94+ # Filter out deps that are satisfied by local packages (they aren't in apt repos)
95+ echo "$local_pkgs" > /tmp/local_pkg_names
96+ filtered_deps=$(echo "$local_deps" | grep -vxFf /tmp/local_pkg_names || true)
9297apt-get -o Dir::State::status=/tmp/rootfs/var/lib/dpkg/status \
93- --yes --download-only install $essential $local_deps
98+ --yes --download-only install $essential $filtered_deps
9499
95100# Extract all packages into the target rootfs
96101for f in /var/cache/apt/archives/*.deb; do
@@ -127,6 +132,19 @@ if [ ! -e /tmp/rootfs/usr/bin/sh ]; then
127132 fi
128133fi
129134
135+ # Remove usrmerge package - our merged-usr fixup above already handles this,
136+ # and usrmerge's postinst fails on overlayfs (which BuildKit uses).
137+ # Create a fake dpkg status entry so dpkg thinks it's installed.
138+ for f in /var/cache/apt/archives/usrmerge_*.deb /var/cache/apt/archives/usr-is-merged_*.deb; do
139+ if [ -f "$f" ]; then
140+ pkg=$(dpkg-deb -f "$f" Package)
141+ ver=$(dpkg-deb -f "$f" Version)
142+ arch=$(dpkg-deb -f "$f" Architecture)
143+ printf 'Package: %s\nStatus: install ok installed\nVersion: %s\nArchitecture: %s\nDescription: faked by dalec\n\n' "$pkg" "$ver" "$arch" >> /tmp/rootfs/var/lib/dpkg/status
144+ rm "$f"
145+ fi
146+ done
147+
130148cp /var/cache/apt/archives/*.deb /tmp/rootfs/var/cache/apt/archives/
131149
132150# Copy apt sources from worker into rootfs so the final container can install packages
0 commit comments