Skip to content

apk-builder

apk-builder #147

Workflow file for this run

---
name: apk-builder
'on':
schedule:
# Rebuild images on Sunday
- cron: '25 8 * * 0'
push:
branches: [ master ]
# Allows you to run this workflow manually from the Actions tab
workflow_dispatch:
env:
IMAGE_NAME: kamailio-builder
IMAGE_REPO: ghcr.io
jobs:
build:
name: Build image
strategy:
fail-fast: false
matrix:
os:
- alpine-edge
- alpine-latest
include:
# setting base iamge
- base_image: alpine:edge
os: alpine-edge
- base_image: alpine:latest
os: alpine-latest
runs-on: ubuntu-latest
permissions:
packages: write
steps:
- name: is required base image update
id: check_base_image
run: |
set -x
docker pull ${{ matrix.base_image }}
docker pull ${{env.IMAGE_REPO}}/${{ github.repository_owner }}/${{ env.IMAGE_NAME }}:${{ matrix.os }}
SHA_ALPINE=$(docker image inspect -f '{{index .RootFS.Layers 0}}' ${{ matrix.base_image }})
SHA_BUILDER=$(docker image inspect -f '{{index .RootFS.Layers 0}}' ${{env.IMAGE_REPO}}/${{ github.repository_owner }}/${{ env.IMAGE_NAME }}:${{ matrix.os }})
if [ "${GITHUB_EVENT_NAME}" = "workflow_dispatch" -o "${SHA_ALPINE}" != "${SHA_BUILDER}" ]; then
echo "update=true" >> $GITHUB_OUTPUT
else
echo "Builder already use fresh alpine base image, finishing"
echo "update=false" >> $GITHUB_OUTPUT
fi
- name: checkout sources
uses: actions/checkout@v4
if: steps.check_base_image.outputs.update == 'true'
- name: print commit info
id: init
if: steps.check_base_image.outputs.update == 'true'
run: |
git log -n 1
- name: Image metadata
id: metadata
uses: docker/metadata-action@v5
if: steps.check_base_image.outputs.update == 'true'
with:
# list of Docker images to use as base name for tags
images: |
${{env.IMAGE_REPO}}/${{ github.repository_owner }}/${{ env.IMAGE_NAME }}
tags: |
${{ matrix.os }}
flavor: |
latest=false
- name: Set up QEMU
uses: docker/setup-qemu-action@v3
if: steps.check_base_image.outputs.update == 'true'
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v3
if: steps.check_base_image.outputs.update == 'true'
- name: Login to GitHub Container Registry
uses: docker/login-action@v3
if: steps.check_base_image.outputs.update == 'true'
with:
registry: ${{ env.IMAGE_REPO }}
username: ${{ github.repository_owner }}
password: ${{ secrets.GITHUB_TOKEN }}
- name: Build builder image
uses: docker/build-push-action@v6
if: steps.check_base_image.outputs.update == 'true'
id: build
env:
DOCKER_BUILD_SUMMARY: false
with:
tags: ${{ steps.metadata.outputs.tags }}
labels: ${{ steps.metadata.outputs.labels }}
platforms: "linux/386,linux/amd64,linux/arm/v6,linux/arm/v7,linux/arm64/v8,linux/ppc64le,linux/riscv64,linux/s390x"
context: "{{defaultContext}}:apk"
push: true
build-args: |
base_image=${{ matrix.base_image }}
cleanup:
name: Cleanup untaged images
runs-on: ubuntu-latest
continue-on-error: true
permissions:
packages: write
needs:
- build
steps:
- name: Cleanup untaged
uses: dataaxiom/ghcr-cleanup-action@v1
with:
owner: ${{ github.repository_owner }}
package: ${{ env.IMAGE_NAME }}