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: ...@@ -59,7 +59,7 @@ deploy:
tags: tags:
- local - local
script: script:
- "cp -r www/dist/* /var/www/game" - ./ci/ www/dist /var/www
only: only:
- master - master
- tags - tags
set -e
if ! test -h "$OUTDIR/game" && test -d "$OUTDIR/game"; then
echo "Removing legacy deployment directory ..."
rm -r "$OUTDIR/game"
if ! test -d "$OUTDIR/versions"; then
echo "Creating versions directory ..."
mkdir "$OUTDIR/versions"
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"
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