Files
UltimateCoder c52dc1f989 fix(docker): push image on PR builds, fix feature branch tags
- Add PR support: build pushes :latest and :pr-<number> tag
- Fix feature branch tags: replace / with - to produce valid Docker tags

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-04-26 14:39:58 +02:00

90 lines
2.9 KiB
YAML

name: Docker build & push
on:
workflow_call:
inputs:
DockerImageDomain:
description: 'Docker registry domain, e.g. registry.example.com'
required: true
type: string
DockerImageOrganisation:
description: 'Namespace / organisation in the registry'
required: true
type: string
DockerImageName:
description: 'Image name'
required: true
type: string
DockerFilePath:
description: 'Path to the Dockerfile'
required: false
type: string
default: ./Dockerfile
DockerImageVersion:
description: 'Value used for the VERSION build-arg'
required: true
type: string
secrets:
DockerUsername:
description: 'Registry username'
required: true
DockerPassword:
description: 'Registry password / token'
required: true
jobs:
build-and-push:
runs-on: ubuntu-latest
env:
IMAGE: ${{ inputs.DockerImageDomain }}/${{ inputs.DockerImageOrganisation }}/${{ inputs.DockerImageName }}
steps:
- name: Checkout
uses: actions/checkout@v4
- name: Build Image
run: |
docker build \
-t "$IMAGE:latest" \
. \
--file "${{ inputs.DockerFilePath }}" \
--build-arg VERSION=${{ inputs.DockerImageVersion }}
- name: Docker Release - Master
if: startsWith(github.ref, 'refs/heads/master')
run: |
docker image tag "$IMAGE:latest" "$IMAGE:${GITHUB_REF_NAME}"
- name: Docker Release - Dev
if: startsWith(github.ref, 'refs/heads/develop') || startsWith(github.ref, 'refs/heads/feature/')
run: |
TAG="${GITHUB_REF_NAME//\//-}"
docker image tag "$IMAGE:latest" "$IMAGE:${TAG}"
- name: Docker Release - Tagged
if: startsWith(github.ref, 'refs/tags/')
run: |
docker image tag "$IMAGE:latest" "$IMAGE:${GITHUB_REF_NAME}"
- name: Docker Release - PR
if: startsWith(github.ref, 'refs/pull/')
run: |
PR_NUM=${GITHUB_REF#refs/pull/}
PR_NUM=${PR_NUM%/head}
docker image tag "$IMAGE:latest" "$IMAGE:pr-${PR_NUM}"
- name: Docker Push
if: startsWith(github.ref, 'refs/heads/master') || startsWith(github.ref, 'refs/heads/develop') || startsWith(github.ref, 'refs/heads/feature/') || startsWith(github.ref, 'refs/tags/') || startsWith(github.ref, 'refs/pull/')
env:
USERNAME: ${{ secrets.DockerUsername }}
PASSWORD: ${{ secrets.DockerPassword }}
run: |
echo "$PASSWORD" | docker login "${{ inputs.DockerImageDomain }}" -u "$USERNAME" --password-stdin
docker push -a "$IMAGE"
# docker system prune --all --force --filter until=6h
- name: Cleanup
run: |
docker images "$IMAGE" --format "{{.Repository}}:{{.Tag}}" | xargs -r docker rmi -f