Skip to content

Commit

Permalink
feat: add chroot-ln helper
Browse files Browse the repository at this point in the history
  • Loading branch information
autumnjolitz committed Oct 16, 2024
1 parent 05331f3 commit 24ff608
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 0 deletions.
1 change: 1 addition & 0 deletions Dockerfile.alpine
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ ENV BUILD_ROOT=$BUILD_ROOT \

ADD --chmod=0755 chroot-apk.sh /usr/local/bin/chroot-apk
ADD --chmod=0755 chroot-pip.sh /usr/local/bin/chroot-pip
ADD --chmod=0755 chroot-ln.sh /usr/local/bin/chroot-ln
ADD --chmod=0755 remove-py-if-pyc-exists.sh /usr/local/bin/remove-py-if-pyc-exists
RUN set -eu ; \
python -m pip install -U pip setuptools ; \
Expand Down
35 changes: 35 additions & 0 deletions chroot-ln.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
#!/usr/bin/env sh

if [ "x$CACHE_ROOT" = 'x' ] || [ "x$BUILD_ROOT" = 'x' ]; then
>&2 echo "CACHE_ROOT (${CACHE_ROOT:-not-set}) and/or BUILD_ROOT (${BUILD_ROOT:-not-set}) is not set!"
exit 1
fi

set -e
set -o pipefail

setup () {
>&2 echo "Grafting $CACHE_ROOT into $BUILD_ROOT..."
tar -C "$CACHE_ROOT" -cpf - . | tar -C "$BUILD_ROOT" -xpf -
return $?
}

fini () {
>&2 echo "Removing APK data from $BUILD_ROOT, storing in $CACHE_ROOT"
tar -C "$BUILD_ROOT" -cpf - etc/apk bin/ln bin/busybox var/cache/apk usr/share/apk | tar -C "$CACHE_ROOT" -xpf -
$_chroot /bin/ln -sf /usr/bin/dash /bin/sh.bak
rm -rf $BUILD_ROOT/bin/ln $BUILD_ROOT/bin/busybox $BUILD_ROOT/etc/apk $BUILD_ROOT/var/cache/apk $BUILD_ROOT/usr/share/apk
if $_chroot /usr/bin/dash -c '[ ! -x /bin/sh ]'; then
>&2 echo '/bin/sh in chroot failed the vibe check, replacing with a symlink to /usr/bin/dash!'
mv $BUILD_ROOT/bin/sh.bak $BUILD_ROOT/bin/sh
else
>&2 echo '/bin/sh passed the vibe check'
rm $BUILD_ROOT/bin/sh.bak
fi
return $?
}

trap fini EXIT
setup
set -x
ln $@

0 comments on commit 24ff608

Please sign in to comment.