From: Raphaƫl Jakse Date: Mon, 13 Apr 2020 08:32:51 +0000 (+0200) Subject: Add scripts to deploy to production X-Git-Url: https://secure.softndesign.org/git/?a=commitdiff_plain;h=9712ec4e9fbfabb508bdc8880ce8332186f1b4d8;p=trivabble.git Add scripts to deploy to production --- diff --git a/bin/disable-const-let.sh b/bin/disable-const-let.sh new file mode 100644 index 0000000..1b9b510 --- /dev/null +++ b/bin/disable-const-let.sh @@ -0,0 +1,17 @@ +#!/usr/bin/env sh + +# This is needed for compatibility with Safari 9, used in the iPad 2. +# This browser understands the code of Trivabble, except const and let. +# Let's sadly edit them out of javascript files on production to enable +# more people to play. + +WORKING_DIRECTORY="$(dirname "$(dirname "$0")")" + +if [ -d "$WORKING_DIRECTORY/.git" ]; then + if [ -z "$(git status --porcelain | grep '.js$')" ]; then + sed -i -E 's/(^|\(|\s)(let|const)(\s)/\1var\3/g' "$WORKING_DIRECTORY"/*.js + else + >&2 echo "You have untracked changes in JS files. I'm not going to mess up with your working copy." + exit 1 + fi +fi diff --git a/bin/setup_prod.sh b/bin/setup_prod.sh new file mode 100644 index 0000000..4a1578f --- /dev/null +++ b/bin/setup_prod.sh @@ -0,0 +1,3 @@ +#!/usr/bin/env sh + +exec "$(dirname $0)/disable-const-let.sh" diff --git a/bin/upgrade-prod.sh b/bin/upgrade-prod.sh new file mode 100644 index 0000000..c52de1b --- /dev/null +++ b/bin/upgrade-prod.sh @@ -0,0 +1,63 @@ +#!/usr/bin/env sh + +set -euf + +error() { + >&2 echo "$1" + exit 1 +} + +if [ -z "${1+x}" ]; then + error "Please provide the production directory in parameter." +fi + +if [ "$(id -u)" = "0" ]; then + error "Not running as root. Please run me as your webserver's user for instance, using something like sudo -H -u www-data $0 $1" +fi + +PROD_DIR="$1" + +if ! [ -d "$PROD_DIR" ]; then + error "The production directory $PROD_DIR does not exist. I give up." +fi + +if [ -d "$PROD_DIR/.git" ]; then + error "The production folder should not be a git repository." +fi + +WORKING_DIRECTORY="$(dirname "$(dirname "$0")")" + +if ! [ -d "$WORKING_DIRECTORY/.git" ]; then + error "Not a git repository. Cannot update." +fi + +if [ -f "$WORKING_DIRECTORY/games.backup.json" ]; then + error "Your working copy has a 'games.backup.json' file. I give up." +fi + +if [ -z "$(git status --porcelain)" ]; then + error "Your git repository is not clean. I am not doing anything." +fi + +# Thx https://stackoverflow.com/questions/17414104/git-checkout-latest-tag + +echo "Fetching updates from git" +git fetch +new_version="$(git tag --list '[prod]*' --sort=v:refname | tail -1)" + +echo "Checking out ${new_version}..." +git checkout "$new_version" + +echo "Setting up production mode..." +"$(dirname $0)"/setup_prod.sh + +BACKUP_DIR="$WORKING_DIRECTORY/../trivabble-prod.bak" + +echo "Backing up production to $BACKUP_DIR ..." +rsync -avp --delete "$PROD_DIR/" "$BACKUP_DIR/" + +echo "Sending to production..." +rsync -avp --delete --exclude 'games.backup.json' --exclude '/.git' "$WORKING_DIRECTORY/" "$PROD_DIR/" + +echo echo "Resetting the directory..." +git reset --hard "$new_version"