ci: add GitHub Actions workflow for Docker Hub auto-publish

Triggers on push to main and version tags. Requires DOCKERHUB_USERNAME
and DOCKERHUB_TOKEN secrets configured in GitHub repo settings.
This commit is contained in:
Siddharth Kumar Sah
2026-03-22 19:29:57 +08:00
parent ce03aad10f
commit 22b08c0475
+52
View File
@@ -0,0 +1,52 @@
name: Build and Push Docker Image
on:
push:
branches: [main]
tags: ["v*"]
workflow_dispatch:
env:
REGISTRY: docker.io
IMAGE_NAME: siddharth123sk/stirling-image
jobs:
build-and-push:
runs-on: ubuntu-latest
permissions:
contents: read
packages: write
steps:
- name: Checkout
uses: actions/checkout@v4
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v3
- name: Log in to Docker Hub
uses: docker/login-action@v3
with:
username: ${{ secrets.DOCKERHUB_USERNAME }}
password: ${{ secrets.DOCKERHUB_TOKEN }}
- name: Extract metadata
id: meta
uses: docker/metadata-action@v5
with:
images: ${{ env.IMAGE_NAME }}
tags: |
type=raw,value=latest,enable={{is_default_branch}}
type=semver,pattern={{version}}
type=sha,prefix=
- name: Build and push
uses: docker/build-push-action@v5
with:
context: .
file: docker/Dockerfile
push: true
tags: ${{ steps.meta.outputs.tags }}
labels: ${{ steps.meta.outputs.labels }}
cache-from: type=gha
cache-to: type=gha,mode=max