This radically changes the way we deploy to the production server, as a Git checkout is no longer required there. All the necessary files are now inside the docker image. As a result, /data/git should no longer be mounted as a Docker volume. - Renamed docker/build.sh → docker/full_rebuild.sh This makes it clearer that it performs a full rebuild of the Docker images. - Full rebuilds should be done on a regular basis to pull in Ubuntu security updates. - Removed rsync_ui.sh, we no longer need it. Other projects can also remove their rsync_ui.sh. - Moved deploy.sh → deploy/2docker.sh and added deploy/2server.sh
80 lines
2.6 KiB
Bash
Executable File
80 lines
2.6 KiB
Bash
Executable File
#!/bin/bash -e
|
|
|
|
# macOS does not support readlink -f, so we use greadlink instead
|
|
if [[ `uname` == 'Darwin' ]]; then
|
|
command -v greadlink 2>/dev/null 2>&1 || { echo >&2 "Install greadlink using brew."; exit 1; }
|
|
readlink='greadlink'
|
|
else
|
|
readlink='readlink'
|
|
fi
|
|
ROOT="$(dirname "$(dirname "$($readlink -f "$0")")")"
|
|
PROJECT_NAME="$(basename $ROOT)"
|
|
DOCKER_DEPLOYDIR="$ROOT/docker/4_run/deploy"
|
|
DOCKER_IMAGE="armadillica/blender_cloud:latest"
|
|
REMOTE_SECRET_CONFIG_DIR="/data/config"
|
|
REMOTE_DOCKER_COMPOSE_DIR="/root/docker"
|
|
|
|
#################################################################################
|
|
case $1 in
|
|
cloud*)
|
|
DEPLOYHOST="$1"
|
|
;;
|
|
*)
|
|
echo "Use $0 cloud{nr}|cloud.blender.org" >&2
|
|
exit 1
|
|
esac
|
|
SSH_OPTS="-o ClearAllForwardings=yes -o PermitLocalCommand=no"
|
|
SSH="ssh $SSH_OPTS $DEPLOYHOST"
|
|
SCP="scp $SSH_OPTS"
|
|
|
|
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
|
|
|
|
cat <<EOT
|
|
[ping OK]
|
|
|
|
Make sure that you have pushed the $DOCKER_IMAGE
|
|
docker image to Docker Hub.
|
|
|
|
press [ENTER] to continue, Ctrl+C to abort.
|
|
EOT
|
|
read dummy
|
|
|
|
#################################################################################
|
|
echo "==================================================================="
|
|
echo "Bringing remote Docker up to date…"
|
|
$SSH mkdir -p $REMOTE_DOCKER_COMPOSE_DIR
|
|
$SCP $DOCKER_DEPLOYDIR/$PROJECT_NAME/docker/docker-compose.yml $DEPLOYHOST:$REMOTE_DOCKER_COMPOSE_DIR
|
|
$SSH -T <<EOT
|
|
set -e
|
|
cd $REMOTE_DOCKER_COMPOSE_DIR
|
|
docker pull $DOCKER_IMAGE
|
|
docker-compose up -d
|
|
|
|
echo
|
|
echo "==================================================================="
|
|
echo "Clearing front page from Redis cache."
|
|
docker exec redis redis-cli DEL pwview//
|
|
EOT
|
|
|
|
# Notify Sentry of this new deploy.
|
|
# See https://sentry.io/blender-institute/blender-cloud/settings/release-tracking/
|
|
# and https://docs.sentry.io/api/releases/post-organization-releases/
|
|
# and https://sentry.io/api/
|
|
echo
|
|
echo "==================================================================="
|
|
REVISION=$(date +'%Y%m%d.%H%M%S.%Z')
|
|
echo "Notifying Sentry of this new deploy of revision $REVISION."
|
|
SENTRY_RELEASE_URL="$($SSH env PYTHONPATH="$REMOTE_SECRET_CONFIG_DIR" python3 -c "\"import config_secrets; print(config_secrets.SENTRY_RELEASE_URL)\"")"
|
|
curl -s "$SENTRY_RELEASE_URL" -XPOST -H 'Content-Type: application/json' -d "{\"version\": \"$REVISION\"}" | json_pp
|
|
echo
|
|
|
|
echo
|
|
echo "==================================================================="
|
|
echo "Deploy to $DEPLOYHOST done."
|
|
echo "==================================================================="
|