Files
ackify-ce/.github/workflows/build-docker.yml

95 lines
2.6 KiB
YAML

name: Build and Push Docker
on:
workflow_call:
inputs:
push:
description: 'Push image to registry'
required: false
type: boolean
default: true
env:
REGISTRY: docker.io
IMAGE_NAME: btouchard/ackify-ce
jobs:
build:
name: Build Docker Image
runs-on: ubuntu-latest
steps:
- name: Checkout code
uses: actions/checkout@v4
- name: Set up Node.js
uses: actions/setup-node@v4
with:
node-version: '22'
cache: 'npm'
cache-dependency-path: webapp/package-lock.json
- name: Build frontend
run: |
cd webapp
npm ci --no-audit --no-fund --no-progress
npm run build
- name: Copy frontend to backend embed directory
run: |
mkdir -p backend/cmd/community/web/dist
cp -r webapp/dist/* backend/cmd/community/web/dist/
- name: Compute IMAGE_TAG
run: |
# Strip leading 'v' from tag refs; leave branches unchanged
echo "IMAGE_TAG=${GITHUB_REF_NAME#v}" >> "$GITHUB_ENV"
- name: Set up QEMU
uses: docker/setup-qemu-action@v3
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v3
- name: Log in to Docker Hub
if: inputs.push
uses: docker/login-action@v3
with:
registry: ${{ env.REGISTRY }}
username: ${{ secrets.DOCKER_USERNAME }}
password: ${{ secrets.DOCKER_PASSWORD }}
- name: Extract metadata
id: meta
uses: docker/metadata-action@v5
with:
images: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}
tags: |
type=ref,event=branch
type=ref,event=pr
type=semver,pattern={{version}}
type=semver,pattern={{major}}.{{minor}}
type=semver,pattern={{major}}
type=sha,prefix={{branch}}-,enable={{is_default_branch}}
type=sha,enable=false
type=raw,value=latest,enable=${{ github.event_name == 'release' }}
- name: Build and push Docker image
uses: docker/build-push-action@v5
with:
context: .
file: ./Dockerfile
platforms: linux/amd64,linux/arm64
push: ${{ inputs.push }}
provenance: false
tags: |
${{ steps.meta.outputs.tags }}
${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}:${{ env.IMAGE_TAG }}
labels: ${{ steps.meta.outputs.labels }}
cache-from: type=gha
cache-to: type=gha,mode=max
build-args: |
VERSION=${{ github.ref_name }}
COMMIT=${{ github.sha }}
BUILD_DATE=${{ github.event.head_commit.timestamp }}