Manual Docker Build #41
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
name: Manual Docker Build | |
on: | |
workflow_dispatch: | |
inputs: | |
version: | |
description: 'Version to tag the images (e.g., 1.0.0-beta.1, test-branch)' | |
required: true | |
type: string | |
latest: | |
description: 'Also tag as latest (use with caution)' | |
required: false | |
type: boolean | |
default: false | |
no_cache: | |
description: 'Force rebuild without using cache' | |
required: false | |
type: boolean | |
default: false | |
env: | |
REGISTRY: ghcr.io | |
IMAGE_NAME: ${{ github.repository }} | |
jobs: | |
build-and-push-image: | |
runs-on: ubuntu-24.04 | |
strategy: | |
fail-fast: false | |
matrix: | |
include: | |
- dockerfile: ./apps/web/Dockerfile | |
image: ghcr.io/${{ github.repository_owner }}/web | |
- dockerfile: ./apps/api/Dockerfile | |
image: ghcr.io/${{ github.repository_owner }}/api | |
permissions: | |
contents: read | |
packages: write | |
steps: | |
- name: Checkout repository | |
uses: actions/checkout@v4 | |
- name: Set up QEMU | |
uses: docker/setup-qemu-action@v3 | |
- name: Set up Docker Buildx | |
uses: docker/setup-buildx-action@v3 | |
- name: Clean up old cache entries | |
if: ${{ !inputs.no_cache }} | |
run: | | |
# Clean up GitHub Actions cache entries older than 7 days | |
gh api repos/${{ github.repository }}/actions/caches --paginate \ | |
--jq '.actions_caches[] | select(.created_at < (now - (7 * 24 * 3600)) | strftime("%Y-%m-%dT%H:%M:%SZ")) | .id' \ | |
| xargs -I {} gh api --method DELETE repos/${{ github.repository }}/actions/caches/{} || true | |
env: | |
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }} | |
- name: Log in to GitHub Container Registry | |
uses: docker/login-action@v3 | |
with: | |
registry: ${{ env.REGISTRY }} | |
username: ${{ github.actor }} | |
password: ${{ secrets.GH_PACKAGE_TOKEN }} | |
- name: Extract metadata | |
id: meta | |
uses: docker/metadata-action@v5 | |
with: | |
images: ${{ matrix.image }} | |
tags: | | |
type=raw,value=${{ inputs.version }} | |
type=raw,value=latest,enable=${{ inputs.latest }} | |
- name: Build and push | |
uses: docker/build-push-action@v5 | |
with: | |
context: . | |
file: ${{ matrix.dockerfile }} | |
platforms: linux/amd64,linux/arm64 | |
push: true | |
tags: ${{ steps.meta.outputs.tags }} | |
labels: ${{ steps.meta.outputs.labels }} | |
no-cache: ${{ inputs.no_cache }} | |
cache-from: | | |
type=gha,scope=${{ matrix.dockerfile }} | |
type=registry,ref=${{ matrix.image }}:buildcache | |
cache-to: | | |
type=gha,mode=max,scope=${{ matrix.dockerfile }} | |
type=registry,ref=${{ matrix.image }}:buildcache,mode=max |