Auto Deployments

Where I catch up with modern times & build a Continuous deployment solution for this site

What magical times we live in, automatic deployments after every commit to the app running this website! I remember enviously reading about Capistrano while uploading files via FTP like an animal way back when. Finally got around to build out some reliable continuous deployments for my home projects, and it is a thing of beauty!

Dokku deals with all of the details of actually running containers for me on the VPS I have in a cloud somewhere.

Powered by Docker, you can install Dokku on any hardware. Use it on inexpensive cloud providers. Use the extra cash to buy a pony or feed kittens. You’ll save tens of dollars a year on your dog photo sharing website.

We can save money, littteraly pennies are being saved.

I probably could have done this earlier, using some other platform, or even scripts and a post commit hook. Github actions though makes it easy, it’s integrated right there next to my repo. Writing actions themselves is it a pretty horrible user experience if you’re not familiar. The documentation isn’t particularly clear, there isn’t anyway to trial an action without commiting it to the repo. If you have any errors in your YAML file then, good luck figuring out what you did wrong. For me it’s always almost indentation.

I’m undecided if I want deployments when marking a release, or deploys when commiting to main. Either way having the workflow_dispatch option as a trigger allows you to manually run the job.

In github secrets for the repo add in a private key, and a signature for the host your pushing to.

Finally the actions/checkout step needs fetch-depth: 0 to checkout with history otherwise dokku rejects the push.

name: Deploy to dokku

# Controls when the workflow will run

# Triggers the workflow on push or pull request events but only for the master branch

    branches: [ master ]
    branches: [ master ]
  #release when a version is tagged. 
    types: [ published ]


  # Allows you to run this workflow manually from the Actions tab

# A workflow run is made up of one or more jobs that can run sequentially or in parallel

    runs-on: ubuntu-latest

    # Checks-out your repository under $GITHUB_WORKSPACE, so your job can access it
    - uses: actions/checkout@v3
        fetch-depth: 0

    - name: Install SSH key
      uses: shimataro/ssh-key-action@v2.3.1
        key: ${{ secrets.SSH_PRIVATE_KEY }}
        name: id_rsa # optional
        known_hosts: ${{ secrets.KNOWN_HOSTS }}

    - name: Push to Dokku
      run: |
        git remote add dokku
        git push dokku master