Initial commit #1
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: Deploy SRS to K8s | |
on: | |
push: | |
branches: | |
- main | |
# See https://docs.github.com/en/actions/managing-workflow-runs/manually-running-a-workflow | |
workflow_dispatch: | |
jobs: | |
k8s: | |
name: release-k8s | |
runs-on: ubuntu-20.04 | |
if: github.event.repository.name != 'srs-k8s-template' | |
steps: | |
- name: Check secrets.KUBECONFIG | |
env: | |
KUBECONFIG: ${{ secrets.KUBECONFIG }} | |
run: | | |
if [[ $KUBECONFIG == '' ]]; then | |
echo 'Please set the KUBECONFIG at Settings/Secrets' | |
exit 1 | |
fi | |
- name: Checkout | |
uses: actions/checkout@v2 | |
- name: Set K8s context | |
uses: ossrs/k8s-set-context-action@v1 | |
with: | |
kubeconfig: '${{ secrets.KUBECONFIG }}' | |
- name: Deploy SRS | |
run: | | |
# Deploy the Docker image to the K8s cluster | |
kubectl apply -f srs.yaml | |
# (Optional) Set env SRS_EIP | |
# SRS_EIP 81.70.125.89 | |
- name: Get EIP of SRS | |
run: | | |
# Show the website if ready | |
for ((i=0; i<30; i++)); do | |
EIP=$(kubectl get svc/srs-service |grep srs-service |awk '{print $4}') | |
if [[ $EIP != '<pending>' ]]; then | |
# Export as SRS_EIP | |
echo "SRS_EIP=$EIP" >> $GITHUB_ENV | |
echo "" | |
echo "Website:" | |
echo " http://${EIP}:8080" | |
break | |
fi | |
echo "" | |
echo "Waiting for K8s ready" | |
kubectl get deploy/srs-deployment | |
kubectl get svc/srs-service | |
sleep 1 | |
done | |
# (Optional) Update README if EIP changed. | |
- name: Update README | |
continue-on-error: true | |
run: | | |
EIP=$(grep 'Publish RTMP to rtmp' README.md |awk -F '://' '{print $2}'| awk -F '/' '{print $1}') | |
echo "README EIP is $EIP" | |
if [[ $EIP != '' && $EIP != $SRS_EIP ]]; then | |
sed -i "s/$EIP/$SRS_EIP/g" README.md | |
echo "README_CHANGED=true" >> $GITHUB_ENV | |
fi | |
# (Optional) Commit modified files | |
- name: Commit files | |
if: env.README_CHANGED == 'true' | |
run: | | |
git config --local user.email "[email protected]" | |
git config --local user.name "GitHub Action" | |
git add . | |
git commit -m "Update README if EIP changed." | |
# (Optional) Push changes | |
- name: Push changes | |
if: env.README_CHANGED == 'true' | |
uses: ad-m/github-push-action@master | |
with: | |
branch: main | |
github_token: ${{ secrets.GITHUB_TOKEN }} |