Skip to content

main

main #44

Workflow file for this run

name: main
on:
schedule:
- cron: "0 22 * * 0" # every sunday at 10pm
push:
branches:
- "main"
tags:
- "v?[0-9]+.[0-9]+.[0-9]+*"
pull_request:
branches:
- "main"
jobs:
container_build:
name: Container build and push
runs-on: ubuntu-latest
steps:
- name: Check out repository
uses: actions/checkout@v4
- name: Set build variables
id: env
run: |
REGISTRY=ghcr.io/
IMAGE=zeiss/acme-dns-azure
VERSION=noop
if [ "${{ github.event_name }}" = "schedule" ]; then
VERSION=edge
elif [[ $GITHUB_REF == refs/tags/* ]]; then
VERSION=${GITHUB_REF#refs/tags/}
elif [[ $GITHUB_REF == refs/heads/* ]]; then
VERSION=$(echo ${GITHUB_REF#refs/heads/} | sed -r 's#/+#-#g')
if [ "${{ github.event.repository.default_branch }}" = "$VERSION" ]; then
VERSION=edge
fi
elif [[ $GITHUB_REF == refs/pull/* ]]; then
VERSION=pr-${{ github.event.number }}
fi
TAGS="${REGISTRY}${IMAGE}:${VERSION}"
if [[ $VERSION =~ ^v?[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}$ ]]; then
VERSION_STRIP=${VERSION#v}
MINOR=${VERSION_STRIP%.*}
MAJOR=${MINOR%.*}
TAGS="$TAGS,${REGISTRY}${IMAGE}:${MINOR},${REGISTRY}${IMAGE}:${MAJOR},${REGISTRY}${IMAGE}:latest"
# elif [ "${{ github.event_name }}" = "push" ]; then
# TAGS="$TAGS,${REGISTRY}${IMAGE}:sha-${GITHUB_SHA::8}"
fi
echo "version=${VERSION}" >> $GITHUB_OUTPUT
echo "tags=${TAGS}" >> $GITHUB_OUTPUT
echo "created=$(date -u +'%Y-%m-%dT%H:%M:%SZ')" >> $GITHUB_OUTPUT
- name: Set up QEMU
uses: docker/setup-qemu-action@v3
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v3
with:
config-inline: |
[worker.oci]
max-parallelism = 4
- name: Check out Docker Buildx cache
uses: actions/cache@v3
with:
path: /tmp/.buildx-cache
key: ${{ runner.os }}-buildx-${{ github.sha }}
restore-keys: |
${{ runner.os }}-buildx-
- name: Login to GitHub Container Registry
if: github.event_name != 'pull_request'
uses: docker/login-action@v3
with:
registry: ghcr.io
username: ${{ github.repository_owner }}
password: ${{ secrets.GITHUB_TOKEN }}
- name: Build and push image
id: docker_build
uses: docker/build-push-action@v5
with:
context: ./targets/container
file: ./targets/container/Dockerfile
platforms: linux/amd64,linux/arm64,linux/386,linux/arm/v7
push: ${{ github.event_name != 'pull_request' }}
tags: ${{ steps.env.outputs.tags }}
cache-from: type=local,src=/tmp/.buildx-cache
cache-to: type=local,dest=/tmp/.buildx-cache
labels: |
org.opencontainers.image.created=${{ steps.env.outputs.created }}
org.opencontainers.image.source=https://github.com/${{ github.repository }}
org.opencontainers.image.version=${{ steps.env.outputs.version }}
org.opencontainers.image.revision=${{ github.sha }}
org.opencontainers.image.licenses=${{ github.event.repository.license.name }}