184 lines
7.3 KiB
YAML
184 lines
7.3 KiB
YAML
name: Build container image
|
|
on:
|
|
pull_request:
|
|
branches:
|
|
- main
|
|
schedule:
|
|
- cron: '05 12 * * 2,5'
|
|
# push:
|
|
#branches:
|
|
#- main
|
|
#paths-ignore:
|
|
# - '**/README.md'
|
|
workflow_dispatch:
|
|
|
|
env:
|
|
IMAGE_DESC: "Custom Fedora bootc image"
|
|
IMAGE_NAME: "${{ github.event.repository.name }}" # output image name, usually same as repo name
|
|
IMAGE_REGISTRY: "ghcr.io/${{ github.repository_owner }}" # do not edit
|
|
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: |
|
|
# Lowercase the image uri
|
|
echo "IMAGE_REGISTRY=${IMAGE_REGISTRY,,}" >> ${GITHUB_ENV}
|
|
echo "IMAGE_NAME=${IMAGE_NAME,,}" >> ${GITHUB_ENV}
|
|
|
|
# These stage versions are pinned by https://github.com/renovatebot/renovate
|
|
- 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
|
|
continue-on-error: true
|
|
with:
|
|
target-dir: /var/lib/containers
|
|
mount-opts: compress-force=zstd:2
|
|
|
|
- name: Image Metadata
|
|
uses: docker/metadata-action@030e881283bb7a6894de51c315a6bfe6a94e05cf # 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: " "
|
|
|
|
- name: Cache buildah layers
|
|
uses: actions/cache@v5
|
|
with:
|
|
path: |
|
|
/var/lib/containers/storage/overlay
|
|
~/.cache/buildah
|
|
/tmp/.buildah-cache
|
|
key: ${{ runner.os }}-${{ github.workflow }}-${{ hashFiles('Containerfile') }}-${{ github.ref }}
|
|
restore-keys: |
|
|
${{ runner.os }}-${{ github.workflow }}-${{ hashFiles('Containerfile') }}-
|
|
|
|
- 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
|
|
|
|
# --- CHUNKAH OPTIMIERUNG ---
|
|
- name: Apply chunkah optimization
|
|
id: chunkah
|
|
run: |
|
|
set -x
|
|
BASE_IMAGE="${{ env.IMAGE_NAME }}:${{ env.DEFAULT_TAG }}"
|
|
|
|
# Rootfs extrahieren
|
|
CONTAINER_ID=$(podman create $BASE_IMAGE)
|
|
mkdir -p ./chunkah-in ./chunkah-out
|
|
podman export $CONTAINER_ID | tar -xf - -C ./chunkah-in
|
|
podman rm $CONTAINER_ID
|
|
|
|
# Original-Konfiguration sichern
|
|
podman inspect $BASE_IMAGE --format '{{json .Config}}' > ./chunkah-config.json
|
|
|
|
# Chunkah-Lauf (Jetzt mit korrektem --rootfs Flag)
|
|
podman run --rm \
|
|
-v ./chunkah-in:/inputs:z \
|
|
-v ./chunkah-out:/outputs:z \
|
|
-v ./chunkah-config.json:/config.json:z \
|
|
quay.io/coreos/chunkah:latest \
|
|
build \
|
|
--config /config.json \
|
|
--prune /sysroot/ \
|
|
--max-layers 128 \
|
|
--compressed \
|
|
--output /outputs/image.ociarchive \
|
|
--rootfs /inputs
|
|
|
|
# Altes Image löschen, um Platz zu machen und Eindeutigkeit beim Laden zu sichern
|
|
podman rmi $BASE_IMAGE
|
|
podman load -i ./chunkah-out/image.ociarchive
|
|
|
|
# Eindeutige ID-Zuweisung des frisch geladenen Images (schließt das Chunkah-Image aus)
|
|
IMAGE_ID=$(podman images --filter "dangling=true" --format "{{.ID}}" | head -n 1)
|
|
if [ -z "$IMAGE_ID" ]; then
|
|
IMAGE_ID=$(podman images --format "{{.ID}} {{.Repository}}" | grep -v "chunkah" | head -n 1 | awk '{print $1}')
|
|
fi
|
|
podman tag $IMAGE_ID $BASE_IMAGE
|
|
|
|
|
|
- name: Tag for registry
|
|
run: |
|
|
for tag in ${{ steps.metadata.outputs.tags }}; do
|
|
podman tag ${{ env.IMAGE_NAME }}:${{ env.DEFAULT_TAG }} ${{ env.IMAGE_NAME }}:$tag
|
|
done
|
|
|
|
# Login to GitHub Container Registry
|
|
- name: Login to GitHub Container Registry
|
|
uses: docker/login-action@4907a6ddec9925e35a0a9e82d7399ccc52663121 # 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
|
|
uses: redhat-actions/push-to-registry@5ed88d269cf581ea9ef6dd6806d01562096bee9c # v2
|
|
if: github.event_name != 'pull_request' && github.ref == format('refs/heads/{0}', github.event.repository.default_branch)
|
|
id: push
|
|
env:
|
|
REGISTRY_USER: ${{ github.actor }}
|
|
REGISTRY_PASSWORD: ${{ github.token }}
|
|
with:
|
|
registry: ${{ env.IMAGE_REGISTRY }}
|
|
image: ${{ env.IMAGE_NAME }}
|
|
tags: ${{ steps.metadata.outputs.tags }}
|
|
username: ${{ env.REGISTRY_USER }}
|
|
password: ${{ env.REGISTRY_PASSWORD }}
|
|
# Erzwingt die Beibehaltung und Kompression der Layer als ZSTD beim Push in die Registry
|
|
extra-args: --compression-format=zstd --compression-level=5
|
|
|
|
- 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: |
|
|
# Statisches Signing basierend auf dem unveränderlichen SHA256-Digest des Push-Schritts
|
|
cosign sign -y --key env://COSIGN_PRIVATE_KEY "${{ env.IMAGE_REGISTRY }}/${{ env.IMAGE_NAME }}@${{ steps.push.outputs.digest }}"
|
|
env:
|
|
COSIGN_EXPERIMENTAL: false
|
|
COSIGN_PRIVATE_KEY: ${{ secrets.SIGNING_SECRET }}
|