Files
funnywolf b6b4cbf017 0.4.0 I always have a choice
You shape nothing until you hold everything.
2026-06-27 19:08:48 +08:00

79 lines
2.0 KiB
YAML

name: Docker images
on:
workflow_call:
inputs:
version:
required: true
type: string
push:
required: false
type: boolean
default: true
workflow_dispatch:
inputs:
version:
description: Image tag to build.
required: true
default: dev
push:
description: Push images to GHCR.
required: true
type: boolean
default: false
permissions:
contents: read
packages: write
jobs:
build:
name: Build ${{ matrix.name }}
runs-on: ubuntu-latest
strategy:
fail-fast: false
matrix:
include:
- name: backend
image: asp-backend
context: ./backend
file: ./backend/Dockerfile
- name: frontend
image: asp-frontend
context: ./frontend
file: ./frontend/Dockerfile
steps:
- uses: actions/checkout@v4
- uses: docker/setup-buildx-action@v3
- name: Resolve image tags
id: tags
shell: bash
run: |
owner="${GITHUB_REPOSITORY_OWNER,,}"
repo="${GITHUB_REPOSITORY#*/}"
repo="${repo,,}"
base="ghcr.io/${owner}/${repo}/${{ matrix.image }}"
{
echo "tags<<EOF"
echo "${base}:${{ inputs.version }}"
if [ "${{ inputs.version }}" != "dev" ]; then
echo "${base}:latest"
fi
echo "EOF"
} >> "$GITHUB_OUTPUT"
- name: Login to GHCR
if: inputs.push
uses: docker/login-action@v3
with:
registry: ghcr.io
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}
- uses: docker/build-push-action@v6
with:
context: ${{ matrix.context }}
file: ${{ matrix.file }}
push: ${{ inputs.push }}
tags: ${{ steps.tags.outputs.tags }}
cache-from: type=gha
cache-to: type=gha,mode=max