149 lines
5.3 KiB
YAML
149 lines
5.3 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
|
|
|
|
steps:
|
|
- name: Prepare environment
|
|
run: |
|
|
set -euo pipefail
|
|
|
|
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}"
|
|
|
|
echo "DATE_TAG=$(date -u +'%Y%m%d')" >> "${GITHUB_ENV}"
|
|
echo "BUILD_DATE_ISO=$(date -u +'%Y-%m-%dT%H:%M:%SZ')" >> "${GITHUB_ENV}"
|
|
|
|
- name: Checkout
|
|
uses: actions/checkout@v7.0.1
|
|
|
|
- name: Prepare Registry Auth File
|
|
env:
|
|
AUTH_BASE64: ${{ secrets.READONLY_AUTH_BASE64 }}
|
|
run: |
|
|
set -euo pipefail
|
|
|
|
sed "s|READONLY_TOKEN_PLACEHOLDER|${AUTH_BASE64}|g" \
|
|
configs/auth.json.template > configs/auth.json
|
|
|
|
- name: Set up Docker Buildx
|
|
uses: docker/setup-buildx-action@v4.3.0
|
|
|
|
- name: Image Metadata
|
|
id: metadata
|
|
uses: docker/metadata-action@v6.2.0
|
|
with:
|
|
images: ${{ env.IMAGE_REGISTRY }}/${{ env.IMAGE_NAME }}
|
|
tags: |
|
|
type=raw,value=${{ env.DEFAULT_TAG }},enable=${{ github.ref_name == 'main' }}
|
|
type=raw,value=${{ env.DEFAULT_TAG }}.${{ env.DATE_TAG }},enable=${{ github.ref_name == 'main' }}
|
|
type=raw,value=${{ env.DATE_TAG }},enable=${{ github.ref_name == 'main' }}
|
|
type=raw,value=test-{{branch}},enable=${{ github.ref_name != 'main' && github.event_name != 'pull_request' }}
|
|
type=ref,event=pr,prefix=test-pr-
|
|
labels: |
|
|
org.opencontainers.image.created=${{ env.BUILD_DATE_ISO }}
|
|
org.opencontainers.image.description=${{ env.IMAGE_DESC }}
|
|
org.opencontainers.image.documentation=${{ github.server_url }}/${{ github.repository }}
|
|
org.opencontainers.image.source=${{ github.server_url }}/${{ github.repository }}
|
|
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.DEFAULT_TAG }}.${{ env.DATE_TAG }}
|
|
containers.bootc=1
|
|
ostree.bootable=1
|
|
|
|
- name: Login to Gitea Container Registry
|
|
if: github.event_name != 'pull_request'
|
|
uses: docker/login-action@v4.6.0
|
|
with:
|
|
registry: ${{ env.REGISTRY_HOST }}
|
|
username: ${{ github.repository_owner }}
|
|
password: ${{ secrets.REGISTRY }}
|
|
|
|
- name: Build and Push Image
|
|
id: build_image
|
|
uses: docker/build-push-action@v7.3.0
|
|
with:
|
|
context: .
|
|
file: ./Containerfile
|
|
platforms: linux/amd64
|
|
push: ${{ github.event_name != 'pull_request' }}
|
|
tags: ${{ steps.metadata.outputs.tags }}
|
|
labels: ${{ steps.metadata.outputs.labels }}
|
|
oci-mediatypes: true
|
|
compression: zstd
|
|
provenance: false
|
|
sbom: false
|
|
cache-from: type=registry,ref=${{ env.IMAGE_REGISTRY }}/${{ env.IMAGE_NAME }}:buildcache-amd64-main
|
|
cache-to: type=registry,ref=${{ env.IMAGE_REGISTRY }}/${{ env.IMAGE_NAME }}:buildcache-amd64-main,mode=max
|
|
outputs: type=registry,oci-mediatypes=true,compression=zstd,compression-args=binary-path=/usr/bin/go-zstd-chunked
|
|
|
|
- name: Install gettext dependencies
|
|
if: github.event_name != 'pull_request' && github.ref_name == 'main'
|
|
run: |
|
|
set -euo pipefail
|
|
sudo apt-get update
|
|
sudo apt-get install -y gettext
|
|
|
|
- name: Install Cosign
|
|
if: github.event_name != 'pull_request' && github.ref_name == 'main'
|
|
uses: sigstore/cosign-installer@v4.1.2
|
|
|
|
- name: Sign container image
|
|
if: github.event_name != 'pull_request' && github.ref_name == 'main'
|
|
env:
|
|
COSIGN_PRIVATE_KEY: ${{ secrets.SIGNING_SECRET }}
|
|
COSIGN_PASSWORD: ""
|
|
run: |
|
|
set -euo pipefail
|
|
|
|
echo "${{ secrets.REGISTRY }}" | cosign login \
|
|
"${{ env.REGISTRY_HOST }}" \
|
|
-u "${{ github.repository_owner }}" \
|
|
--password-stdin
|
|
|
|
IMAGE="${{ env.IMAGE_REGISTRY }}/${{ env.IMAGE_NAME }}"
|
|
DIGEST="${{ steps.build_image.outputs.digest }}"
|
|
|
|
test -n "${DIGEST}"
|
|
|
|
cosign sign -y \
|
|
--key env://COSIGN_PRIVATE_KEY \
|
|
--use-signing-config=false \
|
|
--new-bundle-format=false \
|
|
--registry-referrers-mode=legacy \
|
|
"${IMAGE}@${DIGEST}"
|
|
|
|
- name: Post-Build Cleanup
|
|
if: always()
|
|
run: |
|
|
rm -f configs/auth.json
|
|
docker buildx prune -a -f || true |