56 lines
1.6 KiB
YAML
56 lines
1.6 KiB
YAML
name: Build & Publish Docker Image
|
|
|
|
on:
|
|
push:
|
|
branches:
|
|
- main
|
|
tags:
|
|
- "v*"
|
|
|
|
jobs:
|
|
build-and-push:
|
|
runs-on: gitea-runner
|
|
|
|
steps:
|
|
- name: Checkout
|
|
uses: actions/checkout@v4
|
|
|
|
# Strip "https://" from the server URL to get the registry hostname
|
|
- name: Resolve registry host
|
|
id: reg
|
|
run: |
|
|
host=$(echo "${{ gitea.server_url }}" | sed 's|https://||;s|http://||;s|/||g')
|
|
echo "host=$host" >> $GITEA_OUTPUT
|
|
echo "image=$host/${{ gitea.repository }}" >> $GITEA_OUTPUT
|
|
|
|
- name: Set up Docker Buildx
|
|
uses: docker/setup-buildx-action@v3
|
|
|
|
- name: Log in to Gitea registry
|
|
uses: docker/login-action@v3
|
|
with:
|
|
registry: ${{ steps.reg.outputs.host }}
|
|
username: ${{ secrets.REGISTRY_USER }}
|
|
password: ${{ secrets.REGISTRY_TOKEN }}
|
|
|
|
- name: Extract Docker metadata
|
|
id: meta
|
|
uses: docker/metadata-action@v5
|
|
with:
|
|
images: ${{ steps.reg.outputs.image }}
|
|
tags: |
|
|
type=raw,value=latest,enable=${{ gitea.ref == 'refs/heads/main' }}
|
|
type=semver,pattern={{version}}
|
|
type=semver,pattern={{major}}.{{minor}}
|
|
type=sha,prefix=sha-,format=short
|
|
|
|
- name: Build and push
|
|
uses: docker/build-push-action@v6
|
|
with:
|
|
context: .
|
|
push: true
|
|
tags: ${{ steps.meta.outputs.tags }}
|
|
labels: ${{ steps.meta.outputs.labels }}
|
|
cache-from: type=registry,ref=${{ steps.reg.outputs.image }}:cache
|
|
cache-to: type=registry,ref=${{ steps.reg.outputs.image }}:cache,mode=max
|