This repository has been archived on 2026-10-15. You can view files and clone it. You cannot open issues or pull requests or push a commit.
Files
resuable-workflows/.gitea/workflows/docker.yaml
T
UltimateCoderandClaude Sonnet 5 b0ce78f80f Add replace-build-vars composite action, wire into docker.yaml
Replaces {{BUILD_VAR_*}} placeholders in all text files of the calling
repo's checkout with Gitea Actions build/commit/branch info before the
docker build step runs. Language-agnostic (plain text substitution),
runs unconditionally, no-op when no placeholders are present.

Co-Authored-By: Claude Sonnet 5 <[email protected]>
Claude-Session: https://claude.ai/code/session_01VVTCJvvJmS4fCSrm5wxwVo
2026-09-05 13:39:20 +02:00

93 lines
3.0 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: Replace build placeholders
uses: UltimateCoder/resuable-workflows/actions/replace-build-vars@v3
- 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