Use Buildah instead of Docker and build three times a month instead of every day

This commit is contained in:
Anders da Silva Rytter Hansen 2026-01-05 18:06:29 -03:00
commit fa7c3a5c4e
2 changed files with 58 additions and 81 deletions

View file

@ -1,42 +1,32 @@
name: os name: os
# This workflow uses actions that are not certified by GitHub.
# They are provided by a third-party and are governed by
# separate terms of service, privacy policy, and support
# documentation.
on: on:
schedule: schedule:
- cron: '0 5 * * *' # 5 am every day - cron: '0 5 8,18,28 * *'
push: push:
paths: paths:
- 'Dockerfile' - 'Dockerfile'
- 'etc/**' - 'etc/**'
- 'usr/**' - 'usr/**'
- 'repo/**' - 'repo/**'
- '.github/workflows/os.yml'
workflow_dispatch:
env: env:
# Use docker.io for Docker Hub if empty
REGISTRY: ghcr.io REGISTRY: ghcr.io
# github.repository as <account>/<repo>
IMAGE_NAME: ${{ github.repository }} IMAGE_NAME: ${{ github.repository }}
IMAGE_REGISTRY: ghcr.io/${{ github.repository_owner }}
jobs: jobs:
build: build:
runs-on: ubuntu-latest runs-on: ubuntu-latest
permissions: permissions:
contents: read contents: read
packages: write packages: write
# This is used to complete the identity challenge id-token: write # Påkrævet til cosign keyless signering
# with sigstore/fulcio when running outside of PRs.
id-token: write
steps: steps:
- name: Maximize build space - name: Maximize build space
uses: AdityaGarg8/remove-unwanted-software@v1 uses: AdityaGarg8/remove-unwanted-software@v5
with: with:
remove-dotnet: 'true' remove-dotnet: 'true'
remove-android: 'true' remove-android: 'true'
@ -44,71 +34,62 @@ jobs:
- name: Get current date - name: Get current date
id: date id: date
run: echo "::set-output name=date::$(date +'%Y%m%d')" run: echo "date=$(date +'%Y%m%d')" >> $GITHUB_OUTPUT
- name: Test with environment variables
run: echo $DATE
env:
DATE: ${{ steps.date.outputs.date }}
- name: Checkout repository - name: Checkout repository
uses: actions/checkout@v3 uses: actions/checkout@v4
# Install the cosign tool except on PR
# https://github.com/sigstore/cosign-installer
- name: Install cosign
if: github.event_name != 'pull_request'
uses: sigstore/cosign-installer@6e04d228eb30da1757ee4e1dd75a0ec73a653e06 #v3.1.1
with:
cosign-release: 'v2.1.1'
# Workaround: https://github.com/docker/build-push-action/issues/461
- name: Setup Docker buildx
uses: docker/setup-buildx-action@79abd3f86f79a9d68a23c75a09a9a85889262adf
# Login against a Docker registry except on PR
# https://github.com/docker/login-action
- name: Log into registry ${{ env.REGISTRY }}
if: github.event_name != 'pull_request'
uses: docker/login-action@28218f9b04b4f3f62068d7b6ce6ca5b26e35336c
with:
registry: ${{ env.REGISTRY }}
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}
# Extract metadata (tags, labels) for Docker
# https://github.com/docker/metadata-action
- name: Extract Docker metadata - name: Extract Docker metadata
id: meta id: meta
uses: docker/metadata-action@98669ae865ea3cffbcbaa878cf57c20bbf1c6c38 uses: docker/metadata-action@v5
with: with:
images: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }} images: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}
# Vi konstruerer tags her med branch-navnet som præfiks
tags: |
type=ref,event=branch
type=raw,value=latest,enable={{is_default_branch}}
type=raw,value=${{ github.ref_name }}-10
type=raw,value=${{ github.ref_name }}-10.${{ steps.date.outputs.date }}
# Build and push Docker image with Buildx (don't push on PR) - name: Log into GHCR
# https://github.com/docker/build-push-action if: github.event_name != 'pull_request'
- name: Build and push Docker image run: |
id: build-and-push buildah login -u ${{ github.actor }} -p ${{ secrets.GITHUB_TOKEN }} ${{ env.REGISTRY }}
uses: docker/build-push-action@ac9327eae2b366085ac7f6a2d02df8aa8ead720a
with:
context: .
push: ${{ github.event_name != 'pull_request' }}
tags: ${{ steps.meta.outputs.tags }}, ${{ steps.meta.outputs.tags }}-10, ${{ steps.meta.outputs.tags }}-10.${{ steps.date.outputs.date }}
# labels: ${{ steps.meta.outputs.labels }}
cache-from: type=gha
cache-to: type=gha,mode=max
- name: Build image with Buildah
id: build-image
run: |
# Vi bygger med 'raw-img' lokalt
buildah bud \
--label "org.opencontainers.image.source=https://github.com/${{ github.repository }}" \
-t raw-img .
# Sign the resulting Docker image digest except on PRs. # Gem det primære tag til signering (vi tager det første fra listen)
# This will only write to the public Rekor transparency log when the Docker PRIMARY_TAG=$(echo "${{ steps.meta.outputs.tags }}" | head -n 1)
# repository is public to avoid leaking data. If you would like to publish echo "primary_tag=$PRIMARY_TAG" >> $GITHUB_OUTPUT
# transparency data even for private images, pass --force to cosign below.
# https://github.com/sigstore/cosign - name: Push to GHCR
- name: Sign the published Docker image if: github.event_name != 'pull_request'
if: ${{ github.event_name != 'pull_request' }} run: |
env: for tag in $(echo "${{ steps.meta.outputs.tags }}"); do
# https://docs.github.com/en/actions/security-guides/security-hardening-for-github-actions#using-an-intermediate-environment-variable echo "Tagging and pushing: $tag"
TAGS: ${{ steps.meta.outputs.tags }} buildah tag raw-img "$tag"
DIGEST: ${{ steps.build-and-push.outputs.digest }} buildah push "$tag"
# This step uses the identity token to provision an ephemeral certificate done
# against the sigstore community Fulcio instance.
run: echo "${TAGS}" | xargs -I {} cosign sign --yes {}@${DIGEST} - name: Install cosign
if: github.event_name != 'pull_request'
uses: sigstore/cosign-installer@v3.3.0
# VI TILFØJER LOGIN TIL COSIGN HER
- name: Log into GHCR (Cosign)
if: github.event_name != 'pull_request'
run: |
cosign login ${{ env.REGISTRY }} -u ${{ github.actor }} -p ${{ secrets.GITHUB_TOKEN }}
- name: Sign image
if: github.event_name != 'pull_request'
run: |
# Vi signerer det primære tag.
# Vi bruger --yes til at acceptere betingelserne automatisk.
cosign sign --yes "${{ steps.build-image.outputs.primary_tag }}"

View file

@ -1,8 +1,4 @@
FROM quay.io/almalinuxorg/atomic-desktop-kde:10 FROM quay.io/almalinuxorg/atomic-desktop-kde:10
ARG CACHEBUST=1
# Get list of kernels from my repo. If the list has been updated, then the image will be rebuilt. If it hasn't been updated, then caching of the previous build will be used.
ADD "https://copr.fedorainfracloud.org/api_3/build/list?ownername=andersrh&projectname=my-ostree-os&packagename=kernel" /tmp/builds.txt
RUN echo 'omit_drivers+=" nouveau "' | tee /etc/dracut.conf.d/blacklist-nouveau.conf RUN echo 'omit_drivers+=" nouveau "' | tee /etc/dracut.conf.d/blacklist-nouveau.conf