Commit 06643b1e authored by Rahix's avatar Rahix 🦀
Browse files

ci: Atomically deploy updates

Use a symlink-based procedure for making the update deployment atomic.
This way, at no time does the filesystem contain an invalid version of
the game and thus the webserver will never serve an inconsistent state.
parent c8a886d8
......@@ -59,7 +59,7 @@ deploy:
tags:
- local
script:
- "cp -r www/dist/* /var/www/game"
- ./ci/deploy.sh www/dist /var/www
only:
- master
- tags
#!/bin/bash
set -e
INDIR="$1"
OUTDIR="$2"
if ! test -h "$OUTDIR/game" && test -d "$OUTDIR/game"; then
echo "Removing legacy deployment directory ..."
rm -r "$OUTDIR/game"
fi
if ! test -d "$OUTDIR/versions"; then
echo "Creating versions directory ..."
mkdir "$OUTDIR/versions"
fi
VERSION="$(git -C "$INDIR" describe --always --long)"
echo "Copying to $OUTDIR/versions/$VERSION ..."
cp -rT "$INDIR" "$OUTDIR/versions/$VERSION"
echo "Atomically updating symlink ..."
ln -nsf "$OUTDIR/versions/$VERSION" "$OUTDIR/new-game"
mv -T "$OUTDIR/new-game" "$OUTDIR/game"
echo "WE ARE LIVE!"
echo "Cleaning up previous deployments ..."
for PREVIOUS in "$OUTDIR/versions"/*; do
if ! [ "$PREVIOUS" = "$OUTDIR/versions/$VERSION" ]; then
echo " - Removing $PREVIOUS ..."
rm -r "$PREVIOUS"
fi
done
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment