#!/usr/bin/env bash set -e echo "Upgrading PostHog. This will cause a few minutes of downtime." read -r -p "Do you want to upgarde PostHog? [y/N] " response if [[ "$response" =~ ^([yY][eE][sS]|[yY])+$ ]] then echo "OK!" else exit fi if [ "$REGISTRY_URL" == "" ] then export REGISTRY_URL="posthog/posthog" fi export POSTHOG_APP_TAG="${POSTHOG_APP_TAG:-latest}" echo "Checking for named postgres and clickhouse volumes to avoid data loss when upgrading from < 1.39" if docker volume ls | grep -Pzoq 'clickhouse-data\n(.|\n)*postgres-data\n' then DOCKER_VOLUMES_MISSING=FALSE echo "Found postgres and clickhouse volumes, proceeding..." else DOCKER_VOLUMES_MISSING=TRUE echo "" echo "" echo "🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨" echo "🚨🚨🚨🚨🚨 WARNING: POTENTIAL DATA LOSS 🚨🚨🚨🚨🚨🚨" echo "🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨" echo "" echo "" echo "We were unable to find named clickhouse and postgres volumes." echo "If you created your PostHog stack PRIOR TO August 12th, 2022 / v1.39.0, the Postgres and Clickhouse containers did NOT have persistent named volumes by default." echo "If you choose to upgrade, you πŸ’£ will likely lose data πŸ’£ contained in these anonymous volumes." echo "" echo "See the discussion here for more information: https://github.com/PostHog/posthog/pull/11256" echo "" echo "WE STRONGLY RECOMMEND YOU:" echo "" echo "πŸ›‘ Stop this script and do not proceed" echo "βœ… Back up your entire environment/installation (vm, host, etc.), including all docker containers and volumes:" echo "βœ… Specifically back up the contents of :" echo " β˜‘ /var/lib/postgresql/data in the postgres (*_db_1) container" echo " β˜‘ /var/lib/clickhouse in the clickhouse (*_clickhouse_1) container" echo "and be ready to check/recopy the data before you boot PostHog next." read -r -p "Do you want to proceed anyway? [y/N] " response if [[ "$response" =~ ^([yY][eE][sS]|[yY])+$ ]] then echo "OK!" else exit fi fi [[ -f ".env" ]] && export $(cat .env | xargs) || ( echo "No .env file found. Please create it with POSTHOG_SECRET and DOMAIN set." && exit 1) # we introduced ENCRYPTION_SALT_KEYS and so if there isn't one, need to add it # check for it in the .env file if ! grep -q "ENCRYPTION_SALT_KEYS" .env; then ENCRYPTION_KEY=$(dd if=/dev/urandom bs=32 count=1 2>/dev/null | openssl base64) echo "ENCRYPTION_SALT_KEYS=$ENCRYPTION_KEY" >> .env echo "Added missing ENCRYPTION_SALT_KEYS to .env file" else # Read the existing key EXISTING_KEY=$(grep "ENCRYPTION_SALT_KEYS" .env | cut -d '=' -f2) # Check if the existing key is in the correct format (32 bytes base64url) if [[ ! $EXISTING_KEY =~ ^[A-Za-z0-9_-]{43}$ ]]; then echo "ENCRYPTION_SALT_KEYS is not in the correct fernet format and will not work" echo "πŸ›‘ Stop this script and do not proceed" echo "remove ENCRYPTION_SALT_KEYS from .env and try again" exit 1 fi fi export POSTHOG_APP_TAG="${POSTHOG_APP_TAG:-latest-release}" cd posthog git pull cd ../ # Upgrade Docker Compose to version 2.13.0 echo "Setting up Docker Compose" sudo rm /usr/local/bin/docker-compose sudo curl -L "https://github.com/docker/compose/releases/download/v2.13.0/docker-compose-$(uname -s)-$(uname -m)" -o /usr/local/bin/docker-compose || true sudo chmod +x /usr/local/bin/docker-compose rm -f docker-compose.yml cp posthog/docker-compose.base.yml docker-compose.base.yml cp posthog/docker-compose.hobby.yml docker-compose.yml.tmpl envsubst < docker-compose.yml.tmpl > docker-compose.yml rm docker-compose.yml.tmpl docker-compose pull echo "Checking if async migrations are up to date" sudo -E docker-compose run asyncmigrationscheck echo "Stopping the stack!" docker-compose stop # rewrite entrypoint # TODO: this is duplicated from bin/deploy-hobby. We should refactor this into a # single script. cat > compose/start <