-
Notifications
You must be signed in to change notification settings - Fork 0
116 lines (103 loc) · 3.92 KB
/
build.yml
File metadata and controls
116 lines (103 loc) · 3.92 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
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
name: Build and Push Docker Images
on:
push:
branches: ["main", "dev"]
paths-ignore:
- "**.md"
- ".gitignore"
- "docker-compose.yml"
- "docker-compose.prod.yml"
- "nginx.prod.conf"
env:
REGISTRY: ghcr.io
IMAGE_API: ${{ github.repository }}/api
IMAGE_WEB: ${{ github.repository }}/web
jobs:
build-and-push:
runs-on: ubuntu-latest
permissions:
contents: read
packages: write
steps:
- name: Checkout repository
uses: actions/checkout@v6
- 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 }}
# ── API ──────────────────────────────────────────────────────────────────
- name: Extract metadata for API image
id: meta-api
uses: docker/metadata-action@v6
with:
images: ${{ env.REGISTRY }}/${{ env.IMAGE_API }}
tags: |
type=ref,event=branch
type=sha,prefix={{branch}}-,format=short
- name: Build and push API image
uses: docker/build-push-action@v7
with:
context: ./apps/api
push: true
tags: ${{ steps.meta-api.outputs.tags }}
labels: ${{ steps.meta-api.outputs.labels }}
cache-from: type=gha,scope=api
cache-to: type=gha,mode=max,scope=api
# ── Web ──────────────────────────────────────────────────────────────────
- name: Extract metadata for Web image
id: meta-web
uses: docker/metadata-action@v6
with:
images: ${{ env.REGISTRY }}/${{ env.IMAGE_WEB }}
tags: |
type=ref,event=branch
type=sha,prefix={{branch}}-,format=short
- name: Build and push Web image
uses: docker/build-push-action@v7
with:
context: .
file: apps/web/Dockerfile
push: true
tags: ${{ steps.meta-web.outputs.tags }}
labels: ${{ steps.meta-web.outputs.labels }}
# NEXT_PUBLIC_API_BASE_URL 在运行时由环境变量注入,构建时留空即可
build-args: |
NEXT_PUBLIC_API_BASE_URL=
cache-from: type=gha,scope=web
cache-to: type=gha,mode=max,scope=web
# ── Deploy(按需取消注释)──────────────────────────────────────────────────
#
# deploy:
# needs: build-and-push
# runs-on: ubuntu-latest
# if: github.ref == 'refs/heads/main'
#
# steps:
# - name: Checkout repository
# uses: actions/checkout@v6
#
# - name: Copy docker-compose.prod.yml to server
# uses: appleboy/scp-action@v0.1.7
# with:
# host: ${{ secrets.DEPLOY_HOST }}
# username: ${{ secrets.DEPLOY_USER }}
# key: ${{ secrets.DEPLOY_KEY }}
# source: "docker-compose.prod.yml,nginx.prod.conf"
# target: "/opt/lyranote"
#
# - name: Deploy via SSH
# uses: appleboy/ssh-action@v1.0.3
# with:
# host: ${{ secrets.DEPLOY_HOST }}
# username: ${{ secrets.DEPLOY_USER }}
# key: ${{ secrets.DEPLOY_KEY }}
# script: |
# cd /opt/lyranote
# echo "${{ secrets.GITHUB_TOKEN }}" | docker login ghcr.io -u ${{ github.actor }} --password-stdin
# docker compose -f docker-compose.prod.yml pull
# docker compose -f docker-compose.prod.yml up -d
# docker image prune -f