Refine script. #74
Workflow file for this run
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
name: "Release ossrs.net and api.ossrs.net" | |
on: | |
push: | |
tags: | |
- v1* | |
jobs: | |
k8s: | |
name: release-k8s | |
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 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/web:$SRS_TAG" | |
docker build --tag ossrs/web:$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/web:$SRS_TAG registry.cn-hangzhou.aliyuncs.com/ossrs/web:$SRS_TAG | |
docker tag ossrs/web:$SRS_TAG registry.cn-hangzhou.aliyuncs.com/ossrs/web:$SRS_MAJOR | |
docker push --all-tags registry.cn-hangzhou.aliyuncs.com/ossrs/web | |
################################################################ | |
# 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 20081 # For HTTPX proxy. | |
ufw allow 8100 # For ossrs.net static files. | |
# | |
#ufw allow 8101 # For srs-cloud version service. | |
#ufw allow 8102 # For srs server version service. | |
#ufw allow 1989 # For SRS demo signaling service. | |
#ufw allow 1987 # For hgsw SLS log proxy service. | |
# | |
export SRS_DROPLET_PIP=$(ifconfig eth0 |grep 'inet ' |awk '{print $2}') | |
echo "SRS_DROPLET_PIP=$SRS_DROPLET_PIP" | |
# | |
# Restart HTTPX | |
cat << END > /root/restart_docs-proxy.sh | |
# See https://github.com/ossrs/ossrs.net | |
docker pull registry.cn-hangzhou.aliyuncs.com/ossrs/httpx:1 | |
docker rm -f docs-proxy || sleep 1 | |
docker run -d -it --restart always \\ | |
--name docs-proxy -p 20081:80 \\ | |
--log-driver=json-file --log-opt=max-size=500m --log-opt=max-file=3 \\ | |
registry.cn-hangzhou.aliyuncs.com/ossrs/httpx:1 \\ | |
./bin/httpx-static -http 80 \\ | |
-proxy http://$SRS_DROPLET_PIP:1989/sig/ \\ | |
-proxy http://$SRS_DROPLET_PIP:1987/gif/ \\ | |
-proxy http://$SRS_DROPLET_PIP:8102/service/v1/?modifyRequestHost=true \\ | |
-pre-hook http://$SRS_DROPLET_PIP:1987/service/v1/?_sys_logstore=srs-eggs\&_sys_logfmt_app=true\&_sys_keep_ua=false\&_sys_keep_referer=false\&_sys_keep_oreferer=false\&_sys_keep_oua=false\&_sys_keep_fwd=false \\ | |
-proxy http://$SRS_DROPLET_PIP:8101/terraform/v1/?modifyRequestHost=true \\ | |
-pre-hook http://$SRS_DROPLET_PIP:1987/terraform/v1/?_sys_logstore=cloud-eggs\&_sys_logfmt_app=true\&_sys_keep_ua=false\&_sys_keep_referer=false\&_sys_keep_oreferer=false\&_sys_keep_oua=false\&_sys_keep_fwd=false \\ | |
-proxy http://$SRS_DROPLET_PIP:8100/ | |
END | |
bash /root/restart_docs-proxy.sh | |
# | |
# Restart static files | |
cat << END > /root/restart_docs-statics.sh | |
# See https://github.com/ossrs/ossrs.net | |
docker pull registry.cn-hangzhou.aliyuncs.com/ossrs/web:$SRS_MAJOR | |
docker rm -f docs-statics || sleep 1 | |
docker run -d -it --restart always --name docs-statics -p 8100:80 \\ | |
--log-driver=json-file --log-opt=max-size=500m --log-opt=max-file=3 \\ | |
registry.cn-hangzhou.aliyuncs.com/ossrs/web:$SRS_MAJOR | |
END | |
bash /root/restart_docs-statics.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 |