diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml new file mode 100644 index 0000000..0f73688 --- /dev/null +++ b/.github/workflows/ci.yml @@ -0,0 +1,38 @@ +name: deploy to digitalOcean +run-name: Deploy to DigitalOcean by @${{ github.actor }} +on: + push: + branches: + - main + +jobs: + deploy: + runs-on: ubuntu-latest + steps: + - name: Deploy Flask app + uses: appleboy/ssh-action@v0.1.2 + with: + host: ${{secrets.SSH_HOST}} # IP address of the server you wish to ssh into + key: ${{secrets.SSH_KEY}} # Private or public key of the server + username: ${{ secrets.SSH_USERNAME }} # User of the server you want to ssh into + script: | + if ! [ -d "$HOME/waterlogged-prototype/" ]; then + echo 'repo does not exist!' + exit 1 + fi + + cd $HOME/waterlogged-prototype/ + + git pull + if [ $? != 0 ]; then + echo "git pull failed, check the server logs!" + exit 1 + fi + + ./deploy-rust.sh + if [ $? != 0 ]; then + echo "deploy-rust.sh failed, check the server logs!" + exit 1 + fi + + echo 'Deployment successful to digital ocean' diff --git a/README.md b/README.md index af21f17..b948f8f 100644 --- a/README.md +++ b/README.md @@ -9,8 +9,7 @@ Similar advice is available from government sources on a subscription basis, mos # TODOs -- [✓] Build a decent docker template for the rust API [KN 4/11/23] -- [] Set up CI to deploy to digitalocean droplet using ssh and docker +See https://github.com/nseymoursmith/waterlogged-prototype/issues # User flow diff --git a/deploy-rust.sh b/deploy-rust.sh new file mode 100755 index 0000000..701d906 --- /dev/null +++ b/deploy-rust.sh @@ -0,0 +1,23 @@ +#!/bin/bash + +./stop-api.sh + +if ! [ -d "$HOME/waterlogged-prototype/dockerised-rust-api/" ]; then + echo 'docker app directory does not exist!' + exit 1 +fi + +cd $HOME/waterlogged-prototype/dockerised-rust-api/ +cargo build --release +if [ $? != 0 ]; then + echo "cargo build failed, check the server logs!" + exit 1 +fi + +./target/release/api-example & + +# Capture PID of last executed command with `$!` +# and use it to generate a kill script +echo "kill $!" > ../stop-api.sh + +chmod +x ../stop-api.sh