Skip to content

Build and Publish Docker Image #5

Build and Publish Docker Image

Build and Publish Docker Image #5

Workflow file for this run

name: Build and Publish Docker Image
# Trigger the workflow on push or pull request to the main branch
on:
push:
# branches:
# - main
# - release
tags:
- 'v*.*.*'
# pull_request:
# branches:
# - main
# - release
workflow_dispatch:
jobs:
build-and-push:
runs-on: ubuntu-latest
permissions:
contents: read
packages: write
steps:
# Step 1: Checkout the repository code
- name: Checkout repository
uses: actions/checkout@v4
# Step 2: Set up Docker Buildx
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v3
# Step 3: Log in to Docker Hub (or GHCR if you prefer)
- name: Log in to Docker Hub
uses: docker/login-action@v3
with:
registry: ghcr.io
username: ${{ github.actor }} # Docker Hub username (use GitHub actor if using GHCR)
password: ${{ secrets.GITHUB_TOKEN }} # Docker Hub password (use GitHub token if using GHCR)
- name: Set short git commit SHA
id: vars
run: |
calculatedSha=$(git rev-parse --short ${{ github.sha }})
echo "COMMIT_SHORT_SHA=$calculatedSha" >> $GITHUB_ENV
- name: Build and push
uses: docker/build-push-action@v6
with:
context: .
push: true
tags: ghcr.io/${{ github.repository_owner }}/snipbox:${{ env.COMMIT_SHORT_SHA }},ghcr.io/${{ github.repository_owner }}/snipbox:latest