@@ -27,11 +27,18 @@ jobs:
2727 username : ${{ secrets.BROADCASTER_SSH_USERNAME }}
2828 key : ${{ secrets.BROADCASTER_SSH_PRIV_KEY }}
2929 script : |
30+ # Exit if any command fails.
31+ set -e
32+
3033 export APP_NAME=broadcaster
3134 export TAG=${{ github.ref_name }}
3235 export TAG=${TAG#*-v}
36+
37+ echo "Cleaning previous broadcaster docker image"
3338 docker stop $APP_NAME
3439 docker rm $APP_NAME
40+
41+ echo "Running a new broadcaster image - $TAG"
3542 docker run -d --restart unless-stopped \
3643 --name $APP_NAME \
3744 -e SECRET_KEY_BASE=${{ secrets.BROADCASTER_SECRET_KEY_BASE }} \
@@ -42,10 +49,40 @@ jobs:
4249 -e WHIP_TOKEN=${{ secrets.BROADCASTER_WHIP_TOKEN }} \
4350 --network host \
4451 ghcr.io/elixir-webrtc/apps/$APP_NAME:$TAG
45- docker image prune --all --force
46-
47-
4852
53+ docker image prune --all --force
4954
55+ echo "Waiting for broadcaster to be ready."
56+ attempts=10
57+ until curl localhost:4000 > /dev/null 2>&1
58+ do
59+ ((attempts--))
60+ if [ $attempts -eq 0 ]; then
61+ exit 1
62+ fi
63+ sleep 1
64+ done
65+
66+ echo "Cloning client script"
67+ rm -rf /tmp/apps
68+ git clone -b ${{ github.ref_name }} https://github.com/${{ github.repository }} /tmp/apps
69+ cd /tmp/apps/broadcaster
5070
71+ echo "Terminating previously running client"
72+ # ignore non-zero exit status
73+ killall node || true
74+
75+ # This is needed to find `node` and `npm` commands.
76+ # See difference between interactive and non-interactive shells.
77+ source ~/.nvm/nvm.sh
78+
79+ echo "Installing puppeteer in current directory"
80+ npm install puppeteer
5181
82+ # Run node in bg, disconnect it from terminal and redirect all output.
83+ # In other case action won't end.
84+ echo "Running client script"
85+ USERNAME=${{ secrets.BROADCASTER_ADMIN_USERNAME }} \
86+ PASSWORD=${{ secrets.BROADCASTER_ADMIN_PASSWORD }} \
87+ TOKEN=${{ secrets.BROADCASTER_WHIP_TOKEN }} \
88+ nohup node headless_client.js > nohup.out 2> nohup.err < /dev/null &
0 commit comments