Skip to content

Commit

Permalink
feature: add helper to install apk packages in the buildroot with
Browse files Browse the repository at this point in the history
  • Loading branch information
autumnjolitz committed Oct 7, 2024
1 parent 5ac7aaf commit 35df05f
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 2 deletions.
4 changes: 2 additions & 2 deletions Dockerfile.alpine
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ ARG PYTHON_VERSION=3.12
ARG SOURCE_IMAGE=docker.io/python:${PYTHON_VERSION}-alpine${ALPINE_VERSION}
ARG BASE_IMAGE_DIGEST

FROM --platform=$BUILDPLATFORM $SOURCE_IMAGE@${BASE_IMAGE_DIGEST} AS buildroot
FROM --platform=$BUILDPLATFORM ${SOURCE_IMAGE}@${BASE_IMAGE_DIGEST} AS buildroot

Check warning on line 8 in Dockerfile.alpine

View workflow job for this annotation

GitHub Actions / docker (ghcr.io, 3.12, 3.20, ubuntu-latest)

Default value for global ARG results in an empty or invalid base image name

InvalidDefaultArgInFrom: Default value for ARG ${SOURCE_IMAGE}@${BASE_IMAGE_DIGEST} results in empty or invalid base image name More info: https://docs.docker.com/go/dockerfile/rule/invalid-default-arg-in-from/

Check warning on line 8 in Dockerfile.alpine

View workflow job for this annotation

GitHub Actions / docker (ghcr.io, 3.12, 3.20, ubuntu-latest)

Default value for global ARG results in an empty or invalid base image name

InvalidDefaultArgInFrom: Default value for ARG ${SOURCE_IMAGE}@${BASE_IMAGE_DIGEST} results in empty or invalid base image name More info: https://docs.docker.com/go/dockerfile/rule/invalid-default-arg-in-from/

Check warning on line 8 in Dockerfile.alpine

View workflow job for this annotation

GitHub Actions / docker (ghcr.io, 3.12, 3.20, ubuntu-latest)

Default value for global ARG results in an empty or invalid base image name

InvalidDefaultArgInFrom: Default value for ARG ${SOURCE_IMAGE}@${BASE_IMAGE_DIGEST} results in empty or invalid base image name More info: https://docs.docker.com/go/dockerfile/rule/invalid-default-arg-in-from/

Check warning on line 8 in Dockerfile.alpine

View workflow job for this annotation

GitHub Actions / docker (ghcr.io, 3.12, 3.20, ubuntu-latest)

Default value for global ARG results in an empty or invalid base image name

InvalidDefaultArgInFrom: Default value for ARG ${SOURCE_IMAGE}@${BASE_IMAGE_DIGEST} results in empty or invalid base image name More info: https://docs.docker.com/go/dockerfile/rule/invalid-default-arg-in-from/

Check warning on line 8 in Dockerfile.alpine

View workflow job for this annotation

GitHub Actions / docker (ghcr.io, 3.11, 3.20, ubuntu-latest)

Default value for global ARG results in an empty or invalid base image name

InvalidDefaultArgInFrom: Default value for ARG ${SOURCE_IMAGE}@${BASE_IMAGE_DIGEST} results in empty or invalid base image name More info: https://docs.docker.com/go/dockerfile/rule/invalid-default-arg-in-from/

Check warning on line 8 in Dockerfile.alpine

View workflow job for this annotation

GitHub Actions / docker (ghcr.io, 3.11, 3.20, ubuntu-latest)

Default value for global ARG results in an empty or invalid base image name

InvalidDefaultArgInFrom: Default value for ARG ${SOURCE_IMAGE}@${BASE_IMAGE_DIGEST} results in empty or invalid base image name More info: https://docs.docker.com/go/dockerfile/rule/invalid-default-arg-in-from/

Check warning on line 8 in Dockerfile.alpine

View workflow job for this annotation

GitHub Actions / docker (ghcr.io, 3.11, 3.20, ubuntu-latest)

Default value for global ARG results in an empty or invalid base image name

InvalidDefaultArgInFrom: Default value for ARG ${SOURCE_IMAGE}@${BASE_IMAGE_DIGEST} results in empty or invalid base image name More info: https://docs.docker.com/go/dockerfile/rule/invalid-default-arg-in-from/

Check warning on line 8 in Dockerfile.alpine

View workflow job for this annotation

