ci: improve multi-arch builds #292
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# SPDX-FileCopyrightText: © Vegard IT GmbH (https://vegardit.com) | |
# SPDX-FileContributor: Sebastian Thomschke | |
# SPDX-License-Identifier: Apache-2.0 | |
# SPDX-ArtifactOfProjectHomePage: https://github.com/vegardit/docker-gitea-act-runner | |
# | |
# https://docs.github.com/en/actions/writing-workflows/workflow-syntax-for-github-actions | |
name: Build | |
on: | |
push: | |
branches-ignore: # build all branches except: | |
- 'dependabot/**' # prevent GHA triggered twice (once for commit to the branch and once for opening/syncing the PR) | |
tags-ignore: # don't build tags | |
- '**' | |
paths-ignore: | |
- '**/*.md' | |
- '.editorconfig' | |
- '.git*' | |
- '.github/*.yml' | |
- '.github/workflows/stale.yml' | |
pull_request: | |
paths-ignore: | |
- '**/*.md' | |
- '.editorconfig' | |
- '.git*' | |
- '.github/*.yml' | |
- '.github/workflows/stale.yml' | |
schedule: | |
# https://docs.github.com/en/actions/writing-workflows/choosing-when-your-workflow-runs/events-that-trigger-workflows | |
- cron: '0 17 * * 3' | |
workflow_dispatch: | |
# https://docs.github.com/en/actions/writing-workflows/choosing-when-your-workflow-runs/events-that-trigger-workflows#workflow_dispatch | |
inputs: | |
VERSION: | |
type: string | |
default: latest | |
description: Version of the Gitea Act Runner, see https://dl.gitea.com/act_runner/ | |
defaults: | |
run: | |
shell: bash | |
env: | |
DOCKER_REPO_NAME: gitea-act-runner | |
TRIVY_CACHE_DIR: ~/.trivy/cache | |
jobs: | |
########################################################### | |
build: | |
########################################################### | |
runs-on: ubuntu-latest # https://github.com/actions/runner-images#available-images | |
timeout-minutes: 30 | |
permissions: | |
packages: write | |
strategy: | |
matrix: | |
include: | |
- DOCKER_IMAGE_FLAVOR: dood | |
DOCKER_IMAGE_TAG_PREFIX: "" | |
GITEA_ACT_RUNNER_VERSION: latest | |
- DOCKER_IMAGE_FLAVOR: dind | |
DOCKER_IMAGE_TAG_PREFIX: dind- | |
GITEA_ACT_RUNNER_VERSION: latest | |
- DOCKER_IMAGE_FLAVOR: dind-rootless | |
DOCKER_IMAGE_TAG_PREFIX: dind-rootless- | |
GITEA_ACT_RUNNER_VERSION: latest | |
- DOCKER_IMAGE_FLAVOR: dood | |
DOCKER_IMAGE_TAG_PREFIX: "" | |
GITEA_ACT_RUNNER_VERSION: nightly | |
- DOCKER_IMAGE_FLAVOR: dind | |
DOCKER_IMAGE_TAG_PREFIX: dind- | |
GITEA_ACT_RUNNER_VERSION: nightly | |
- DOCKER_IMAGE_FLAVOR: dind-rootless | |
DOCKER_IMAGE_TAG_PREFIX: dind-rootless- | |
GITEA_ACT_RUNNER_VERSION: nightly | |
fail-fast: true | |
steps: | |
- name: "Show: GitHub context" | |
env: | |
GITHUB_CONTEXT: ${{ toJSON(github) }} | |
run: echo $GITHUB_CONTEXT | |
- name: "Show: environment variables" | |
run: env | sort | |
- name: Git Checkout | |
uses: actions/checkout@v4 # https://github.com/actions/checkout | |
- name: Run the sh-checker | |
uses: luizm/action-sh-checker@master # https://github.com/marketplace/actions/sh-checker | |
env: | |
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} | |
SHFMT_OPTS: --simplify --keep-padding | |
with: | |
sh_checker_comment: true | |
sh_checker_checkbashisms_enable: true | |
sh_checker_shfmt_disable: true | |
- name: Check Dockerfile | |
uses: hadolint/[email protected] | |
with: | |
dockerfile: image/Dockerfile | |
- name: Cache trivy cache | |
uses: actions/cache@v4 | |
with: | |
path: ${{ env.TRIVY_CACHE_DIR }} | |
# https://github.com/actions/cache/issues/342#issuecomment-673371329 | |
key: ${{ runner.os }}-trivy-${{ github.run_id }} | |
restore-keys: | | |
${{ runner.os }}-trivy- | |
- name: Configure fast APT repository mirror | |
uses: vegardit/fast-apt-mirror.sh@v1 | |
- name: Install dos2unix | |
run: sudo apt-get install --no-install-recommends -y dos2unix | |
- name: "Determine if docker images shall be published" | |
id: docker_push_actions | |
run: | | |
# ACT -> https://nektosact.com/usage/index.html#skipping-steps | |
set -x | |
if [[ $GITHUB_REF_NAME == 'main' && $GITHUB_EVENT_NAME != 'pull_request' && -z "$ACT" ]]; then | |
echo "DOCKER_PUSH_GHCR=true" >> "$GITHUB_ENV" | |
echo "DOCKER_PUSH_GHCR=true" >> $GITHUB_OUTPUT | |
if [[ -n "${{ secrets.DOCKER_HUB_USERNAME }}" ]]; then | |
echo "DOCKER_PUSH=true" >> "$GITHUB_ENV" | |
fi | |
fi | |
- name: Login to docker.io | |
if: ${{ env.DOCKER_PUSH }} | |
uses: docker/login-action@v3 | |
with: | |
username: ${{ secrets.DOCKER_HUB_USERNAME }} | |
password: ${{ secrets.DOCKER_HUB_TOKEN }} | |
- name: Login to ghcr.io | |
if: ${{ env.DOCKER_PUSH_GHCR }} | |
uses: docker/login-action@v3 | |
with: | |
registry: ghcr.io | |
username: ${{ github.actor }} | |
password: ${{ secrets.GITHUB_TOKEN }} | |
- name: Build ${{ env.DOCKER_REPO_NAME }}:${{ env.DOCKER_IMAGE_TAG }} | |
env: | |
DOCKER_BASE_IMAGE: ghcr.io/dockerhub-mirror/debian:stable-slim | |
DOCKER_IMAGE_REPO: ${{ github.repository_owner }}/${{ env.DOCKER_REPO_NAME }} | |
DOCKER_IMAGE_TAG_PREFIX: ${{ matrix.DOCKER_IMAGE_TAG_PREFIX }} | |
DOCKER_IMAGE_FLAVOR: ${{ matrix.DOCKER_IMAGE_FLAVOR }} | |
TRIVY_GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} | |
run: | | |
if [[ -n "${{ inputs.VERSION }}" ]]; then | |
export GITEA_ACT_RUNNER_VERSION="${{ inputs.VERSION }}" | |
else | |
export GITEA_ACT_RUNNER_VERSION="${{ matrix.GITEA_ACT_RUNNER_VERSION }}" | |
fi | |
bash build-image.sh | |
outputs: | |
DOCKER_PUSH_GHCR: ${{ steps.docker_push_actions.outputs.DOCKER_PUSH_GHCR }} | |
########################################################### | |
delete-untagged-images: | |
########################################################### | |
runs-on: ubuntu-latest # https://github.com/actions/runner-images#available-images | |
timeout-minutes: 5 | |
needs: [build] | |
if: ${{ needs.build.outputs.DOCKER_PUSH_GHCR }} | |
concurrency: | |
group: ${{ github.workflow }} | |
cancel-in-progress: false | |
permissions: | |
packages: write | |
steps: | |
- name: Delete untagged images | |
uses: dataaxiom/ghcr-cleanup-action@v1 | |
with: | |
package: ${{ env.DOCKER_REPO_NAME }} | |
delete-untagged: true | |
delete-partial-images: true | |
delete-ghost-images: true | |
delete-orphaned-images: true | |
validate: true |