2024

All of my projects live in DigitalOcean Droplets, somewhere in some kind of internets cloud thing. Deploying to these Droplets has meant a lot of SFTP action... Until GitHub Actions showed me a better way.

I had a less-than-positive (bad) experience with Netlify which led them to erroneously charging my money card and their support was bad. It really burnt me.

In protest, I built my own private Netlify clone, but running bash scripts from Node is just not that fun.

Enter GitHub actions: you can create highly customisable workflows with various triggers that perform various actions which you may create yourself or import from other GitHub committers.

  1. The following action is fired on git push to the master branch.
  2. It spins up Ubuntu
  3. Check outs the latest commit
  4. Installs Node.js
  5. Runs npm install
  6. Runs npm run-script build
  7. Transfers the built React app to the specified Droplet (or server of your nomination) to be served by NGINX
name: Deploy create-react-app to DigitalOcean Droplet with SCP

on:
  push:
    branches: [ master ]

jobs:
  deploy:
    name: Deploy

    runs-on: ubuntu-latest

    steps:
    - uses: actions/checkout@v3
      with:
        submodules: 'recursive'

    - name: Setup Node.js
      uses: actions/setup-node@v3
      with:
        node-version: '16.x'

    - name: Install dependencies
      run: npm install

    - name: Build
      run: npm run-script build
      env: 
        CI: false

    - name: Deploy
      uses: appleboy/scp-action@master
      with:
        host: ${{ secrets.DROPLET_HOST }}
        username: ${{ secrets.DROPLET_USERNAME }}
        password: ${{ secrets.DROPLET_PASSWORD }}
        source: 'build/'
        target: '${{ secrets.DEPLOY_TARGET }}'
        strip_components: 1