-
Notifications
You must be signed in to change notification settings - Fork 7k
173 lines (154 loc) · 5.62 KB
/
build-docs.yml
File metadata and controls
173 lines (154 loc) · 5.62 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
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
name: Document deploy
on:
push:
branches:
- main
paths:
- 'document/**'
workflow_dispatch:
permissions:
contents: read
packages: write
attestations: write
id-token: write
pull-requests: write
jobs:
sync-images:
runs-on: ubuntu-latest
steps:
- name: Checkout current repository
uses: actions/checkout@v4
- name: Checkout target repository
uses: actions/checkout@v4
with:
repository: labring/fastgpt-img
token: ${{ secrets.DOCS_IMGS_SYNC_TOKEN }}
path: fastgpt-img
- name: Sync images
run: |
# Create imgs directory if it doesn't exist
mkdir -p fastgpt-img
# Copy all images from document/public/imgs to the target repository
cp -r document/public/imgs/* fastgpt-img
# Navigate to target repository
cd fastgpt-img
# Configure git
git config user.name "github-actions[bot]"
git config user.email "github-actions[bot]@users.noreply.github.com"
# Add, commit and push changes
git add .
if ! git diff --cached --quiet; then
git commit -m "Sync images from FastGPT document at $(date)"
git push
echo "Images synced successfully"
else
echo "No changes to sync"
fi
# Add a new job to generate unified timestamp
generate-timestamp:
needs: sync-images
runs-on: ubuntu-latest
outputs:
datetime: ${{ steps.datetime.outputs.datetime }}
steps:
- name: Get current datetime
id: datetime
run: echo "datetime=$(date +'%Y%m%d%H%M%S')" >> $GITHUB_OUTPUT
build-images:
needs: generate-timestamp
runs-on: ubuntu-latest
strategy:
matrix:
domain_config:
- domain: 'https://fastgpt.io'
suffix: 'io'
- domain: 'https://fastgpt.cn'
suffix: 'cn'
steps:
- name: Checkout
uses: actions/checkout@v4
- name: Rewrite image paths
if: matrix.domain_config.suffix == 'io'
run: |
find document/content/docs -name "*.mdx" -type f | while read file; do
sed -i 's|](/imgs/|](https://cdn.jsdelivr.net/gh/labring/fastgpt-img@main/|g' "$file"
done
- name: Rewrite domain links for CN
if: matrix.domain_config.suffix == 'cn'
run: |
find document/content/docs -name "*.mdx" -type f | while read file; do
sed -i 's|doc\.fastgpt\.io|doc.fastgpt.cn|g' "$file"
done
- name: Docker meta
id: meta
uses: docker/metadata-action@v5
with:
# list of Docker images to use as base name for tags
images: |
${{ secrets.FASTGPT_ALI_IMAGE_PREFIX }}/fastgpt-docs
tags: |
${{ matrix.domain_config.suffix }}-${{ needs.generate-timestamp.outputs.datetime }}
flavor: latest=false
- name: Login to Aliyun
uses: docker/login-action@v3
with:
registry: registry.cn-hangzhou.aliyuncs.com
username: ${{ secrets.FASTGPT_ALI_IMAGE_USER }}
password: ${{ secrets.FASTGPT_ALI_IMAGE_PSW }}
- name: Build and push Docker images (CN)
if: matrix.domain_config.suffix == 'cn'
uses: docker/build-push-action@v5
with:
context: ./document
file: ./document/Dockerfile
push: true
tags: ${{ steps.meta.outputs.tags }}
labels: ${{ steps.meta.outputs.labels }}
platforms: linux/amd64
build-args: |
FASTGPT_HOME_DOMAIN=${{ matrix.domain_config.domain }}
DOC_TRACK_SRC=${{ secrets.DOC_TRACK_SRC }}
DOC_TRACK_SITE_ID=${{ secrets.DOC_TRACK_CN }}
- name: Build and push Docker images (IO)
if: matrix.domain_config.suffix == 'io'
uses: docker/build-push-action@v5
with:
context: ./document
file: ./document/Dockerfile
push: true
tags: ${{ steps.meta.outputs.tags }}
labels: ${{ steps.meta.outputs.labels }}
platforms: linux/amd64
build-args: |
FASTGPT_HOME_DOMAIN=${{ matrix.domain_config.domain }}
DOC_TRACK_SRC=${{ secrets.DOC_TRACK_SRC }}
DOC_TRACK_SITE_ID=${{ secrets.DOC_TRACK_IO }}
update-images:
needs: [generate-timestamp, build-images]
runs-on: ubuntu-24.04
strategy:
matrix:
domain_config:
- domain: 'https://fastgpt.io'
suffix: 'io'
deployment: 'fastgpt-docs'
kube_config: 'KUBE_CONFIG_IO'
- domain: 'https://fastgpt.cn'
suffix: 'cn'
deployment: 'fastgpt-docs'
kube_config: 'KUBE_CONFIG_CN'
steps:
- name: Checkout code
uses: actions/checkout@v4
# Add kubeconfig setup step to handle encoding issues
- name: Setup kubeconfig
run: |
mkdir -p $HOME/.kube
echo "${{ secrets[matrix.domain_config.kube_config] }}" > $HOME/.kube/config
chmod 600 $HOME/.kube/config
- name: Update deployment image
run: |
kubectl set image deployment/${{ matrix.domain_config.deployment }} ${{ matrix.domain_config.deployment }}=${{ secrets.FASTGPT_ALI_IMAGE_PREFIX }}/fastgpt-docs:${{ matrix.domain_config.suffix }}-${{ needs.generate-timestamp.outputs.datetime }}
- name: Annotate deployment
run: |
kubectl annotate deployment/${{ matrix.domain_config.deployment }} originImageName="${{ secrets.FASTGPT_ALI_IMAGE_PREFIX }}/fastgpt-docs:${{ matrix.domain_config.suffix }}-${{ needs.generate-timestamp.outputs.datetime }}" --overwrite