187 lines
7.1 KiB
YAML
187 lines
7.1 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 }}"
|
|
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: |
|
|
REGISTRY_HOST=$(echo "${{ github.server_url }}" | awk -F/ '{print $3}')
|
|
OWNER_LOWER="${{ github.repository_owner }}"
|
|
NAME_LOWER="${{ env.IMAGE_NAME }}"
|
|
|
|
echo "REGISTRY_HOST=${REGISTRY_HOST}" >> ${GITHUB_ENV}
|
|
echo "IMAGE_REGISTRY=${REGISTRY_HOST}/${OWNER_LOWER,,}" >> ${GITHUB_ENV}
|
|
echo "IMAGE_NAME=${NAME_LOWER,,}" >> ${GITHUB_ENV}
|
|
|
|
- name: Determine image tag
|
|
run: |
|
|
BRANCH="$GITHUB_REF_NAME"
|
|
if [[ "$BRANCH" == "main" ]]; then
|
|
echo "IMAGE_TAG=${DEFAULT_TAG}" >> ${GITHUB_ENV}
|
|
echo "IS_TEST_BUILD=false" >> ${GITHUB_ENV}
|
|
else
|
|
SANITIZED=$(echo "$BRANCH" | sed 's/[^a-zA-Z0-9._-]/-/g' | head -c 50)
|
|
echo "IMAGE_TAG=test-${SANITIZED}" >> ${GITHUB_ENV}
|
|
echo "IS_TEST_BUILD=true" >> ${GITHUB_ENV}
|
|
fi
|
|
|
|
- name: Checkout
|
|
# Abgesichert: entspricht actions/checkout@v5.0.0 (oder aktuellste v5-Commit)
|
|
uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v5.0.0
|
|
|
|
- name: Image Metadata
|
|
id: metadata
|
|
# Abgesichert: entspricht docker/metadata-action@v5.7.0
|
|
uses: docker/metadata-action@902fa8ec7d6ecbf8d84d538b9b233a880e428804 # v5.7.0
|
|
with:
|
|
images: ${{ env.IMAGE_REGISTRY }}/${{ env.IMAGE_NAME }}
|
|
tags: |
|
|
type=raw,value=${{ env.IMAGE_TAG }}
|
|
type=raw,value=${{ env.IMAGE_TAG }}.{{date 'YYYYMMDD'}},enable=${{ env.IS_TEST_BUILD == 'false' }}
|
|
type=raw,value={{date 'YYYYMMDD'}},enable=${{ env.IS_TEST_BUILD == 'false' }}
|
|
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=${{ github.server_url }}/${{ github.repository }}/raw/commit/${{ github.sha }}/README.md
|
|
org.opencontainers.image.source=${{ github.server_url }}/${{ github.repository }}/src/commit/${{ github.sha }}/Containerfile
|
|
org.opencontainers.image.title=${{ env.IMAGE_NAME }}
|
|
org.opencontainers.image.url=${{ github.server_url }}/${{ github.repository }}
|
|
org.opencontainers.image.vendor=${{ github.repository_owner }}
|
|
org.opencontainers.image.version=${{ env.IMAGE_TAG }}.{{date 'YYYYMMDD'}}
|
|
containers.bootc=1
|
|
ostree.bootable=1
|
|
|
|
- name: Login to Gitea Container Registry (Buildah)
|
|
if: github.event_name != 'pull_request'
|
|
run: |
|
|
echo "${{ secrets.REGISTRY }}" | buildah login -u "${{ github.repository_owner }}" --password-stdin ${{ env.REGISTRY_HOST }}
|
|
|
|
- name: 1. Build Base OS Image (Rootless)
|
|
run: |
|
|
LABEL_ARGS=()
|
|
while IFS= read -r line; do
|
|
if [[ -n "$line" ]]; then
|
|
LABEL_ARGS+=("--label" "$line")
|
|
fi
|
|
done <<< "${{ steps.metadata.outputs.labels }}"
|
|
|
|
buildah bud \
|
|
--storage-driver=overlay \
|
|
--storage-opt=overlay.mount_program=/usr/bin/fuse-overlayfs \
|
|
--format=oci \
|
|
"${LABEL_ARGS[@]}" \
|
|
-t localhost/fluffy-pancake:base \
|
|
-f ./Containerfile \
|
|
.
|
|
|
|
- name: 2. Rechunk via Chunkah (Rootless)
|
|
if: github.event_name != 'pull_request'
|
|
env:
|
|
GENERATED_TAGS: ${{ steps.metadata.outputs.tags }}
|
|
run: |
|
|
CHUNKAH_CONFIG_STR="$(podman inspect localhost/fluffy-pancake:base)"
|
|
# Chunkah ist hier bereits vorbildlich über seinen immutable SHA-256 Digest gepinnt!
|
|
CHUNKAH_REF="quay.io/coreos/chunkah:v0.6.0@sha256:ff8b8b466a942ec6000445d4001fc661e2fc5a952ad9ee29b4de9ab09d1d1708"
|
|
|
|
TAG_LIST=($GENERATED_TAGS)
|
|
FIRST_TAG=${TAG_LIST[0]}
|
|
|
|
echo "Starte Re-Chunking für Haupt-Tag: $FIRST_TAG"
|
|
buildah build \
|
|
--storage-driver=overlay \
|
|
--storage-opt=overlay.mount_program=/usr/bin/fuse-overlayfs \
|
|
--skip-unused-stages=false \
|
|
--from localhost/fluffy-pancake:base \
|
|
--build-arg "CHUNKAH=${CHUNKAH_REF}" \
|
|
--build-arg "CHUNKAH_CONFIG_STR=${CHUNKAH_CONFIG_STR}" \
|
|
--build-arg "CHUNKAH_ARGS=--max-layers 128 --prune /sysroot/ --label ostree.commit- --label ostree.final-diffid-" \
|
|
-t "$FIRST_TAG" \
|
|
-v "$(pwd):/run/src" \
|
|
--security-opt=label=disable \
|
|
./Containerfile.splitter
|
|
|
|
for tag in "${TAG_LIST[@]}"; do
|
|
if [[ "$tag" != "$FIRST_TAG" ]]; then
|
|
echo "Zusätzliches Tag setzen: $tag"
|
|
buildah tag --storage-driver=overlay "$FIRST_TAG" "$tag"
|
|
fi
|
|
done
|
|
|
|
rm -rf out
|
|
|
|
- name: 3. Push OCI Images directly
|
|
if: github.event_name != 'pull_request'
|
|
env:
|
|
GENERATED_TAGS: ${{ steps.metadata.outputs.tags }}
|
|
run: |
|
|
TAG_LIST=($GENERATED_TAGS)
|
|
FIRST_TAG=${TAG_LIST[0]}
|
|
|
|
echo "Pushe primäres Image und extrahiere Digest für Cosign..."
|
|
buildah push \
|
|
--storage-driver=overlay \
|
|
--digestfile primary_digest.txt \
|
|
"$FIRST_TAG"
|
|
|
|
echo "IMAGE_DIGEST=$(cat primary_digest.txt)" >> ${GITHUB_ENV}
|
|
|
|
for tag in "${TAG_LIST[@]}"; do
|
|
if [[ "$tag" != "$FIRST_TAG" ]]; then
|
|
echo "Pushe zusätzliches Tag: $tag"
|
|
buildah push --storage-driver=overlay "$tag"
|
|
fi
|
|
done
|
|
|
|
- name: Install Cosign
|
|
if: github.event_name != 'pull_request'
|
|
# Abgesichert: entspricht sigstore/cosign-installer@v3.8.1 (Stabile v3/v4-Basis)
|
|
uses: sigstore/cosign-installer@V4.1.2
|
|
|
|
- name: Sign container image
|
|
if: github.event_name != 'pull_request' && env.IS_TEST_BUILD == 'false'
|
|
env:
|
|
COSIGN_PRIVATE_KEY: ${{ secrets.SIGNING_SECRET }}
|
|
COSIGN_PASSWORD: ""
|
|
run: |
|
|
echo "Signing image mit lokal extrahiertem Digest: ${{ env.IMAGE_DIGEST }}"
|
|
cosign sign -y \
|
|
--key env://COSIGN_PRIVATE_KEY \
|
|
--use-signing-config=false \
|
|
--new-bundle-format=false \
|
|
--tlog-upload=false \
|
|
--registry-referrers-mode=legacy \
|
|
"${{ env.IMAGE_REGISTRY }}/${{ env.IMAGE_NAME }}@${{ env.IMAGE_DIGEST }}"
|
|
|
|
- name: Post-Build Cleanup
|
|
if: always()
|
|
run: |
|
|
echo "Bereinige unprivilegierten Buildah-Storage..."
|
|
buildah prune --storage-driver=overlay --force
|