Skip to content

Docker Build and Publish #12

Docker Build and Publish

Docker Build and Publish #12

name: Docker Build and Publish
permissions:
packages: write
contents: read
on:
workflow_run:
workflows: ["Build and Release"]
types:
- completed
branches:
- main
workflow_dispatch:
push:
paths:
- "Dockerfile"
- "package.json"
- ".dockerignore"
- "entrypoint.sh"
branches:
- main
jobs:
docker:
if: ${{ github.event.workflow_run.conclusion == 'success' || github.event_name == 'workflow_dispatch' || github.event_name == 'push' }}
runs-on: ubuntu-latest
steps:
- name: Checkout repository
uses: actions/checkout@v4
- name: Generate lowercase repository name
id: repo-name
shell: bash
run: |
echo "REPO_NAME=$(echo ${{ github.repository }} | tr '[:upper:]' '[:lower:]')" >> $GITHUB_OUTPUT
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v3
- name: Log in to GitHub Container Registry
uses: docker/login-action@v3
with:
registry: ghcr.io
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}
- name: Extract metadata for Docker
id: meta
uses: docker/metadata-action@v5
with:
images: ghcr.io/${{ steps.repo-name.outputs.REPO_NAME }}
tags: |
type=ref,event=branch
type=ref,event=pr
type=semver,pattern={{version}}
type=semver,pattern={{major}}.{{minor}}
type=sha
type=raw,value=latest,enable={{is_default_branch}}
- name: Build and push Docker image
uses: docker/build-push-action@v5
with:
context: .
push: true
tags: ${{ steps.meta.outputs.tags }}
labels: ${{ steps.meta.outputs.labels }}
cache-from: |
type=registry,ref=ghcr.io/${{ steps.repo-name.outputs.REPO_NAME }}:buildcache
type=gha
cache-to: |
type=registry,ref=ghcr.io/${{ steps.repo-name.outputs.REPO_NAME }}:buildcache,mode=max
type=gha,mode=max
build-args: |
NODE_ENV=production
VERSION=${{ github.ref_name }}