Bake Portage #3
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
name: Bake Portage | |
on: | |
#push: | |
# branches: | |
# - main | |
workflow_dispatch: | |
inputs: | |
portage_date: | |
description: The date (tag) of the latest portage image (e.g. `20241231`) | |
required: true | |
# Could be `latest` or a date like `20241231` | |
type: string | |
default: latest | |
workflow_call: | |
inputs: | |
portage_date: | |
description: The date (tag) of the latest portage image (e.g. `20241231`) | |
required: true | |
# Could be `latest` or a date like `20241231` | |
type: string | |
outputs: | |
portage_image: | |
description: Portage Image (e.g. `ghcr.io/berney/kubler-images/portage:20241231`) | |
value: ${{ jobs.portage.outputs.portage_image }} | |
# Jobs run in parallel | |
# Jobs are independent with separate file systems, IP addresses, etc. | |
jobs: | |
portage: | |
runs-on: ubuntu-latest | |
outputs: | |
portage_image: ${{ steps.portage_image.outputs.portage_image }} | |
env: | |
KUBLER_IMAGE: ghcr.io/${{ github.repository }} | |
PORTAGE_DATE: ${{ inputs.portage_date }} | |
steps: | |
- name: Set up QEMU | |
id: qemu | |
uses: docker/setup-qemu-action@v3 | |
with: | |
image: tonistiigi/binfmt:latest | |
platforms: all | |
- name: 🐋 Set up Docker Buildx | |
id: buildx | |
uses: docker/setup-buildx-action@v3 | |
with: | |
# This breaks kubler https://github.com/edannenberg/kubler/issues/215 | |
# Sets up `docker build` command as an alias to `docker buildx` (default `false`) | |
install: true | |
- name: 🐋 Docker Login | |
uses: docker/login-action@v3 | |
with: | |
registry: ghcr.io | |
username: ${{ github.repository_owner }} | |
password: ${{ secrets.GITHUB_TOKEN }} | |
- uses: oras-project/setup-oras@v1 | |
- run: | | |
oras version | |
- name: Check out repository code | |
uses: actions/checkout@v4 | |
- name: 🐋🍳 Docker Bake Kubler portage - set PORTAGE_IMAGE env vars | |
run: | | |
set -eux | |
TMP_PORTAGE_IMAGE=ghcr.io/"${GITHUB_REPOSITORY}"/tmp/portage:"${PORTAGE_DATE}" | |
PORTAGE_IMAGE=ghcr.io/"${GITHUB_REPOSITORY}"/portage:"${PORTAGE_DATE}" | |
echo "TMP_PORTAGE_IMAGE=$TMP_PORTAGE_IMAGE" >> $GITHUB_ENV | |
echo "PORTAGE_IMAGE=$PORTAGE_IMAGE" >> $GITHUB_ENV | |
- name: 🐋 Docker Pull Portage | |
id: portage-pull | |
continue-on-error: true | |
run: | | |
set -eu | |
docker pull "$PORTAGE_IMAGE" | |
# We always test, even if we pulled | |
# A pushed image should have been tested before being pushed. | |
# But re-testing for extra safety and in case tests have changed in between. | |
- name: 🐋🍳 Docker Bake Kubler portage - test pulled | |
id: portage-pull-test | |
if: ${{ steps.portage-pull.outcome == 'success' }} | |
continue-on-error: true | |
run: | | |
set -eux | |
docker run --rm "${PORTAGE_IMAGE}" grep TIMESTAMP /var/db/repos/gentoo/Manifest | |
cd bob-portage || exit 1 | |
docker run --rm -v /run/docker.sock:/run/docker.sock -v "$(pwd):/src:ro" -w /src -e CONTAINER_MODE=entrypoint "$KUBLER_IMAGE" dgoss run -w /goss --entrypoint /goss/goss "${PORTAGE_IMAGE}" validate --color | |
- name: 🐋🍳 Docker Bake Kubler portage - list targets | |
if: ${{ steps.portage-pull.outcome == 'failure' || steps.portage-pull-test.outcome == 'failure' }} | |
uses: docker/bake-action/subaction/list-targets@v4 | |
with: | |
workdir: bob-portage | |
- name: 🐋🍳 Docker Bake Kubler portage | |
if: ${{ steps.portage-pull.outcome == 'failure' || steps.portage-pull-test.outcome == 'failure' }} | |
uses: docker/bake-action@v4 | |
with: | |
workdir: bob-portage | |
push: true | |
set: | | |
kubler-portage.tags=${{ env.TMP_PORTAGE_IMAGE }} | |
kubler-portage.cache-from=type=gha,scope=portage | |
kubler-portage.cache-to=type=gha,scope=portage | |
- name: 🐋🍳 Docker Bake Kubler portage - test baked | |
if: ${{ steps.portage-pull.outcome == 'failure' || steps.portage-pull-test.outcome == 'failure' }} | |
run: | | |
set -eux | |
docker run --rm "${TMP_PORTAGE_IMAGE}" grep TIMESTAMP /var/db/repos/gentoo/Manifest | |
cd bob-portage || exit 1 | |
docker run --rm -v /run/docker.sock:/run/docker.sock -v "$(pwd):/src:ro" -w /src -e CONTAINER_MODE=entrypoint "$KUBLER_IMAGE" dgoss run -w /goss --entrypoint /goss/goss "${TMP_PORTAGE_IMAGE}" validate --color | |
- name: 🐋🍳 Docker Bake Kubler portage - oras cp | |
if: ${{ steps.portage-pull.outcome == 'failure' || steps.portage-pull-test.outcome == 'failure' }} | |
env: | |
TMP_IMAGE: ${{ env.TMP_PORTAGE_IMAGE }} | |
IMAGE: ${{ env.PORTAGE_IMAGE }} | |
run: | | |
set -eux | |
# Strip tag from end of string | |
LATEST="${IMAGE%:*}" | |
oras cp -v "$TMP_IMAGE" "$IMAGE" | |
oras cp -v "$TMP_IMAGE" "$LATEST" | |
- name: Output PORTAGE_IMAGE | |
id: portage_image | |
run: | | |
set -eux | |
echo "portage_image=${PORTAGE_IMAGE}" >> $GITHUB_OUTPUT |