-
Notifications
You must be signed in to change notification settings - Fork 12
89 lines (81 loc) · 3.23 KB
/
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
name: "Release SRS demo signaling"
on:
push:
tags:
- v1*
jobs:
docker:
name: release-docker
runs-on: ubuntu-20.04
steps:
################################################################
# Git checkout
- name: Checkout repository
uses: actions/checkout@v2
# 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
################################################################
# Build
# 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
# Build SRS image
- name: Build SRS docker image
run: |
echo "Release ossrs/signaling:$SRS_TAG"
docker build --tag ossrs/signaling:$SRS_TAG .
################################################################
# Aliyun ACR
- name: Login Aliyun docker hub
uses: aliyun/acr-login@v1
with:
login-server: https://registry.cn-hangzhou.aliyuncs.com
username: "${{ secrets.ACR_USERNAME }}"
password: "${{ secrets.ACR_PASSWORD }}"
- name: Push to Aliyun docker hub
run: |
docker tag ossrs/signaling:$SRS_TAG registry.cn-hangzhou.aliyuncs.com/ossrs/signaling:$SRS_TAG
docker tag ossrs/signaling:$SRS_TAG registry.cn-hangzhou.aliyuncs.com/ossrs/signaling:$SRS_MAJOR
docker push --all-tags registry.cn-hangzhou.aliyuncs.com/ossrs/signaling
################################################################
# Execute command in a ssh, because ufw limit the rate.
- name: Restart the containers
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 1989 # For SRS demo signaling service.
#
# Restart SRS signaling service
cat << END > /root/restart_docs-signaling.sh
docker pull registry.cn-hangzhou.aliyuncs.com/ossrs/signaling:$SRS_MAJOR
docker rm -f docs-signaling || sleep 1
docker run -d -it --restart always --name docs-signaling -p 1989:1989 \
registry.cn-hangzhou.aliyuncs.com/ossrs/signaling:$SRS_MAJOR
END
bash /root/restart_docs-signaling.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