- Change username and password fields in the Docker login action to utilize secrets for enhanced security. - Ensure compatibility with different registry user configurations by allowing fallback to the repository owner.
58 lines
1.7 KiB
YAML
58 lines
1.7 KiB
YAML
name: Docker Image bauen & veröffentlichen
|
|
|
|
on:
|
|
# Kein Build auf Branch-Pushes (dev/main).
|
|
# Build nur, wenn ein Versions-Tag (v*) gesetzt wird
|
|
# -> also beim Release-Merge dev -> main inkl. Tag.
|
|
push:
|
|
tags:
|
|
- "v*"
|
|
workflow_dispatch:
|
|
|
|
env:
|
|
# Host der Gitea Container Registry (bei Bedarf als Repo-Variable REGISTRY überschreiben)
|
|
REGISTRY: ${{ vars.REGISTRY || 'git.hexahost.dev' }}
|
|
IMAGE_NAME: ${{ github.repository }}
|
|
|
|
jobs:
|
|
build-and-push:
|
|
runs-on: ubuntu-latest
|
|
permissions:
|
|
contents: read
|
|
packages: write
|
|
|
|
steps:
|
|
- name: Repository auschecken
|
|
uses: actions/checkout@v4
|
|
|
|
- name: Docker Buildx einrichten
|
|
uses: docker/setup-buildx-action@v3
|
|
|
|
- name: An Gitea Container Registry anmelden
|
|
uses: docker/login-action@v3
|
|
with:
|
|
registry: ${{ env.REGISTRY }}
|
|
username: ${{ secrets.REGISTRY_USER || github.repository_owner }}
|
|
password: ${{ secrets.REGISTRY_TOKEN }}
|
|
|
|
- name: Metadaten (Tags & Labels) bestimmen
|
|
id: meta
|
|
uses: docker/metadata-action@v5
|
|
with:
|
|
images: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}
|
|
tags: |
|
|
type=semver,pattern={{version}}
|
|
type=semver,pattern={{major}}.{{minor}}
|
|
type=semver,pattern={{major}}
|
|
type=sha,format=short
|
|
type=raw,value=latest,enable=${{ startsWith(github.ref, 'refs/tags/') }}
|
|
|
|
- name: Image bauen & pushen
|
|
uses: docker/build-push-action@v6
|
|
with:
|
|
context: .
|
|
file: ./Dockerfile
|
|
push: true
|
|
tags: ${{ steps.meta.outputs.tags }}
|
|
labels: ${{ steps.meta.outputs.labels }}
|