-
Notifications
You must be signed in to change notification settings - Fork 0
91 lines (81 loc) · 2.98 KB
/
Copy pathcd.yml
File metadata and controls
91 lines (81 loc) · 2.98 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
name: CD
on:
push:
branches: [main]
tags: ['v*']
env:
REGISTRY: ghcr.io
# GHCR 要求镜像名全小写;github.repository_owner 保留原始大小写,
# 由 lowercase-owner job 通过 tr 转换后输出给后续 job 使用。
jobs:
lowercase-owner:
name: Normalize image owner
runs-on: ubuntu-latest
outputs:
owner: ${{ steps.norm.outputs.owner }}
steps:
- name: Lowercase owner
id: norm
run: echo "owner=$(echo "${{ github.repository_owner }}" | tr '[:upper:]' '[:lower:]')" >> "$GITHUB_OUTPUT"
shell: bash
build-and-push:
name: Build and Push Images
runs-on: ubuntu-latest
needs: lowercase-owner
permissions:
contents: read
packages: write
steps:
- name: Checkout
uses: actions/checkout@v4
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v3
- name: Log in to GitHub Container Registry
uses: docker/login-action@v3
with:
registry: ${{ env.REGISTRY }}
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}
- name: Extract metadata
id: meta
uses: docker/metadata-action@v5
with:
images: |
ghcr.io/${{ needs.lowercase-owner.outputs.owner }}/betterwrite-web
ghcr.io/${{ needs.lowercase-owner.outputs.owner }}/betterwrite-worker
ghcr.io/${{ needs.lowercase-owner.outputs.owner }}/betterwrite-migrate
tags: |
type=ref,event=branch
type=semver,pattern={{version}}
type=semver,pattern={{major}}.{{minor}}
type=sha,prefix=,suffix=,format=short
- name: Build and push web image
uses: docker/build-push-action@v6
with:
context: .
file: ./docker/Dockerfile.web
push: true
tags: ghcr.io/${{ needs.lowercase-owner.outputs.owner }}/betterwrite-web:${{ github.ref_name == 'main' && 'latest' || github.ref_name }}
labels: ${{ steps.meta.outputs.labels }}
cache-from: type=gha
cache-to: type=gha,mode=max
- name: Build and push worker image
uses: docker/build-push-action@v6
with:
context: .
file: ./docker/Dockerfile.worker
push: true
tags: ghcr.io/${{ needs.lowercase-owner.outputs.owner }}/betterwrite-worker:${{ github.ref_name == 'main' && 'latest' || github.ref_name }}
labels: ${{ steps.meta.outputs.labels }}
cache-from: type=gha
cache-to: type=gha,mode=max
- name: Build and push migrate image
uses: docker/build-push-action@v6
with:
context: .
file: ./docker/Dockerfile.migrate
push: true
tags: ghcr.io/${{ needs.lowercase-owner.outputs.owner }}/betterwrite-migrate:${{ github.ref_name == 'main' && 'latest' || github.ref_name }}
labels: ${{ steps.meta.outputs.labels }}
cache-from: type=gha
cache-to: type=gha,mode=max