Create a GitHub token with:
reporead:orgdelete:packageswrite:packages
Store that token in the CR_PAT environment variable in your terminal session: export CR_PAT=YOUR_TOKEN_FROM_GITHUB
Run the following commands (Note: there are references to the image name in test-image/Dockerfile-features that aren't yet parameterised)
export IMAGE_BASE_NAME=test-docker-cache
export IMAGE_NAME=ghcr.io/stuartleeks/$IMAGE_BASE_NAME
# Set up registry auth
# Assumes that you have run the following in your terminal session: export CR_PAT=YOUR_TOKEN_FROM_GITHUB
echo $CR_PAT | docker login ghcr.io -u USERNAME --password-stdin
# Set up gh cli auth
echo $CR_PAT | gh auth login --with-tokenTo run a test, run make <name>, e.g. make 5d-build-BUILDKIT_INLINE_CACHE-multistage_image-retag.
docker builddoesn't work with just--cache=from(same forbuildx)docker builddoes work if the build/pushed image was built with--build-arg BUILDKIT_INLINE_CACHE=1(same forbuildx) => Need to be able to set thisdocker build[x]seem to fail if buildingimage1thenimage2based off it and pushingimage2docker build[x]works with multistage build (all layers are used in cache)
This section walks through the various tests. Each section corresponds to the scripts with the matching number, i.e. notes-3 discusses the scripts 3*.sh.
Single build step
docker build specifying --cache-from - not successful
docker buildx specifying --cache-from - not successful
2a added --build-arg BUILDKIT_INLINE_CACHE=1 which was successful.
3 added --build-arg BUILDKIT_INLINE_CACHE=1 to the approach from 1, and was successful.
3a added a re-tagging step and was still successful
3b added a step to derive an image from the first step to mimic container-features and this was not successful
4 attempted the same as 3b, but with buildx - not successful
4a tried the mode=max option for specifying the cache output settings, but still not successful
5 explores the same two stages as 3b and 4, but as a multistage build (single Dockerfile) and this was successful
5a added in re-tagging and was still successful
5b was the same as 5a but without the mode=max option and was still successful
5c reverted to the --build-arg BUILDKIT_INLINE_CACHE=1 approach and was still successful
5d switched to docker build and was still successful
6 returns to 4, but pushes both the image and image-features images. This was successful.
6a is the same as 6 but with build rather than buildx. This was also successful.
https://docs.github.com/en/packages/working-with-a-github-packages-registry/working-with-the-container-registry#authenticating-to-the-container-registry https://docs.github.com/en/packages/learn-github-packages/configuring-a-packages-access-control-and-visibility https://docs.github.com/en/authentication/keeping-your-account-and-data-secure/creating-a-personal-access-token