Update Docker build and push workflow

This commit is contained in:
2026-01-19 23:13:07 +01:00
parent 3450740cdf
commit 0469a73106

View File

@@ -1,44 +1,52 @@
name: Docker Build and Push
name: Build and Push Docker Image
on:
push:
branches:
- main
- master
tags:
- 'v*'
pull_request:
branches:
- main
permissions:
contents: read
packages: write
jobs:
build-and-push:
runs-on: ubuntu-latest
steps:
- name: Checkout
- name: Check out repository code
uses: actions/checkout@v3
- name: Set up QEMU
uses: docker/setup-qemu-action@v2
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v2
- name: Login to Registry
- name: Login to Gitea Container Registry
uses: docker/login-action@v2
with:
registry: ${{ secrets.DOCKER_REGISTRY }}
username: ${{ secrets.DOCKER_USERNAME }}
password: ${{ secrets.DOCKER_PASSWORD }}
registry: git.govekar.net
username: lovrog05
password: ${{ secrets.PACKAGES_SECRET }}
- name: Extract metadata (tags, labels) for Docker
id: meta
uses: docker/metadata-action@v4
with:
images: ${{ secrets.DOCKER_REGISTRY }}/${{ secrets.DOCKER_USERNAME }}/matrix-gif-widget
tags: |
type=ref,event=branch
type=sha,format=long
- name: Build Docker Image
env:
BRANCH_NAME: ${{ github.ref_name }}
SHORT_HASH: ${{ github.sha }}
run: |
# Build the image with the commit hash tag
docker build --build-arg BUILD_IDENTIFIER=${SHORT_HASH:0:5} -t git.govekar.net/lovrog05/glm-host:${BRANCH_NAME}-${SHORT_HASH:0:5} .
- name: Build and push
uses: docker/build-push-action@v4
with:
context: .
push: true
tags: ${{ steps.meta.outputs.tags }}
labels: ${{ steps.meta.outputs.labels }}
# Tag the same image as "latest"
docker tag git.govekar.net/lovrog05/glm-host:${BRANCH_NAME}-${SHORT_HASH:0:5} git.govekar.net/lovrog05/glm-host:${BRANCH_NAME}-latest
- name: Push Docker Images
env:
BRANCH_NAME: ${{ github.ref_name }}
SHORT_HASH: ${{ github.sha }}
run: |
docker push git.govekar.net/lovrog05/glm-host:${BRANCH_NAME}-${SHORT_HASH:0:5}
docker push git.govekar.net/lovrog05/glm-host:${BRANCH_NAME}-latest
- name: Log out from registry
if: always()
run: docker logout git.govekar.net