-
-
Notifications
You must be signed in to change notification settings - Fork 117
140 lines (135 loc) · 4.98 KB
/
api-release.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
name: "Release Version Management"
on:
push:
tags:
- releases-v1*
jobs:
envs:
name: envs
steps:
##################################################################################################################
# Git checkout
- name: Checkout repository
uses: actions/checkout@v3
# The github.ref is, for example, refs/tags/v5.0.145 or refs/tags/v5.0-r8
# Generate variables like:
# SRS_TAG=nodejs-v1.0.52
# SRS_MAJOR=nodejs-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| awk -F '.' '{print $1}' |sed 's/-v/-/g')
echo "SRS_MAJOR=$SRS_MAJOR" >> $GITHUB_ENV
# Map a step output to a job output, see https://docs.github.com/en/actions/using-jobs/defining-outputs-for-jobs
outputs:
SRS_TAG: ${{ env.SRS_TAG }}
SRS_MAJOR: ${{ env.SRS_MAJOR }}
runs-on: ubuntu-20.04
docker:
needs:
- envs
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
# Git checkout
- name: Checkout repository
uses: actions/checkout@v3
# Build SRS image
- name: Build SRS docker image
run: |
echo "Release ossrs/oryx:$SRS_TAG"
docker build --tag ossrs/oryx:$SRS_TAG -f releases/Dockerfile .
# Create main images for Docker
- name: Login to docker hub
uses: docker/login-action@v2
with:
username: "${{ secrets.DOCKER_USERNAME }}"
password: "${{ secrets.DOCKER_PASSWORD }}"
- name: Push to Docker hub
run: |
docker tag ossrs/oryx:$SRS_TAG ossrs/oryx:$SRS_MAJOR
docker push --all-tags ossrs/oryx
runs-on: ubuntu-20.04
aliyun:
needs:
- envs
- docker
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
# Aliyun ACR
- name: Login Aliyun docker hub
uses: docker/login-action@v2
with:
registry: registry.cn-hangzhou.aliyuncs.com
username: "${{ secrets.ACR_USERNAME }}"
password: "${{ secrets.ACR_PASSWORD }}"
- name: Docker alias images for ossrs/oryx
uses: akhilerm/[email protected]
with:
src: ossrs/oryx:${{ env.SRS_TAG }}
dst: |
registry.cn-hangzhou.aliyuncs.com/ossrs/oryx:${{ env.SRS_TAG }}
registry.cn-hangzhou.aliyuncs.com/ossrs/oryx:${{ env.SRS_MAJOR }}
runs-on: ubuntu-20.04
deploy:
needs:
- envs
- aliyun
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
# Git checkout
- name: Checkout repository
uses: actions/checkout@v3
# Generate variables like:
# SRS_DROPLET_EIP=1.2.3.4
- name: Build droplet variables
run: |
SRS_DROPLET_EIP=$(dig +short lh.ossrs.net)
echo "SRS_DROPLET_EIP=$SRS_DROPLET_EIP" >> $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
timeout: 60s
command_timeout: 30m
script: |
#
ufw allow 8101
#
export SRS_DROPLET_PIP=$(ifconfig eth0 |grep 'inet ' |awk '{print $2}')
echo "SRS_DROPLET_PIP=$SRS_DROPLET_PIP"
#
# Restart Oryx release
cat << END > /root/restart_docs-stack.sh
# See https://github.com/ossrs/oryx
docker pull registry.cn-hangzhou.aliyuncs.com/ossrs/oryx:$SRS_MAJOR
docker rm -f docs-cloudversion || sleep 1
docker run -d -it --restart always --privileged --name docs-cloudversion -p 8101:9000 \\
--log-driver=json-file --log-opt=max-size=500m --log-opt=max-file=3 \\
registry.cn-hangzhou.aliyuncs.com/ossrs/oryx:$SRS_MAJOR
END
bash /root/restart_docs-stack.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
runs-on: ubuntu-20.04