095607e35b
- 为 `actions/setup-buildx-action` 配置 `driver-opts`。 - 固定 `buildkit` 镜像版本,提升构建环境一致性。
154 lines
4.0 KiB
YAML
154 lines
4.0 KiB
YAML
name: CI and Docker
|
|
|
|
on:
|
|
push:
|
|
branches:
|
|
- main
|
|
- master
|
|
tags:
|
|
- "v*"
|
|
paths-ignore:
|
|
- "**/*.md"
|
|
- "deploy/.env.example"
|
|
pull_request:
|
|
paths-ignore:
|
|
- "**/*.md"
|
|
- "deploy/.env.example"
|
|
workflow_dispatch:
|
|
|
|
permissions:
|
|
contents: read
|
|
packages: write
|
|
|
|
concurrency:
|
|
group: ${{ github.workflow }}-${{ github.ref }}
|
|
cancel-in-progress: true
|
|
|
|
env:
|
|
REGISTRY: ghcr.io
|
|
PLATFORMS: linux/amd64
|
|
|
|
jobs:
|
|
checks:
|
|
name: Check web and api
|
|
runs-on: ubuntu-latest
|
|
steps:
|
|
- name: Checkout
|
|
uses: actions/checkout@v4
|
|
|
|
- name: Setup Node.js
|
|
uses: actions/setup-node@v4
|
|
with:
|
|
node-version: 20
|
|
cache: npm
|
|
cache-dependency-path: apps/web/package-lock.json
|
|
|
|
- name: Install web dependencies
|
|
working-directory: apps/web
|
|
run: npm ci
|
|
|
|
- name: Check shadcn/ui usage
|
|
working-directory: apps/web
|
|
run: npm run check:shadcn
|
|
|
|
- name: Build web
|
|
working-directory: apps/web
|
|
run: npm run build
|
|
|
|
- name: Setup Go
|
|
uses: actions/setup-go@v5
|
|
with:
|
|
go-version-file: apps/api/go.mod
|
|
cache-dependency-path: apps/api/go.sum
|
|
|
|
- name: Test api
|
|
working-directory: apps/api
|
|
run: go test ./...
|
|
|
|
docker:
|
|
name: Build and publish ${{ matrix.name }}
|
|
runs-on: ubuntu-latest
|
|
needs: checks
|
|
if: github.event_name != 'pull_request'
|
|
strategy:
|
|
fail-fast: false
|
|
matrix:
|
|
include:
|
|
- name: all-in-one
|
|
suffix: ""
|
|
context: .
|
|
file: ./deploy/all-in-one/Dockerfile
|
|
- name: api
|
|
suffix: -api
|
|
context: .
|
|
file: ./deploy/api.Dockerfile
|
|
- name: web
|
|
suffix: -web
|
|
context: .
|
|
file: ./deploy/web.Dockerfile
|
|
- name: postfix
|
|
suffix: -postfix
|
|
context: ./deploy/postfix
|
|
file: ./deploy/postfix/Dockerfile
|
|
- name: dovecot
|
|
suffix: -dovecot
|
|
context: ./deploy/dovecot
|
|
file: ./deploy/dovecot/Dockerfile
|
|
- name: rspamd
|
|
suffix: -rspamd
|
|
context: ./deploy/rspamd
|
|
file: ./deploy/rspamd/Dockerfile
|
|
|
|
steps:
|
|
- name: Checkout
|
|
uses: actions/checkout@v4
|
|
|
|
- name: Setup Docker Buildx
|
|
uses: docker/setup-buildx-action@v3
|
|
with:
|
|
driver-opts: |
|
|
image=ghcr.io/moby/buildkit:buildx-stable-1
|
|
|
|
- name: Login to GHCR
|
|
uses: docker/login-action@v3
|
|
with:
|
|
registry: ${{ env.REGISTRY }}
|
|
username: ${{ github.actor }}
|
|
password: ${{ secrets.GITHUB_TOKEN }}
|
|
|
|
- name: Prepare image name
|
|
id: image
|
|
shell: bash
|
|
run: |
|
|
image="${REGISTRY}/${GITHUB_REPOSITORY}${{ matrix.suffix }}"
|
|
echo "name=${image,,}" >> "$GITHUB_OUTPUT"
|
|
|
|
- name: Docker metadata
|
|
id: meta
|
|
uses: docker/metadata-action@v5
|
|
with:
|
|
images: ${{ steps.image.outputs.name }}
|
|
tags: |
|
|
type=raw,value=latest,enable={{is_default_branch}}
|
|
type=ref,event=branch
|
|
type=ref,event=tag
|
|
type=sha,prefix=sha-
|
|
labels: |
|
|
org.opencontainers.image.title=LanQin Email ${{ matrix.name }}
|
|
|
|
- name: Build and push
|
|
uses: docker/build-push-action@v6
|
|
with:
|
|
context: ${{ matrix.context }}
|
|
file: ${{ matrix.file }}
|
|
platforms: ${{ env.PLATFORMS }}
|
|
push: true
|
|
tags: ${{ steps.meta.outputs.tags }}
|
|
labels: ${{ steps.meta.outputs.labels }}
|
|
cache-from: |
|
|
type=gha,scope=lanqin-${{ matrix.name }}
|
|
type=registry,ref=${{ steps.image.outputs.name }}:buildcache
|
|
cache-to: |
|
|
type=gha,mode=max,scope=lanqin-${{ matrix.name }},ignore-error=true
|
|
type=registry,ref=${{ steps.image.outputs.name }}:buildcache,mode=max
|