GitHub Actions / docker (ghcr.io, 3.11, 3.20, ubuntu-latest)

Default value for global ARG results in an empty or invalid base image name

InvalidDefaultArgInFrom: Default value for ARG ${SOURCE_IMAGE}@${BASE_IMAGE_DIGEST} results in empty or invalid base image name More info: https://docs.docker.com/go/dockerfile/rule/invalid-default-arg-in-from/

Check warning on line 8 in Dockerfile.alpine

View workflow job for this annotation

GitHub Actions / docker (ghcr.io, 3.10, 3.20, ubuntu-latest)

Default value for global ARG results in an empty or invalid base image name

InvalidDefaultArgInFrom: Default value for ARG ${SOURCE_IMAGE}@${BASE_IMAGE_DIGEST} results in empty or invalid base image name More info: https://docs.docker.com/go/dockerfile/rule/invalid-default-arg-in-from/

Check warning on line 8 in Dockerfile.alpine

View workflow job for this annotation

GitHub Actions / docker (ghcr.io, 3.10, 3.20, ubuntu-latest)

Default value for global ARG results in an empty or invalid base image name

InvalidDefaultArgInFrom: Default value for ARG ${SOURCE_IMAGE}@${BASE_IMAGE_DIGEST} results in empty or invalid base image name More info: https://docs.docker.com/go/dockerfile/rule/invalid-default-arg-in-from/

Check warning on line 8 in Dockerfile.alpine

View workflow job for this annotation

GitHub Actions / docker (ghcr.io, 3.10, 3.20, ubuntu-latest)

Default value for global ARG results in an empty or invalid base image name

InvalidDefaultArgInFrom: Default value for ARG ${SOURCE_IMAGE}@${BASE_IMAGE_DIGEST} results in empty or invalid base image name More info: https://docs.docker.com/go/dockerfile/rule/invalid-default-arg-in-from/

Check warning on line 8 in Dockerfile.alpine

View workflow job for this annotation

GitHub Actions / docker (ghcr.io, 3.10, 3.20, ubuntu-latest)

Default value for global ARG results in an empty or invalid base image name

InvalidDefaultArgInFrom: Default value for ARG ${SOURCE_IMAGE}@${BASE_IMAGE_DIGEST} results in empty or invalid base image name More info: https://docs.docker.com/go/dockerfile/rule/invalid-default-arg-in-from/

Check warning on line 8 in Dockerfile.alpine

View workflow job for this annotation

GitHub Actions / docker (ghcr.io, 3.9, 3.20, ubuntu-latest)

Default value for global ARG results in an empty or invalid base image name

InvalidDefaultArgInFrom: Default value for ARG ${SOURCE_IMAGE}@${BASE_IMAGE_DIGEST} results in empty or invalid base image name More info: https://docs.docker.com/go/dockerfile/rule/invalid-default-arg-in-from/

Check warning on line 8 in Dockerfile.alpine

View workflow job for this annotation

GitHub Actions / docker (ghcr.io, 3.9, 3.20, ubuntu-latest)

Default value for global ARG results in an empty or invalid base image name

InvalidDefaultArgInFrom: Default value for ARG ${SOURCE_IMAGE}@${BASE_IMAGE_DIGEST} results in empty or invalid base image name More info: https://docs.docker.com/go/dockerfile/rule/invalid-default-arg-in-from/

Check warning on line 8 in Dockerfile.alpine

View workflow job for this annotation

GitHub Actions / docker (ghcr.io, 3.9, 3.20, ubuntu-latest)

Default value for global ARG results in an empty or invalid base image name

InvalidDefaultArgInFrom: Default value for ARG ${SOURCE_IMAGE}@${BASE_IMAGE_DIGEST} results in empty or invalid base image name More info: https://docs.docker.com/go/dockerfile/rule/invalid-default-arg-in-from/

Check warning on line 8 in Dockerfile.alpine

View workflow job for this annotation

GitHub Actions / docker (ghcr.io, 3.9, 3.20, ubuntu-latest)

Default value for global ARG results in an empty or invalid base image name

InvalidDefaultArgInFrom: Default value for ARG ${SOURCE_IMAGE}@${BASE_IMAGE_DIGEST} results in empty or invalid base image name More info: https://docs.docker.com/go/dockerfile/rule/invalid-default-arg-in-from/

Check warning on line 8 in Dockerfile.alpine

View workflow job for this annotation

