Giovani Altelino

Giovani Altelino

Software engineering blog and other (un)related themes.

19 Jun 2020

Deployment Automation

If you looking to setup your static hugo website, I recommend you to read here instead.

During the first deployment of this website I really didn’t cared about a continuous deployment setup, since it should work pretty straightforward as I wrote on my blog project post, but I ended up deciding to automate most of my deployment to my droplet, so I could avoid logging into it frequently.

For the blog project I want it to update my website only after I pull a new compiled version to Github, so new changes would appear only after I run ‘Hugo’ on my computer. If you want to do something similar, go to your Github repo, select Actions, them setup your own workflow. I’m also using the Github built in secrets to avoid typing directly into the YAML file some sensitive data.

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
name: deploy hugo

on:
  push:
    branches:
      - master

jobs:
  build:
    runs-on: ubuntu-latest

    steps:
      - uses: actions/checkout@v1
      - name: d
        env:
          remote_host: ${{ secrets.HOST }}
          remote_port: ${{ secrets.PORT }}
          remote_user: ${{ secrets.USER }}
          remote_key: ${{ secrets.SERVER_SSH_KEY }}
          local_dir: "public/"
          remote_dir: ${{ secrets.SERVER_PATH }}
        run: |
          mkdir ~/.ssh
          echo "$remote_key" > ~/.ssh/gh_actions_key
          chmod 600 ~/.ssh/gh_actions_key
          rsync -avzr --delete -e "ssh -p ${remote_port} -i ~/.ssh/gh_actions_key -o StrictHostKeyChecking=no" ${local_dir} ${remote_user}@${remote_host}:${remote_dir}          

A quick note is that I had some issues with it at first, I was trying to use my default SSH Key, which I also use on the Digital Ocean Droplet, the issue was caused due to my default SSH key asking a password, so I made a new key and added it to the Droplet, works fine now.