-
Notifications
You must be signed in to change notification settings - Fork 39
281 lines (273 loc) · 10.2 KB
/
release-en.yml
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
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
name: "Release EN version"
on:
push:
tags:
- v1*
jobs:
envs:
name: envs
runs-on: ubuntu-20.04
steps:
# Git checkout
- name: Checkout repository
uses: actions/checkout@v2
# DigitalOcean droplet
- name: Install doctl
uses: digitalocean/action-doctl@v2
with:
token: ${{ secrets.DIGITALOCEAN_ACCESS_TOKEN }}
# Generate variables like:
# SRS_DROPLET_EIP=1.2.3.4
# SRS_DROPLET_PIP=1.2.3.4
- name: Build droplet variables
run: |
doctl compute droplet list --format Name,Region,Status,VCPUs,Memory
SRS_DROPLET_EIP=$(doctl compute droplet get ossrs --format PublicIPv4 --no-header)
SRS_DROPLET_PIP=$(doctl compute droplet get ossrs --format PrivateIPv4 --no-header)
echo "SRS_DROPLET_EIP=$SRS_DROPLET_EIP" >> $GITHUB_ENV
echo "SRS_DROPLET_PIP=$SRS_DROPLET_PIP" >> $GITHUB_ENV
# The github.ref is, for example, refs/tags/v1.0.52
# Generate variables like:
# SRS_TAG=v1.0.52
# SRS_MAJOR=1
# @see https://docs.github.com/en/actions/reference/workflow-commands-for-github-actions#setting-an-environment-variable
- name: Generate varaiables
run: |
SRS_TAG=$(echo ${{ github.ref }}| awk -F '/' '{print $3}')
echo "SRS_TAG=$SRS_TAG" >> $GITHUB_ENV
SRS_MAJOR=$(echo $SRS_TAG| cut -c 2)
echo "SRS_MAJOR=$SRS_MAJOR" >> $GITHUB_ENV
outputs:
SRS_DROPLET_EIP: ${{ env.SRS_DROPLET_EIP }}
SRS_DROPLET_PIP: ${{ env.SRS_DROPLET_PIP }}
SRS_TAG: ${{ env.SRS_TAG }}
SRS_MAJOR: ${{ env.SRS_MAJOR }}
files:
name: files
runs-on: ubuntu-20.04
needs:
- envs
steps:
- name: Covert output to env
run: |
echo "SRS_DROPLET_EIP=${{ needs.envs.outputs.SRS_DROPLET_EIP }}" >> $GITHUB_ENV
# Git checkout
- name: Checkout repository
uses: actions/checkout@v2
# Run scp first, because ufw limit the rate.
- name: Prepare the droplet
uses: appleboy/ssh-action@master
with:
host: ${{ env.SRS_DROPLET_EIP }}
username: root
key: ${{ secrets.DIGITALOCEAN_SSHKEY }}
port: 22
script: |
mkdir -p /root/search
# Run scp first, because ufw limit the rate.
- name: Copy the files to droplet
uses: appleboy/scp-action@master
with:
host: ${{ env.SRS_DROPLET_EIP }}
username: root
key: ${{ secrets.DIGITALOCEAN_SSHKEY }}
source: "search/scraper.json"
target: "/root/search/"
strip_components: 1
docker0:
name: docker0
runs-on: ubuntu-20.04
needs:
- envs
steps:
- name: Checkout repository
uses: actions/checkout@v2
- name: Build SRS docker image
run: |
echo "Build build/zh-cn"
docker run --rm -v $(pwd):/git -w /git -e SEARCH_APIKEY=${{ secrets.SEARCH_APIKEY }} \
ossrs/docs:docs-cache bash auto/build-en-stage0.sh
- uses: actions/upload-artifact@v2
with:
name: zh-cn
path: build/zh-cn.tar.bz2
docker1:
name: docker1
runs-on: ubuntu-20.04
needs:
- envs
steps:
- name: Checkout repository
uses: actions/checkout@v2
- name: Build SRS docker image
run: |
echo "Build build/en-us"
docker run --rm -v $(pwd):/git -w /git -e SEARCH_APIKEY=${{ secrets.SEARCH_APIKEY }} \
ossrs/docs:docs-cache bash auto/build-en-stage1.sh
- uses: actions/upload-artifact@v2
with:
name: en-us
path: build/en-us.tar.bz2
docker:
name: docker
runs-on: ubuntu-20.04
needs:
- envs
- docker0
- docker1
steps:
- name: Covert output to env
run: |
echo "SRS_TAG=${{ needs.envs.outputs.SRS_TAG }}" >> $GITHUB_ENV
echo "SRS_MAJOR=${{ needs.envs.outputs.SRS_MAJOR }}" >> $GITHUB_ENV
- name: Checkout repository
uses: actions/checkout@v2
- uses: actions/download-artifact@v2
with:
name: zh-cn
path: build
- uses: actions/download-artifact@v2
with:
name: en-us
path: build
- name: Login docker hub
uses: docker/login-action@v1
with:
username: "${{ secrets.DOCKER_USERNAME }}"
password: "${{ secrets.DOCKER_PASSWORD }}"
- name: Push to docker hub
run: |
echo "Release ossrs/docs:en-$SRS_TAG"
docker build --tag ossrs/docs:en-$SRS_TAG -f Dockerfile.en.dist .
docker tag ossrs/docs:en-$SRS_TAG ossrs/docs:en-$SRS_MAJOR
docker push --all-tags ossrs/docs
aliyun:
name: aliyun-hub
runs-on: ubuntu-20.04
needs:
- envs
- docker0
- docker1
steps:
- name: Covert output to env
run: |
echo "SRS_TAG=${{ needs.envs.outputs.SRS_TAG }}" >> $GITHUB_ENV
echo "SRS_MAJOR=${{ needs.envs.outputs.SRS_MAJOR }}" >> $GITHUB_ENV
- name: Checkout repository
uses: actions/checkout@v2
- uses: actions/download-artifact@v2
with:
name: zh-cn
path: build
- uses: actions/download-artifact@v2
with:
name: en-us
path: build
- name: Login docker hub
uses: docker/login-action@v1
with:
registry: registry.cn-hangzhou.aliyuncs.com
username: "${{ secrets.ACR_USERNAME }}"
password: "${{ secrets.ACR_PASSWORD }}"
- name: Push to aliyun hub
run: |
echo "Release registry.cn-hangzhou.aliyuncs.com/ossrs/docs:en-$SRS_TAG"
docker build --tag ossrs/docs:en-$SRS_TAG -f Dockerfile.en.dist .
docker tag ossrs/docs:en-$SRS_TAG registry.cn-hangzhou.aliyuncs.com/ossrs/docs:en-$SRS_TAG
docker tag ossrs/docs:en-$SRS_TAG registry.cn-hangzhou.aliyuncs.com/ossrs/docs:en-$SRS_MAJOR
docker push --all-tags registry.cn-hangzhou.aliyuncs.com/ossrs/docs
deploy:
name: deploy
runs-on: ubuntu-20.04
needs:
- envs
- docker
- files
steps:
- name: Covert output to env
run: |
echo "SRS_TAG=${{ needs.envs.outputs.SRS_TAG }}" >> $GITHUB_ENV
echo "SRS_MAJOR=${{ needs.envs.outputs.SRS_MAJOR }}" >> $GITHUB_ENV
echo "SRS_DROPLET_EIP=${{ needs.envs.outputs.SRS_DROPLET_EIP }}" >> $GITHUB_ENV
echo "SRS_DROPLET_PIP=${{ needs.envs.outputs.SRS_DROPLET_PIP }}" >> $GITHUB_ENV
# Execute command in a ssh, because ufw limit the rate.
- name: Restart the containers
env:
SEARCH_APIKEY: ${{ secrets.SEARCH_APIKEY }}
uses: appleboy/ssh-action@master
with:
host: ${{ env.SRS_DROPLET_EIP }}
username: root
key: ${{ secrets.DIGITALOCEAN_SSHKEY }}
port: 22
envs: SRS_TAG,SRS_MAJOR,SEARCH_APIKEY,SRS_DROPLET_PIP
script: |
#
ufw allow 20080
ufw allow 8107
ufw allow 8108
#
# Restart HTTPX
cat << END > /root/restart_docs-httpx.sh
for ((i=0; i < 5; i++)); do
if [[ $(docker ps -f name=docs-httpx |wc -l) -eq 1 ]]; then echo "Killed"; break; fi;
docker rm -f docs-httpx; sleep 0.3;
done
docker run -d -it --restart always \
--name docs-httpx -p 20080:80 ossrs/httpx:1 \
./bin/httpx-static -http 80 \
-proxy http://$SRS_DROPLET_PIP:8107/lts/ \
-proxy http://$SRS_DROPLET_PIP:8108/multi_search
END
bash /root/restart_docs-httpx.sh
#
# Restart SRS docs
cat << END > /root/restart_docs-docs.sh
for ((i=0; i < 5; i++)); do
if [[ $(docker ps -f name=docs-docs |wc -l) -eq 1 ]]; then echo "Killed"; break; fi;
docker rm -f docs-docs; sleep 0.3;
done
docker pull ossrs/docs:en-$SRS_MAJOR
docker run -d -it --restart always --privileged --name docs-docs -p 8107:80 ossrs/docs:en-$SRS_MAJOR
END
bash /root/restart_docs-docs.sh
#
# Use 8107/tcp as port.
sed -i 's/host.docker.internal:3000/host.docker.internal:8107/g' /root/search/scraper.json
#
# Restart typesense
cat << END > /root/restart_docs-typesense.sh
for ((i=0; i < 5; i++)); do
if [[ $(docker ps -f name=docs-typesense |wc -l) -eq 1 ]]; then echo "Killed"; break; fi;
docker rm -f docs-typesense; sleep 0.3;
done
docker run -d -it --restart always --privileged --name docs-typesense -v /root/search/data:/data -p $SRS_DROPLET_PIP:8108:8108 \
typesense/typesense:0.22.1 --enable-cors --data-dir /data --api-key=$SEARCH_APIKEY
END
bash /root/restart_docs-typesense.sh
#
# Restart search scraper
cat << END > /root/restart_docs-search-scraper.sh
for ((i=0; i < 5; i++)); do
if [[ $(docker ps -f name=docs-search-scraper |wc -l) -eq 1 ]]; then echo "Killed"; break; fi;
docker rm -f docs-search-scraper; sleep 0.3;
done
# Replace the BASE_URL
sed -i 's|.*url.*host.docker.internal:8107.*| "url": "http://host.docker.internal:8107/",|g' /root/search/scraper.json
docker run --rm --privileged --name docs-search-scraper --add-host host.docker.internal:$SRS_DROPLET_PIP -e UPDATE_NB_HITS=0 \
-e TYPESENSE_HOST=host.docker.internal -e TYPESENSE_API_KEY=$SEARCH_APIKEY -e TYPESENSE_PORT=8108 \
-e TYPESENSE_PROTOCOL=http -v /root/search/scraper.json:/config.json -e CONFIG=/config.json \
typesense/docsearch-scraper
END
bash /root/restart_docs-search-scraper.sh
#
# Cleanup old docker images.
for image in $(docker images |grep '<none>' |awk '{print $3}'); do
docker rmi -f $image
echo "Remove image $image, r0=$?"
done
- uses: geekyeggo/delete-artifact@v1
with:
name: |
en-us
zh-cn