Skip to content

Docker Builds

Docker Builds #6

Workflow file for this run

name: Docker Builds
on:
workflow_dispatch:
push:
branches:
- main
tags:
- "v*.*.*"
paths:
- "src/**"
- "Dockerfile"
- "package.json"
- "package-lock.json"
- "nginx.conf"
- "__posts"
- "__books"
schedule:
- cron: "0 03 * * 1-5"
permissions:
contents: read
jobs:
docker:
runs-on: ubuntu-24.04
permissions:
contents: write
packages: write
steps:
- name: 🛡️ Harden the runner
uses: step-security/harden-runner@ec9f2d5744a09debf3a187a3f4f675c53b671911 # v2.13.0
with:
egress-policy: audit
- name: 📦 Checkout code
uses: actions/checkout@08c6903cd8c0fde910a37f88322edcfb5dd907a8 # v5
with:
fetch-depth: 0
- name: 🔑 Log in to GitHub Container Registry
uses: docker/login-action@v3
with:
registry: ghcr.io
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}
- name: 🏷️ Get package version
id: get_package_version
run: echo "VERSION=$(node -p "require('./package.json').version")" >> $GITHUB_OUTPUT
- name: 🔍 Check if version is SNAPSHOT
id: check_snapshot
run: |
VERSION="${{ steps.get_package_version.outputs.VERSION }}"
if [[ "$VERSION" == *"-SNAPSHOT"* ]]; then
echo "IS_SNAPSHOT=true" >> $GITHUB_OUTPUT
else
echo "IS_SNAPSHOT=false" >> $GITHUB_OUTPUT
fi
- name: 🐳 Build Docker metadata
id: meta
uses: docker/metadata-action@v5
with:
images: ghcr.io/${{ github.repository }}
tags: |
type=raw,value=${{ steps.get_package_version.outputs.VERSION }}
type=raw,value=latest,enable=${{ steps.check_snapshot.outputs.IS_SNAPSHOT == 'false' }}
- name: 🏗️ Build and push production image
uses: docker/build-push-action@263435318d21b8e681c14492fe198d362a7d2c83 # v6
with:
context: .
file: ./Dockerfile
push: true
tags: ${{ steps.meta.outputs.tags }}
labels: ${{ steps.meta.outputs.labels }}