Skip to content

🚀 Optimize Docker Image #9

🚀 Optimize Docker Image

🚀 Optimize Docker Image #9

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
tags:
- 'v*.*.*'
# pull_request:
# branches:
# - main
workflow_dispatch:
jobs:
test:
runs-on: ubuntu-latest
steps:
# Step 1: Checkout the repository code
- name: Checkout repository
uses: actions/checkout@v4
# Step 2: Install Go
- name: Set up Go
uses: actions/setup-go@v5
with:
go-version: '1.23' # Specify the Go version you need
# Step 3: Run tests
- name: Run Go tests
run: |
go test ./... -v -short
build-and-push:
needs: test
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: .
target: production
push: true
tags: ghcr.io/${{ github.repository_owner }}/snipbox:${{ env.COMMIT_SHORT_SHA }},ghcr.io/${{ github.repository_owner }}/snipbox:latest