Avoids double compression (chunkah zstd + Skopeo zstd:chunked). push-to-registry handles auth and multi-tag push natively.
157 lines
6.7 KiB
YAML
157 lines
6.7 KiB
YAML
name: Build container image
|
|
on:
|
|
pull_request:
|
|
branches:
|
|
- main
|
|
schedule:
|
|
- cron: '05 12 * * 2,5'
|
|
workflow_dispatch:
|
|
|
|
env:
|
|
IMAGE_DESC: "Custom Fedora bootc image"
|
|
IMAGE_NAME: "${{ github.event.repository.name }}"
|
|
IMAGE_REGISTRY: "ghcr.io/${{ github.repository_owner }}"
|
|
DEFAULT_TAG: "stable"
|
|
|
|
concurrency:
|
|
group: ${{ github.workflow }}-${{ github.ref || github.run_id }}
|
|
cancel-in-progress: true
|
|
|
|
jobs:
|
|
build_push:
|
|
name: Build and push image
|
|
runs-on: ubuntu-24.04
|
|
|
|
permissions:
|
|
contents: read
|
|
packages: write
|
|
id-token: write
|
|
|
|
steps:
|
|
- name: Prepare environment
|
|
run: |
|
|
echo "IMAGE_REGISTRY=${IMAGE_REGISTRY,,}" >> ${GITHUB_ENV}
|
|
echo "IMAGE_NAME=${IMAGE_NAME,,}" >> ${GITHUB_ENV}
|
|
|
|
- name: Checkout
|
|
uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v5
|
|
|
|
- name: Mount BTRFS for podman storage
|
|
id: container-storage-action
|
|
uses: ublue-os/container-storage-action@911baca08baf30c8654933e9e9723cb399892140 # main
|
|
with:
|
|
target-dir: /var/lib/containers
|
|
mount-opts: compress-force=zstd:2
|
|
|
|
- name: Image Metadata
|
|
uses: docker/metadata-action@80c7e94dd9b9319bd5eb7a0e0fe9291e23a2a2e9 # v5
|
|
id: metadata
|
|
with:
|
|
tags: |
|
|
type=raw,value=${{ env.DEFAULT_TAG }}
|
|
type=raw,value=${{ env.DEFAULT_TAG }}.{{date 'YYYYMMDD'}}
|
|
type=raw,value={{date 'YYYYMMDD'}}
|
|
type=sha,enable=${{ github.event_name == 'pull_request' }}
|
|
type=ref,event=pr
|
|
labels: |
|
|
org.opencontainers.image.created={{date 'YYYY-MM-DDTHH:mm:ssZ'}}
|
|
org.opencontainers.image.description=${{ env.IMAGE_DESC }}
|
|
org.opencontainers.image.documentation=https://raw.githubusercontent.com/${{ github.repository_owner }}/${{ env.IMAGE_NAME }}/${{ github.sha }}/README.md
|
|
org.opencontainers.image.source=https://github.com/${{ github.repository_owner }}/${{ env.IMAGE_NAME }}/blob/${{ github.sha }}/Containerfile
|
|
org.opencontainers.image.title=${{ env.IMAGE_NAME }}
|
|
org.opencontainers.image.url=https://github.com/${{ github.repository_owner }}/${{ env.IMAGE_NAME }}/tree/${{ github.sha }}
|
|
org.opencontainers.image.vendor=${{ github.repository_owner }}
|
|
org.opencontainers.image.version=${{ env.DEFAULT_TAG }}.{{date 'YYYYMMDD'}}
|
|
containers.bootc=1
|
|
sep-tags: " "
|
|
sep-annotations: " "
|
|
|
|
# OPTIMIERUNG 1: Der Cache lauscht jetzt auf Containerfile UND alle Skripte/Configs
|
|
- name: Cache buildah layers
|
|
uses: actions/cache@27d5ce7f107fe9357f9df03efb73ab90386fccae # v5.0.5
|
|
with:
|
|
path: |
|
|
/var/lib/containers/storage/overlay
|
|
~/.cache/buildah
|
|
/tmp/.buildah-cache
|
|
key: ${{ runner.os }}-${{ github.workflow }}-${{ hashFiles('Containerfile', 'build/**', 'configs/**', 'scripts/**') }}-${{ github.ref }}
|
|
restore-keys: |
|
|
${{ runner.os }}-${{ github.workflow }}-${{ hashFiles('Containerfile', 'build/**', 'configs/**', 'scripts/**') }}-
|
|
${{ runner.os }}-${{ github.workflow }}-
|
|
|
|
- name: Build Image
|
|
id: build_image
|
|
uses: redhat-actions/buildah-build@7a95fa7ee0f02d552a32753e7414641a04307056 # v2
|
|
with:
|
|
containerfiles: |
|
|
./Containerfile
|
|
image: ${{ env.IMAGE_NAME }}
|
|
tags: ${{ env.DEFAULT_TAG }}
|
|
labels: ${{ steps.metadata.outputs.labels }}
|
|
oci: true
|
|
|
|
- name: Rechunk with chunkah
|
|
run: |
|
|
set -euo pipefail
|
|
|
|
IMG="localhost/${{ env.IMAGE_NAME }}:${{ env.DEFAULT_TAG }}"
|
|
CHUNKED_IMG="localhost/${{ env.IMAGE_NAME }}-chunked:${{ env.DEFAULT_TAG }}"
|
|
|
|
# Image-Config fuer chunkah sichern (Labels, Annotations, etc.)
|
|
CONFIG=$(buildah inspect "$IMG" | jq -c .)
|
|
|
|
# Platz schaffen fuer den Rechunk (OCI-Archive + Original passen nicht beide)
|
|
sudo rm -rf /tmp/.buildah-cache/* 2>/dev/null || true
|
|
|
|
# chunkah: content-based Layer-Splitting
|
|
# --max-layers 128: Desktop-Images brauchen mehr als Default (64)
|
|
# --prune /sysroot/: entfernt OSTree-Metadaten (optional seit bootc 1.1.3)
|
|
# --label ostree.*: entfernt gueltigkeitsfaehige ostree-Labels
|
|
buildah build --skip-unused-stages=false \
|
|
--from "$IMG" \
|
|
--build-arg CHUNKAH_CONFIG_STR="$CONFIG" \
|
|
--build-arg "CHUNKAH_ARGS=--prune /sysroot/ --max-layers 128 --compressed --label ostree.commit- --label ostree.final-diffid-" \
|
|
-t "$CHUNKED_IMG" \
|
|
https://github.com/coreos/chunkah/releases/download/v0.5.0/Containerfile.splitter
|
|
|
|
# Platz freigeben: Original und Zwischenprodukt entfernen
|
|
buildah rmi "$IMG"
|
|
buildah tag "$CHUNKED_IMG" "$IMG"
|
|
buildah rmi "$CHUNKED_IMG"
|
|
|
|
- name: Login to GitHub Container Registry
|
|
uses: docker/login-action@650006c6eb7dba73a995cc03b0b2d7f5ca915bee # v3
|
|
if: github.event_name != 'pull_request' && github.ref == format('refs/heads/{0}', github.event.repository.default_branch)
|
|
with:
|
|
registry: ghcr.io
|
|
username: ${{ github.actor }}
|
|
password: ${{ secrets.GITHUB_TOKEN }}
|
|
|
|
- name: Push to GHCR
|
|
if: github.event_name != 'pull_request' && github.ref == format('refs/heads/{0}', github.event.repository.default_branch)
|
|
uses: redhat-actions/push-to-registry@v2
|
|
with:
|
|
image: ${{ env.IMAGE_NAME }}
|
|
tags: ${{ steps.metadata.outputs.tags }}
|
|
registry: ${{ env.IMAGE_REGISTRY }}
|
|
username: ${{ github.actor }}
|
|
password: ${{ secrets.GITHUB_TOKEN }}
|
|
|
|
- name: Get registry digest
|
|
if: github.event_name != 'pull_request' && github.ref == format('refs/heads/{0}', github.event.repository.default_branch)
|
|
run: |
|
|
FINAL_REGISTRY_DIGEST=$(skopeo inspect docker://${{ env.IMAGE_REGISTRY }}/${{ env.IMAGE_NAME }}:${{ env.DEFAULT_TAG }} --format '{{.Digest}}')
|
|
echo "REGISTRY_DIGEST=$FINAL_REGISTRY_DIGEST" >> $GITHUB_ENV
|
|
|
|
- name: Install Cosign
|
|
uses: sigstore/cosign-installer@6f9f17788090df1f26f669e9d70d6ae9567deba6 # v4.1.2
|
|
if: github.event_name != 'pull_request' && github.ref == format('refs/heads/{0}', github.event.repository.default_branch)
|
|
|
|
- name: Sign container image
|
|
if: github.event_name != 'pull_request' && github.ref == format('refs/heads/{0}', github.event.repository.default_branch)
|
|
run: |
|
|
cosign sign -y --key env://COSIGN_PRIVATE_KEY "${{ env.IMAGE_REGISTRY }}/${{ env.IMAGE_NAME }}@${{ env.REGISTRY_DIGEST }}"
|
|
env:
|
|
COSIGN_EXPERIMENTAL: false
|
|
COSIGN_PRIVATE_KEY: ${{ secrets.SIGNING_SECRET }}
|