Files
forumlify/.github/workflows/docker-ghcr.yml
T
lezi-fun cc90c93673 ci: multi-arch images — linux/amd64 + linux/arm64 + windows/amd64
- Linux: build-push-action platforms linux/amd64,linux/arm64
- Windows: separate job on windows-latest (switch to Windows container
  engine, native docker build with Dockerfile.windows) → :next-windows
- Dockerfile.windows: node:20-windowsservercore-ltsc2022, bun install,
  standalone output
2026-08-11 18:59:22 +08:00

89 lines
2.4 KiB
YAML
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
name: Build & Push Docker to GHCR
on:
push:
branches: [next, main]
tags: ['v*']
workflow_dispatch:
env:
REGISTRY: ghcr.io
IMAGE_NAME: ${{ github.repository }}
jobs:
build:
runs-on: ubuntu-latest
permissions:
contents: read
packages: write
steps:
- name: Checkout
uses: actions/checkout@v4
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v3
- name: Login to GHCR
uses: docker/login-action@v3
with:
registry: ${{ env.REGISTRY }}
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}
- name: Extract metadata (tags, labels)
id: meta
uses: docker/metadata-action@v5
with:
images: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}
tags: |
type=ref,event=branch
type=semver,pattern={{version}}
type=semver,pattern={{major}}.{{minor}}
type=sha,prefix=git-
- name: Build and push (linux/amd64 + linux/arm64)
uses: docker/build-push-action@v6
with:
context: .
push: true
platforms: linux/amd64, linux/arm64
tags: ${{ steps.meta.outputs.tags }}
labels: ${{ steps.meta.outputs.labels }}
cache-from: type=gha
cache-to: type=gha,mode=max
# Windows 容器镜像(windowsservercore):需要在 Windows runner 上
# 切换 Windows 容器引擎后原生 docker build(buildx 不支持交叉构建 Windows 容器)
windows:
runs-on: windows-latest
permissions:
contents: read
packages: write
steps:
- name: Checkout
uses: actions/checkout@v4
- name: Login to GHCR
uses: docker/login-action@v3
with:
registry: ${{ env.REGISTRY }}
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}
- name: Switch Docker to Windows containers
shell: pwsh
run: |
& "$env:ProgramFiles\Docker\Docker\DockerCli.exe" -SwitchWindowsEngine
- name: Build Windows image
shell: pwsh
run: |
docker build -f Dockerfile.windows -t ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}:next-windows .
- name: Push Windows image
shell: pwsh
run: |
docker push ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}:next-windows