Lil script to prep Dokku for a Laravel app

Prerequisites

Usage

It creates an app named after your current directory, so be in the directory $HOME/code/yourwebapp. Then it creates a MySQL container. It then links the two together. Noice.

Production

initDokku dokku.yourdomain.net production

Creates a new app and mysql instance on dokku.yourdomain.net, links them together, creates a new git remote named production

Staging

initDokku staging-dokku.internal stage

Creates a new app and mysql instance on staging-dokku.internal, links them together, creates a new git remote named production

The Script

#!/bin/bash

gitRemote=$2

set -u

server=$1
app=${PWD##*/}

ssh [email protected]$server apps:create ${app}
ssh [email protected]$server mysql:create ${app}_db
ssh [email protected]$server mysql:link ${app}_db ${app}

if [ ! -z "${gitRemote}" ]
then
    git remote add ${gitRemote} [email protected]${server}:${app}
fi

Dokku and Laravel go well with

.buildpacks – Heroku (also Dokku) buildpacks that make Laravel work. Place the .buildpacks file in the base directory for your app (The same directory that has artisan in it)

Procfile – Same again in the base directory. You’ll later need to scale the worker up to 1 (or more), it’ll be scaled to 0 by default. Release is ran every time you deploy the app. It’s a good place to put your migrations, cache purges, etc

deploy.yml – You can also use GitHub Actions to deploy to Dokku, presumably after doing tests and style-ci etc. Have a look at my template to get started.

You’ll need to add the test segments, if you properly want to get into GitHub Actions have a look at [email protected]’s repo spatie/freek.dev:.github/workflows/, there’s loads you can do!