diff options
author | Teddy Wing | 2018-11-20 02:16:23 +0100 |
---|---|---|
committer | Teddy Wing | 2018-11-20 02:16:23 +0100 |
commit | 1db7ad0581e7b51c472e03899c367ed61d24744c (patch) | |
tree | 7a103a4662fa0da7fcf04977d144e940705a4a23 | |
parent | 3ce1ae31105e2655a138df923dbea9b90f22d348 (diff) | |
download | dome-key-web-1db7ad0581e7b51c472e03899c367ed61d24744c.tar.bz2 |
Add deployment script
To deploy, run
$ make deploy
This checks prerequisites and runs `scripts/deploy.sh`.
Makefile:
Include a new target that builds the Rust binaries for Linux using
Docker.
The script `rsync`s the website files to the server, moves some files
around on the server, and runs the database migrations.
Currently I'm getting an error at the database migration stage, as it
seems I can't use `UTC_TIMESTAMP()` as a default column value. Need to
correct that to get a clean deployment.
-rw-r--r-- | Makefile | 19 | ||||
-rw-r--r-- | license-generator/.env.sample | 3 | ||||
-rwxr-xr-x | scripts/deploy.sh | 34 | ||||
-rwxr-xr-x | scripts/post-deploy.sh | 25 | ||||
-rwxr-xr-x | scripts/provision.sh | 20 |
5 files changed, 101 insertions, 0 deletions
@@ -10,3 +10,22 @@ assets/styles.css: assets/stylesheets/main.hcss \ internal_error.html: internal_error.in.html ./scripts/generate_500.py > $@ + +# Compile binaries for Linux +license-generator/target/release/fulfillment \ +license-generator/target/release/license: + docker run \ + --rm \ + --interactive \ + --tty \ + --volume $$PWD/license-generator:/app \ + --workdir /app \ + rust:1.30.1-stretch \ + cargo build --release + +.PHONY: deploy +deploy: license-generator/target/release/fulfillment \ + license-generator/target/release/license \ + internal_error.html \ + assets/styles.css + bash ./scripts/deploy.sh diff --git a/license-generator/.env.sample b/license-generator/.env.sample index bc8f6ba..9636e4e 100644 --- a/license-generator/.env.sample +++ b/license-generator/.env.sample @@ -8,6 +8,9 @@ export DATABASE_URL="mysql://localhost:3306/dome_key" export GO_DATABASE_URL="mysql://tcp(localhost:3306)/dome_key" +export SSH_SERVER="user@host" +export REMOTE_PUBLIC_WWW="/home/user/www" + function migrate-create () { local migration_name="$1" diff --git a/scripts/deploy.sh b/scripts/deploy.sh new file mode 100755 index 0000000..a2bde7a --- /dev/null +++ b/scripts/deploy.sh @@ -0,0 +1,34 @@ +#!/bin/bash + +set -ex + + +source license-generator/.env + +echo 'Deploying...' + +rsync -avz \ + --exclude 'assets/stylesheets' \ + 400.html \ + 404.html \ + assets \ + doc \ + downloads \ + index.html \ + internal_error.html \ + license-generator/target/release/fulfillment \ + license-generator/target/release/license \ + robots.txt \ + thank-you.html \ + "$SSH_SERVER":"$REMOTE_PUBLIC_WWW/" + +rsync -avz \ + --exclude '.git' \ + license-generator/migrations \ + production-config \ + scripts \ + "$SSH_SERVER":~/ + + +echo 'Running post-deploy script...' +ssh "$SSH_SERVER" 'bash ~/scripts/post-deploy.sh' diff --git a/scripts/post-deploy.sh b/scripts/post-deploy.sh new file mode 100755 index 0000000..4d3fd9c --- /dev/null +++ b/scripts/post-deploy.sh @@ -0,0 +1,25 @@ +#!/bin/bash + +set -ex + + +export PATH="$HOME/opt/bin:$PATH" + +source "$HOME/production-config/env" + +echo 'Moving files...' + +mv "$REMOTE_PUBLIC_WWW/fulfillment" "$REMOTE_PUBLIC_WWW/fulfillment.fcgi" +mv "$REMOTE_PUBLIC_WWW/license" "$REMOTE_PUBLIC_WWW/license.fcgi" + +mv production-config/.htaccess "$REMOTE_PUBLIC_WWW" + + +echo 'Provisioning...' + +sh "$HOME/scripts/provision.sh" + + +echo 'Migrating database...' + +migrate-up diff --git a/scripts/provision.sh b/scripts/provision.sh new file mode 100755 index 0000000..bf8e478 --- /dev/null +++ b/scripts/provision.sh @@ -0,0 +1,20 @@ +#!/bin/sh + +set -ex + +OPT="$HOME/opt" + + +if [ ! -f "$OPT/bin/migrate" ]; then + echo "Installing 'migrate'..." + + mkdir -p "$OPT/bin" + + curl \ + --remote-name \ + --location 'https://github.com/golang-migrate/migrate/releases/download/v4.0.2/migrate.linux-amd64.tar.gz' + + tar xf migrate.linux-amd64.tar.gz + mv migrate.linux-amd64 "$OPT/bin/migrate" + rm migrate.linux-amd64.tar.gz +fi |