GitHub Actions / docker (ghcr.io, 3.8, 3.20, ubuntu-latest)

Default value for global ARG results in an empty or invalid base image name

InvalidDefaultArgInFrom: Default value for ARG ${SOURCE_IMAGE}@${BASE_IMAGE_DIGEST} results in empty or invalid base image name More info: https://docs.docker.com/go/dockerfile/rule/invalid-default-arg-in-from/

Check warning on line 8 in Dockerfile.alpine

View workflow job for this annotation

GitHub Actions / docker (ghcr.io, 3.8, 3.20, ubuntu-latest)

Default value for global ARG results in an empty or invalid base image name

InvalidDefaultArgInFrom: Default value for ARG ${SOURCE_IMAGE}@${BASE_IMAGE_DIGEST} results in empty or invalid base image name More info: https://docs.docker.com/go/dockerfile/rule/invalid-default-arg-in-from/

Check warning on line 8 in Dockerfile.alpine

View workflow job for this annotation

GitHub Actions / docker (ghcr.io, 3.8, 3.20, ubuntu-latest)

Default value for global ARG results in an empty or invalid base image name

InvalidDefaultArgInFrom: Default value for ARG ${SOURCE_IMAGE}@${BASE_IMAGE_DIGEST} results in empty or invalid base image name More info: https://docs.docker.com/go/dockerfile/rule/invalid-default-arg-in-from/

Check warning on line 8 in Dockerfile.alpine

View workflow job for this annotation

GitHub Actions / docker (ghcr.io, 3.8, 3.20, ubuntu-latest)

Default value for global ARG results in an empty or invalid base image name

InvalidDefaultArgInFrom: Default value for ARG ${SOURCE_IMAGE}@${BASE_IMAGE_DIGEST} results in empty or invalid base image name More info: https://docs.docker.com/go/dockerfile/rule/invalid-default-arg-in-from/

Check warning on line 8 in Dockerfile.alpine

View workflow job for this annotation

GitHub Actions / docker (docker.io, 3.12, 3.20, ubuntu-latest)

Default value for global ARG results in an empty or invalid base image name

InvalidDefaultArgInFrom: Default value for ARG ${SOURCE_IMAGE}@${BASE_IMAGE_DIGEST} results in empty or invalid base image name More info: https://docs.docker.com/go/dockerfile/rule/invalid-default-arg-in-from/

Check warning on line 8 in Dockerfile.alpine

View workflow job for this annotation

GitHub Actions / docker (docker.io, 3.12, 3.20, ubuntu-latest)

Default value for global ARG results in an empty or invalid base image name

InvalidDefaultArgInFrom: Default value for ARG ${SOURCE_IMAGE}@${BASE_IMAGE_DIGEST} results in empty or invalid base image name More info: https://docs.docker.com/go/dockerfile/rule/invalid-default-arg-in-from/

Check warning on line 8 in Dockerfile.alpine

View workflow job for this annotation

GitHub Actions / docker (docker.io, 3.12, 3.20, ubuntu-latest)

Default value for global ARG results in an empty or invalid base image name

InvalidDefaultArgInFrom: Default value for ARG ${SOURCE_IMAGE}@${BASE_IMAGE_DIGEST} results in empty or invalid base image name More info: https://docs.docker.com/go/dockerfile/rule/invalid-default-arg-in-from/

Check warning on line 8 in Dockerfile.alpine

View workflow job for this annotation

GitHub Actions / docker (docker.io, 3.12, 3.20, ubuntu-latest)

Default value for global ARG results in an empty or invalid base image name

InvalidDefaultArgInFrom: Default value for ARG ${SOURCE_IMAGE}@${BASE_IMAGE_DIGEST} results in empty or invalid base image name More info: https://docs.docker.com/go/dockerfile/rule/invalid-default-arg-in-from/

Check warning on line 8 in Dockerfile.alpine

View workflow job for this annotation

GitHub Actions / docker (docker.io, 3.11, 3.20, ubuntu-latest)

Default value for global ARG results in an empty or invalid base image name

InvalidDefaultArgInFrom: Default value for ARG ${SOURCE_IMAGE}@${BASE_IMAGE_DIGEST} results in empty or invalid base image name More info: https://docs.docker.com/go/dockerfile/rule/invalid-default-arg-in-from/

Check warning on line 8 in Dockerfile.alpine

View workflow job for this annotation

