2016-08-23 12:37:29 +02:00
|
|
|
#!/bin/bash -e
|
|
|
|
|
2017-03-10 09:55:04 +01:00
|
|
|
case $1 in
|
2017-03-10 14:24:22 +01:00
|
|
|
cloud*)
|
|
|
|
DEPLOYHOST="$1"
|
2017-03-10 09:55:04 +01:00
|
|
|
;;
|
|
|
|
*)
|
2017-03-10 14:24:22 +01:00
|
|
|
echo "Use $0 cloud{nr}|cloud.blender.org" >&2
|
2017-03-10 09:55:04 +01:00
|
|
|
exit 1
|
|
|
|
esac
|
|
|
|
|
2017-03-10 14:24:22 +01:00
|
|
|
echo -n "Deploying to ${DEPLOYHOST}... "
|
|
|
|
|
|
|
|
if ! ping ${DEPLOYHOST} -q -c 1 -w 2 >/dev/null; then
|
|
|
|
echo "host ${DEPLOYHOST} cannot be pinged, refusing to deploy." >&2
|
|
|
|
exit 2
|
|
|
|
fi
|
|
|
|
|
|
|
|
echo "press [ENTER] to continue, Ctrl+C to abort."
|
|
|
|
read dummy
|
|
|
|
|
|
|
|
|
2016-08-23 12:37:29 +02:00
|
|
|
# Deploys the current production branch to the production machine.
|
|
|
|
PROJECT_NAME="blender-cloud"
|
|
|
|
DOCKER_NAME="blender_cloud"
|
|
|
|
REMOTE_ROOT="/data/git/${PROJECT_NAME}"
|
|
|
|
|
2017-03-10 09:55:04 +01:00
|
|
|
SSH="ssh -o ClearAllForwardings=yes ${DEPLOYHOST}"
|
2016-12-01 12:38:50 +01:00
|
|
|
|
|
|
|
# macOS does not support readlink -f, so we use greadlink instead
|
|
|
|
if [[ `uname` == 'Darwin' ]]; then
|
2016-12-01 12:59:53 +01:00
|
|
|
command -v greadlink 2>/dev/null 2>&1 || { echo >&2 "Install greadlink using brew."; exit 1; }
|
2016-12-01 12:42:23 +01:00
|
|
|
readlink='greadlink'
|
2016-12-01 12:38:50 +01:00
|
|
|
else
|
|
|
|
readlink='readlink'
|
|
|
|
fi
|
|
|
|
|
|
|
|
ROOT="$(dirname "$($readlink -f "$0")")"
|
2016-08-23 12:37:29 +02:00
|
|
|
cd ${ROOT}
|
|
|
|
|
|
|
|
# Check that we're on production branch.
|
|
|
|
if [ $(git rev-parse --abbrev-ref HEAD) != "production" ]; then
|
|
|
|
echo "You are NOT on the production branch, refusing to deploy." >&2
|
|
|
|
exit 1
|
|
|
|
fi
|
|
|
|
|
|
|
|
# Check that production branch has been pushed.
|
|
|
|
if [ -n "$(git log origin/production..production --oneline)" ]; then
|
|
|
|
echo "WARNING: not all changes to the production branch have been pushed."
|
|
|
|
echo "Press [ENTER] to continue deploying current origin/production, CTRL+C to abort."
|
|
|
|
read dummy
|
|
|
|
fi
|
|
|
|
|
2016-11-06 18:58:51 +01:00
|
|
|
function find_module()
|
|
|
|
{
|
2017-01-12 16:55:40 +01:00
|
|
|
MODULE_NAME=$1
|
2016-11-06 18:58:51 +01:00
|
|
|
MODULE_DIR=$(python <<EOT
|
2016-08-26 14:33:22 +02:00
|
|
|
from __future__ import print_function
|
|
|
|
import os.path
|
|
|
|
try:
|
2017-01-12 16:55:40 +01:00
|
|
|
import ${MODULE_NAME}
|
2016-08-26 14:33:22 +02:00
|
|
|
except ImportError:
|
2017-01-12 16:55:40 +01:00
|
|
|
raise SystemExit('${MODULE_NAME} not found on Python path. Are you in the correct venv?')
|
2016-08-26 14:33:22 +02:00
|
|
|
|
2017-01-12 16:55:40 +01:00
|
|
|
print(os.path.dirname(os.path.dirname(${MODULE_NAME}.__file__)))
|
2016-08-26 14:33:22 +02:00
|
|
|
EOT
|
|
|
|
)
|
|
|
|
|
2017-01-12 16:55:40 +01:00
|
|
|
if [ $(git -C $MODULE_DIR rev-parse --abbrev-ref HEAD) != "production" ]; then
|
|
|
|
echo "${MODULE_NAME}: ($MODULE_DIR) NOT on the production branch, refusing to deploy." >&2
|
|
|
|
exit 1
|
|
|
|
fi
|
2016-09-29 17:59:24 +02:00
|
|
|
|
2017-01-12 16:56:06 +01:00
|
|
|
echo $MODULE_DIR
|
2017-01-12 16:55:40 +01:00
|
|
|
}
|
2016-08-26 14:33:22 +02:00
|
|
|
|
2017-01-12 16:56:06 +01:00
|
|
|
# Find our modules
|
|
|
|
PILLAR_DIR=$(find_module pillar)
|
|
|
|
ATTRACT_DIR=$(find_module attract)
|
|
|
|
FLAMENCO_DIR=$(find_module flamenco)
|
2016-09-29 17:59:24 +02:00
|
|
|
|
2017-01-12 16:56:06 +01:00
|
|
|
echo "Pillar : $PILLAR_DIR"
|
|
|
|
echo "Attract : $ATTRACT_DIR"
|
|
|
|
echo "Flamenco: $FLAMENCO_DIR"
|
2016-08-26 14:33:22 +02:00
|
|
|
|
2017-01-13 14:45:36 +01:00
|
|
|
if [ -z "$PILLAR_DIR" -o -z "$ATTRACT_DIR" -o -z "$FLAMENCO_DIR" ];
|
|
|
|
then
|
|
|
|
exit 1
|
|
|
|
fi
|
|
|
|
|
2016-08-23 12:37:29 +02:00
|
|
|
# SSH to cloud to pull all files in
|
|
|
|
function git_pull() {
|
|
|
|
PROJECT_NAME="$1"
|
|
|
|
BRANCH="$2"
|
|
|
|
REMOTE_ROOT="/data/git/${PROJECT_NAME}"
|
|
|
|
|
|
|
|
echo "==================================================================="
|
|
|
|
echo "UPDATING FILES ON ${PROJECT_NAME}"
|
|
|
|
${SSH} git -C ${REMOTE_ROOT} fetch origin ${BRANCH}
|
|
|
|
${SSH} git -C ${REMOTE_ROOT} log origin/${BRANCH}..${BRANCH} --oneline
|
|
|
|
${SSH} git -C ${REMOTE_ROOT} merge --ff-only origin/${BRANCH}
|
|
|
|
}
|
|
|
|
|
|
|
|
git_pull pillar-python-sdk master
|
|
|
|
git_pull pillar production
|
2016-09-29 17:59:24 +02:00
|
|
|
git_pull attract production
|
2017-01-12 16:56:20 +01:00
|
|
|
git_pull flamenco production
|
2016-08-23 12:37:29 +02:00
|
|
|
git_pull blender-cloud production
|
|
|
|
|
|
|
|
# Update the virtualenv
|
2016-08-30 13:58:00 +02:00
|
|
|
#${SSH} -t docker exec ${DOCKER_NAME} /data/venv/bin/pip install -U -r ${REMOTE_ROOT}/requirements.txt --exists-action w
|
2016-08-23 12:37:29 +02:00
|
|
|
|
2016-08-23 12:50:19 +02:00
|
|
|
# RSync the world
|
2017-03-10 09:55:04 +01:00
|
|
|
$ATTRACT_DIR/rsync_ui.sh ${DEPLOYHOST}
|
|
|
|
$FLAMENCO_DIR/rsync_ui.sh ${DEPLOYHOST}
|
|
|
|
./rsync_ui.sh ${DEPLOYHOST}
|
2016-08-23 12:50:19 +02:00
|
|
|
|
2016-08-23 12:37:29 +02:00
|
|
|
# Notify Bugsnag of this new deploy.
|
|
|
|
echo
|
|
|
|
echo "==================================================================="
|
|
|
|
GIT_REVISION=$(${SSH} git -C ${REMOTE_ROOT} describe --always)
|
|
|
|
echo "Notifying Bugsnag of this new deploy of revision ${GIT_REVISION}."
|
|
|
|
BUGSNAG_API_KEY=$(${SSH} python -c "\"import sys; sys.path.append('${REMOTE_ROOT}'); import config_local; print(config_local.BUGSNAG_API_KEY)\"")
|
|
|
|
curl --data "apiKey=${BUGSNAG_API_KEY}&revision=${GIT_REVISION}" https://notify.bugsnag.com/deploy
|
|
|
|
echo
|
|
|
|
|
|
|
|
# Wait for [ENTER] to restart the server
|
|
|
|
echo
|
|
|
|
echo "==================================================================="
|
|
|
|
echo "NOTE: If you want to edit config_local.py on the server, do so now."
|
|
|
|
echo "NOTE: Press [ENTER] to continue and restart the server process."
|
|
|
|
read dummy
|
2016-08-23 14:57:55 +02:00
|
|
|
${SSH} docker exec ${DOCKER_NAME} apache2ctl graceful
|
2016-08-23 12:37:29 +02:00
|
|
|
echo "Server process restarted"
|
|
|
|
|
2016-08-26 15:59:12 +02:00
|
|
|
echo
|
|
|
|
echo "==================================================================="
|
|
|
|
echo "Clearing front page from Redis cache."
|
|
|
|
${SSH} docker exec redis redis-cli DEL pwview//
|
|
|
|
|
2016-08-23 12:37:29 +02:00
|
|
|
echo
|
|
|
|
echo "==================================================================="
|
|
|
|
echo "Deploy of ${PROJECT_NAME} is done."
|
|
|
|
echo "==================================================================="
|