pixelplanet/deployment/post-receive
2022-01-03 14:11:28 +01:00

66 lines
3.0 KiB
Bash
Executable File

#!/bin/bash
# This hook dists pixelplanet after a push, and deploys it
# If it is the production branch, it will deploy it on the life system, and other branch will get deployed to the dev-canvas (a second canvas that is running on the server)
# canvases.json, proxies.json and ecosystem.yml are already in the terget directories
#
# To set up a server to use this, you have to go through the building steps manually first.
# And the configured ecosystem-x.yml files need to be in the target folder already, as they don't get copied from the build directory.
# This hook just buildss the canvas, it does not install new packages if needed. So this has to be done manually first
#
#folder for building the canvas (the git repository will get checkout there and the canvas will get buil thtere)
BUILDDIR="/home/pixelpla/pixelplanet-build"
#folder for dev canvas
DEVFOLDER="/home/pixelpla/pixelplanet-dev"
#folder for production canvas
PFOLDER="/home/pixelpla/pixelplanet"
while read oldrev newrev refname
do
branch=$(git rev-parse --symbolic --abbrev-ref $refname)
if [ "production" == "$branch" ]; then
echo "---UPDATING REPO ON PRODUCTION SERVER---"
GIT_WORK_TREE="$BUILDDIR" GIT_DIR="${BUILDDIR}/.git" git fetch --all
GIT_WORK_TREE="$BUILDDIR" GIT_DIR="${BUILDDIR}/.git" git reset --hard origin/production
COMMITS=`git log --pretty=format:'- %s%b' $newrev ^$oldrev`
COMMITS=`echo "$COMMITS" | sed ':a;N;$!ba;s/\n/\\\n/g'`
echo "---BUILDING pixelplanet---"
cd "$BUILDDIR"
npm run build
echo "---RESTARTING CANVAS---"
cp -r dist/*.js "${PFOLDER}/"
cp -r dist/public "${PFOLDER}/"
cp -r dist/captchaFonts "${PFOLDER}/"
cp -r dist/package.json "${PFOLDER}/"
cp -r dist/assets.json "${PFOLDER}/"
cp -r dist/styleassets.json "${PFOLDER}/"
mkdir -p "${PFOLDER}/log"
cd "$PFOLDER"
pm2 stop ppfun-server
pm2 stop ppfun-backups
pm2 stop ppfun-captchas
pm2 start ecosystem.yml
pm2 start ecosystem-backup.yml
pm2 start ecosystem-captchas.yml
else
echo "---UPDATING REPO ON DEV SERVER---"
pm2 stop ppfun-server-dev
GIT_WORK_TREE="$BUILDDIR" GIT_DIR="${BUILDDIR}/.git" git fetch --all
GIT_WORK_TREE="$BUILDDIR" GIT_DIR="${BUILDDIR}/.git" git reset --hard "origin/$branch"
COMMITS=`git log --pretty=format:'- %s%b' $newrev ^$oldrev`
COMMITS=`echo "$COMMITS" | sed ':a;N;$!ba;s/\n/\\\n/g'`
echo "---BUILDING pixelplanet---"
cd "$BUILDDIR"
nice -n 19 npm run build-en
echo "---RESTARTING CANVAS---"
cp -r dist/*.js "${DEVFOLDER}/"
cp -r dist/public "${DEVFOLDER}/"
cp -r dist/captchaFonts "${DEVFOLDER}/"
cp -r dist/package.json "${DEVFOLDER}/"
cp -r dist/assets.json "${DEVFOLDER}/"
cp -r dist/styleassets.json "${DEVFOLDER}/"
mkdir -p "${PFOLDER}/log"
cd "$DEVFOLDER"
pm2 start ecosystem.yml
fi
done