Files
ws4kp/.github/workflows/build-docker.yaml

67 lines
2.1 KiB
YAML

name: build-docker
on:
push:
# main publishes images, dev and dev/* only check that the image builds
branches:
- main
- dev
- 'dev/**'
tags:
- 'v*.*.*'
- 'v*.*'
# check that pull requests build, without publishing anything
pull_request:
jobs:
build:
name: Build Image
runs-on: ubuntu-latest
permissions:
contents: read
packages: write
steps:
- name: Checkout
uses: actions/checkout@v5
- name: Docker meta
id: meta
uses: docker/metadata-action@v6
with:
images: |
ghcr.io/netbymatt/ws4kp
flavor: |
latest=false
tags: |
type=raw,priority=1000,value=latest,enable=${{ github.ref == 'refs/heads/main' }}
type=ref,event=branch
type=semver,pattern={{version}}
type=semver,pattern={{major}}.{{minor}}
type=semver,pattern={{major}}
type=sha
# QEMU is only needed for the arm64 build, which pull requests skip
- name: Set up QEMU
if: github.event_name != 'pull_request'
uses: docker/setup-qemu-action@v4
- name: Set up Buildx
uses: docker/setup-buildx-action@v4
# pull requests never push, so they don't need to log in (a fork's token is read-only anyway)
- name: Login to GitHub Container Registry
if: github.event_name != 'pull_request'
uses: docker/login-action@v4
with:
registry: ghcr.io
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}
- name: Build and Push
id: docker_build
uses: docker/build-push-action@v7
with:
context: .
pull: true
push: ${{ github.ref == 'refs/heads/main' || github.ref == 'refs/heads/dev' || startsWith(github.ref, 'refs/tags/') }}
platforms: ${{ github.event_name == 'pull_request' && 'linux/amd64' || 'linux/amd64,linux/arm64/v8' }}
tags: ${{ steps.meta.outputs.tags }}
labels: ${{ steps.meta.outputs.labels }}
cache-from: type=gha
cache-to: type=gha,mode=max