Update GitHub Actions workflow for build process
This commit is contained in:
+20
-56
@@ -30,22 +30,23 @@ jobs:
|
||||
steps:
|
||||
- name: Prepare environment
|
||||
run: |
|
||||
# Lowercase the image uri
|
||||
echo "IMAGE_REGISTRY=${IMAGE_REGISTRY,,}" >> ${GITHUB_ENV}
|
||||
echo "IMAGE_NAME=${IMAGE_NAME,,}" >> ${GITHUB_ENV}
|
||||
|
||||
- name: Checkout
|
||||
uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v5
|
||||
uses: actions/checkout@v4
|
||||
|
||||
- name: Mount BTRFS for podman storage
|
||||
id: container-storage-action
|
||||
uses: ublue-os/container-storage-action@911baca08baf30c8654933e9e9723cb399892140 # main
|
||||
uses: ublue-os/container-storage-action@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
|
||||
uses: docker/metadata-action@v5
|
||||
id: metadata
|
||||
with:
|
||||
tags: |
|
||||
@@ -80,7 +81,7 @@ jobs:
|
||||
|
||||
- name: Build Image
|
||||
id: build_image
|
||||
uses: redhat-actions/buildah-build@7a95fa7ee0f02d552a32753e7414641a04307056 # v2
|
||||
uses: redhat-actions/buildah-build@v2
|
||||
with:
|
||||
containerfiles: |
|
||||
./Containerfile
|
||||
@@ -89,66 +90,30 @@ jobs:
|
||||
labels: ${{ steps.metadata.outputs.labels }}
|
||||
oci: true
|
||||
|
||||
- name: Apply chunkah optimization
|
||||
id: chunkah
|
||||
# Intelligentes Rechunking auf RPM-Paketbasis mit maximal 128 Layern
|
||||
- name: Apply native bootc rechunking
|
||||
id: rechunk
|
||||
run: |
|
||||
set -x
|
||||
BASE_IMAGE="${{ env.IMAGE_NAME }}:${{ env.DEFAULT_TAG }}"
|
||||
|
||||
# 1. Das originale ostree-Label im Runner auslesen und sichern
|
||||
OSTREE_DIFFID=$(podman inspect $BASE_IMAGE --format '{{index .Config.Labels "ostree.final-diffid"}}' 2>/dev/null || echo "")
|
||||
BASE_IMAGE="localhost/${{ env.IMAGE_NAME }}:${{ env.DEFAULT_TAG }}"
|
||||
mkdir -p ./chunkah-out
|
||||
|
||||
# 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
|
||||
|
||||
# Die originale Image-Config extrahieren
|
||||
podman inspect $BASE_IMAGE --format '{{json .Config}}' > ./chunkah-config.json
|
||||
|
||||
# Chunkah-Lauf
|
||||
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/ \
|
||||
rpm-ostree compose build-chunked-oci \
|
||||
--bootc \
|
||||
--format-version=2 \
|
||||
--max-layers 128 \
|
||||
--compressed \
|
||||
--output /outputs/image.ociarchive \
|
||||
--rootfs /inputs
|
||||
|
||||
# 2. Das von Chunkah erzeugte Archiv wieder laden und das OCI-Label fest einbrennen
|
||||
if [ ! -z "$OSTREE_DIFFID" ]; then
|
||||
podman load -i ./chunkah-out/image.ociarchive
|
||||
|
||||
# dangling-ID des neuen Images greifen
|
||||
OPT_IMAGE_ID=$(podman images --filter "dangling=true" --format "{{.ID}}" | head -n 1)
|
||||
|
||||
# Ein modifiziertes OCI-Image mit Buildah erstellen (erhält die OCI-Struktur exakt aufrecht)
|
||||
BUILDAH_CONTAINER=$(buildah from $OPT_IMAGE_ID)
|
||||
buildah config --label "ostree.final-diffid=$OSTREE_DIFFID" $BUILDAH_CONTAINER
|
||||
|
||||
# Altes Archiv löschen und durch das final gelabelte OCI-Archiv ersetzen
|
||||
rm ./chunkah-out/image.ociarchive
|
||||
buildah commit --rm $BUILDAH_CONTAINER oci-archive:./chunkah-out/image.ociarchive
|
||||
|
||||
# Lokalen Speicher aufräumen
|
||||
podman rmi $OPT_IMAGE_ID || true
|
||||
fi
|
||||
--from=$BASE_IMAGE \
|
||||
--output=oci-archive:./chunkah-out/image.ociarchive
|
||||
|
||||
- name: Login to GitHub Container Registry
|
||||
uses: docker/login-action@4907a6ddec9925e35a0a9e82d7399ccc52663121 # v3
|
||||
uses: docker/login-action@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 via Skopeo
|
||||
- name: Push to GHCR via Skopeo (with ZSTD Compression)
|
||||
if: github.event_name != 'pull_request' && github.ref == format('refs/heads/{0}', github.event.repository.default_branch)
|
||||
run: |
|
||||
set -x
|
||||
@@ -156,7 +121,7 @@ jobs:
|
||||
export REGISTRY_AUTH_FILE=$HOME/.docker/config.json
|
||||
REGISTRY_PATH="${{ env.IMAGE_REGISTRY }}/${{ env.IMAGE_NAME }}"
|
||||
|
||||
# Loop über alle Tags
|
||||
# Loop über alle generierten Tags aus dem Metadata-Schritt
|
||||
for tag in ${{ steps.metadata.outputs.tags }}; do
|
||||
skopeo copy \
|
||||
--dest-compress-format=zstd \
|
||||
@@ -165,18 +130,17 @@ jobs:
|
||||
docker://$REGISTRY_PATH:$tag
|
||||
done
|
||||
|
||||
# KORREKTUR: Wir fragen den echten, finalen Digest direkt von GHCR ab
|
||||
# Den echten, von der Registry vergebenen Manifest-Digest abfragen
|
||||
FINAL_REGISTRY_DIGEST=$(skopeo inspect docker://$REGISTRY_PATH:${{ env.DEFAULT_TAG }} --format '{{.Digest}}')
|
||||
echo "REGISTRY_DIGEST=$FINAL_REGISTRY_DIGEST" >> $GITHUB_ENV
|
||||
|
||||
- name: Install Cosign
|
||||
uses: sigstore/cosign-installer@6f9f17788090df1f26f669e9d70d6ae9567deba6 # v4.1.2
|
||||
uses: sigstore/cosign-installer@v4
|
||||
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: |
|
||||
# Signiert den exakten, von der Registry bestätigten Digest
|
||||
cosign sign -y --key env://COSIGN_PRIVATE_KEY "${{ env.IMAGE_REGISTRY }}/${{ env.IMAGE_NAME }}@${{ env.REGISTRY_DIGEST }}"
|
||||
env:
|
||||
COSIGN_EXPERIMENTAL: false
|
||||
|
||||
Reference in New Issue
Block a user