GitHub Actions / docker (docker.io, 3.11, 3.20, ubuntu-latest)

Default value for global ARG results in an empty or invalid base image name

InvalidDefaultArgInFrom: Default value for ARG ${SOURCE_IMAGE}@${BASE_IMAGE_DIGEST} results in empty or invalid base image name More info: https://docs.docker.com/go/dockerfile/rule/invalid-default-arg-in-from/

Check warning on line 8 in Dockerfile.alpine

View workflow job for this annotation

GitHub Actions / docker (docker.io, 3.11, 3.20, ubuntu-latest)

Default value for global ARG results in an empty or invalid base image name

InvalidDefaultArgInFrom: Default value for ARG ${SOURCE_IMAGE}@${BASE_IMAGE_DIGEST} results in empty or invalid base image name More info: https://docs.docker.com/go/dockerfile/rule/invalid-default-arg-in-from/

Check warning on line 8 in Dockerfile.alpine

View workflow job for this annotation

GitHub Actions / docker (docker.io, 3.11, 3.20, ubuntu-latest)

Default value for global ARG results in an empty or invalid base image name

InvalidDefaultArgInFrom: Default value for ARG ${SOURCE_IMAGE}@${BASE_IMAGE_DIGEST} results in empty or invalid base image name More info: https://docs.docker.com/go/dockerfile/rule/invalid-default-arg-in-from/

Check warning on line 8 in Dockerfile.alpine

View workflow job for this annotation

GitHub Actions / docker (docker.io, 3.10, 3.20, ubuntu-latest)

Default value for global ARG results in an empty or invalid base image name

InvalidDefaultArgInFrom: Default value for ARG ${SOURCE_IMAGE}@${BASE_IMAGE_DIGEST} results in empty or invalid base image name More info: https://docs.docker.com/go/dockerfile/rule/invalid-default-arg-in-from/

Check warning on line 8 in Dockerfile.alpine

View workflow job for this annotation

GitHub Actions / docker (docker.io, 3.10, 3.20, ubuntu-latest)

Default value for global ARG results in an empty or invalid base image name

InvalidDefaultArgInFrom: Default value for ARG ${SOURCE_IMAGE}@${BASE_IMAGE_DIGEST} results in empty or invalid base image name More info: https://docs.docker.com/go/dockerfile/rule/invalid-default-arg-in-from/

Check warning on line 8 in Dockerfile.alpine

View workflow job for this annotation

GitHub Actions / docker (docker.io, 3.10, 3.20, ubuntu-latest)

Default value for global ARG results in an empty or invalid base image name

InvalidDefaultArgInFrom: Default value for ARG ${SOURCE_IMAGE}@${BASE_IMAGE_DIGEST} results in empty or invalid base image name More info: https://docs.docker.com/go/dockerfile/rule/invalid-default-arg-in-from/

Check warning on line 8 in Dockerfile.alpine

View workflow job for this annotation

GitHub Actions / docker (docker.io, 3.10, 3.20, ubuntu-latest)

Default value for global ARG results in an empty or invalid base image name

InvalidDefaultArgInFrom: Default value for ARG ${SOURCE_IMAGE}@${BASE_IMAGE_DIGEST} results in empty or invalid base image name More info: https://docs.docker.com/go/dockerfile/rule/invalid-default-arg-in-from/

Check warning on line 8 in Dockerfile.alpine

View workflow job for this annotation

GitHub Actions / docker (docker.io, 3.9, 3.20, ubuntu-latest)

Default value for global ARG results in an empty or invalid base image name

InvalidDefaultArgInFrom: Default value for ARG ${SOURCE_IMAGE}@${BASE_IMAGE_DIGEST} results in empty or invalid base image name More info: https://docs.docker.com/go/dockerfile/rule/invalid-default-arg-in-from/

Check warning on line 8 in Dockerfile.alpine

View workflow job for this annotation

GitHub Actions / docker (docker.io, 3.9, 3.20, ubuntu-latest)

Default value for global ARG results in an empty or invalid base image name

InvalidDefaultArgInFrom: Default value for ARG ${SOURCE_IMAGE}@${BASE_IMAGE_DIGEST} results in empty or invalid base image name More info: https://docs.docker.com/go/dockerfile/rule/invalid-default-arg-in-from/

Check warning on line 8 in Dockerfile.alpine

View workflow job for this annotation

GitHub Actions / docker (docker.io, 3.9, 3.20, ubuntu-latest)

