From 63a9b94a0ed85c37aff6f652e103a9d04b342d10 Mon Sep 17 00:00:00 2001 From: Lars Brinkhoff Date: Wed, 20 Jan 2021 12:40:27 +0100 Subject: [PATCH] Deploy built images using rsync. --- .github/workflows/build.yml | 7 +++++++ build/deploy.sh | 32 ++++++++++++++++++++++++++++++-- 2 files changed, 37 insertions(+), 2 deletions(-) diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index f55550f12..293a0ff0f 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -8,6 +8,7 @@ defaults: jobs: build: + environment: Deploy runs-on: ${{matrix.os}} strategy: matrix: @@ -22,3 +23,9 @@ jobs: run: sh -ex build/dependencies.sh install_linux - name: Build run: make check-dirs all EMULATOR=${{matrix.emulator}} + - name: Deploy + if: github.ref == 'refs/heads/master' + env: + SECRET: ${{secrets.SECRET}} + EMULATOR: ${{matrix.emulator}} + run: sh build/deploy.sh diff --git a/build/deploy.sh b/build/deploy.sh index 71f52a29c..4985bb144 100755 --- a/build/deploy.sh +++ b/build/deploy.sh @@ -1,5 +1,33 @@ #!/bin/sh -echo "Here we can do anything when deployment has finished." -echo "Such as kicking off a second build stage." +# At the $HOST, the $USER needs to have an .ssh directory with +# authorized_keys matching $SECRET. + +set -e + +HOST=hactrn.org +PORT=22 +USER=images +DIR=/var/www/hactrn.org/images + +SSH=$HOME/.ssh +ID=$SSH/id_rsa + +if test -z "$SECRET"; then + echo 'ERROR: No key in $SECRET.' + exit 1 +fi + +mkdir -p $SSH +chmod 700 $SSH +echo "$SECRET" > $ID +chmod 600 $ID + +ssh-keyscan -p $PORT -H $HOST >> ~/.ssh/known_hosts + +(cd out; tar czf $EMULATOR.tgz $EMULATOR) + +echo "Deploying to $USER@$HOST:$PORT" +rsync -av --inplace -e "ssh -p$PORT -l$USER" out/$EMULATOR.tgz $HOST:$DIR + exit 0