Default value for global ARG results in an empty or invalid base image name

InvalidDefaultArgInFrom: Default value for ARG ${SOURCE_IMAGE}@${BASE_IMAGE_DIGEST} results in empty or invalid base image name More info: https://docs.docker.com/go/dockerfile/rule/invalid-default-arg-in-from/

Check warning on line 8 in Dockerfile.alpine

View workflow job for this annotation

GitHub Actions / docker (docker.io, 3.9, 3.20, ubuntu-latest)

Default value for global ARG results in an empty or invalid base image name

InvalidDefaultArgInFrom: Default value for ARG ${SOURCE_IMAGE}@${BASE_IMAGE_DIGEST} results in empty or invalid base image name More info: https://docs.docker.com/go/dockerfile/rule/invalid-default-arg-in-from/

Check warning on line 8 in Dockerfile.alpine

View workflow job for this annotation

GitHub Actions / docker (docker.io, 3.8, 3.20, ubuntu-latest)

Default value for global ARG results in an empty or invalid base image name

InvalidDefaultArgInFrom: Default value for ARG ${SOURCE_IMAGE}@${BASE_IMAGE_DIGEST} results in empty or invalid base image name More info: https://docs.docker.com/go/dockerfile/rule/invalid-default-arg-in-from/

Check warning on line 8 in Dockerfile.alpine

View workflow job for this annotation

GitHub Actions / docker (docker.io, 3.8, 3.20, ubuntu-latest)

Default value for global ARG results in an empty or invalid base image name

InvalidDefaultArgInFrom: Default value for ARG ${SOURCE_IMAGE}@${BASE_IMAGE_DIGEST} results in empty or invalid base image name More info: https://docs.docker.com/go/dockerfile/rule/invalid-default-arg-in-from/

Check warning on line 8 in Dockerfile.alpine

View workflow job for this annotation

GitHub Actions / docker (docker.io, 3.8, 3.20, ubuntu-latest)

Default value for global ARG results in an empty or invalid base image name

InvalidDefaultArgInFrom: Default value for ARG ${SOURCE_IMAGE}@${BASE_IMAGE_DIGEST} results in empty or invalid base image name More info: https://docs.docker.com/go/dockerfile/rule/invalid-default-arg-in-from/

Check warning on line 8 in Dockerfile.alpine

View workflow job for this annotation

GitHub Actions / docker (docker.io, 3.8, 3.20, ubuntu-latest)

Default value for global ARG results in an empty or invalid base image name

InvalidDefaultArgInFrom: Default value for ARG ${SOURCE_IMAGE}@${BASE_IMAGE_DIGEST} results in empty or invalid base image name More info: https://docs.docker.com/go/dockerfile/rule/invalid-default-arg-in-from/
ARG PYTHON_VERSION=3.12

ARG BUILD_ROOT='/dest'
Expand All @@ -20,6 +20,7 @@ ENV BUILD_ROOT=$BUILD_ROOT \
_ln="chroot $BUILD_ROOT ln" \
_chroot="chroot $BUILD_ROOT"

ADD --chmod=0755 chroot-apk.sh /usr/local/bin/chroot-apk
RUN set -eu ; \
python -m pip install -U pip setuptools ; \
# Add to buildroot:
Expand Down Expand Up @@ -88,7 +89,6 @@ RUN set -eu ; \
# regenerate the ca-certs!
chroot $BUILD_ROOT update-ca-certificates


FROM scratch AS distroless-python
ARG ALPINE_VERSION=3.20
ARG PYTHON_VERSION=3.12
Expand Down
4 changes: 4 additions & 0 deletions README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,10 @@ Given the following ``Dockerfile``, we will add ``httpie`` to the image and refe
ENTRYPOINT ["http"]
As an additional helper, the ``chroot-apk`` command in the buildroot environment can
be used to install apk packages.

Build and test the image!

.. code:: bash
Expand Down
27 changes: 27 additions & 0 deletions chroot-apk.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
#!/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 -
rm -rf $BUILD_ROOT/bin/ln $BUILD_ROOT/bin/busybox $BUILD_ROOT/etc/apk $BUILD_ROOT/var/cache/apk $BUILD_ROOT/usr/share/apk
return $?
}

trap fini EXIT
setup
set -x
apk --root "$BUILD_ROOT" $@

0 comments on commit 35df05f

Please sign in to comment.