2
0

feat(logs): Cleaner logs w/o ANSI sequences (#316)

This commit is contained in:
Burak Yigit Kaya 2020-01-03 22:06:33 +03:00 committed by GitHub
parent 629ee07c79
commit 4a82e9fa1d
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -1,6 +1,9 @@
#!/usr/bin/env bash #!/usr/bin/env bash
set -e set -e
dc="docker-compose --no-ansi"
dcr="$dc run --rm"
# Thanks to https://unix.stackexchange.com/a/145654/108960 # Thanks to https://unix.stackexchange.com/a/145654/108960
log_file="sentry_install_log-`date +'%Y-%m-%d_%H-%M-%S'`.txt" log_file="sentry_install_log-`date +'%Y-%m-%d_%H-%M-%S'`.txt"
exec &> >(tee -a "$log_file") exec &> >(tee -a "$log_file")
@ -20,7 +23,7 @@ cleanup () {
return 0; return 0;
fi fi
echo "Cleaning up..." echo "Cleaning up..."
docker-compose stop &> /dev/null $dc stop &> /dev/null
DID_CLEAN_UP=1 DID_CLEAN_UP=1
} }
trap cleanup ERR INT TERM trap cleanup ERR INT TERM
@ -28,7 +31,7 @@ trap cleanup ERR INT TERM
echo "Checking minimum requirements..." echo "Checking minimum requirements..."
DOCKER_VERSION=$(docker version --format '{{.Server.Version}}') DOCKER_VERSION=$(docker version --format '{{.Server.Version}}')
COMPOSE_VERSION=$(docker-compose --version | sed 's/docker-compose version \(.\{1,\}\),.*/\1/') COMPOSE_VERSION=$($dc --version | sed 's/docker-compose version \(.\{1,\}\),.*/\1/')
RAM_AVAILABLE_IN_DOCKER=$(docker run --rm busybox free -m 2>/dev/null | awk '/Mem/ {print $2}'); RAM_AVAILABLE_IN_DOCKER=$(docker run --rm busybox free -m 2>/dev/null | awk '/Mem/ {print $2}');
# Compare dot-separated strings - function below is inspired by https://stackoverflow.com/a/37939589/808368 # Compare dot-separated strings - function below is inspired by https://stackoverflow.com/a/37939589/808368
@ -60,7 +63,10 @@ if [ "$RAM_AVAILABLE_IN_DOCKER" -lt "$MIN_RAM" ]; then
fi fi
# Clean up old stuff and ensure nothing is working while we install/update # Clean up old stuff and ensure nothing is working while we install/update
docker-compose down --rmi local --remove-orphans # This is for older versions of on-premise:
$dc -p onpremise down --rmi local --remove-orphans
# This is for newer versions
$dc down --rmi local --remove-orphans
echo "" echo ""
echo "Creating volumes for persistent storage..." echo "Creating volumes for persistent storage..."
@ -88,10 +94,10 @@ echo ""
echo "Building and tagging Docker images..." echo "Building and tagging Docker images..."
echo "" echo ""
# Build the sentry onpremise image first as it is needed for the cron image # Build the sentry onpremise image first as it is needed for the cron image
docker-compose pull --ignore-pull-failures $dc pull --ignore-pull-failures
docker pull ${SENTRY_IMAGE:-getsentry/sentry:latest} docker pull ${SENTRY_IMAGE:-getsentry/sentry:latest}
docker-compose build --force-rm web $dc build --force-rm web
docker-compose build --force-rm $dc build --force-rm
echo "" echo ""
echo "Docker images built." echo "Docker images built."
@ -119,7 +125,7 @@ fi
echo "" echo ""
echo "Setting up database..." echo "Setting up database..."
if [ $CI ]; then if [ $CI ]; then
docker-compose run --rm web upgrade --noinput $dcr web upgrade --noinput
echo "" echo ""
echo "Did not prompt for user creation due to non-interactive shell." echo "Did not prompt for user creation due to non-interactive shell."
echo "Run the following command to create one yourself (recommended):" echo "Run the following command to create one yourself (recommended):"
@ -127,24 +133,25 @@ if [ $CI ]; then
echo " docker-compose run --rm web createuser" echo " docker-compose run --rm web createuser"
echo "" echo ""
else else
docker-compose run --rm web upgrade $dcr web upgrade
fi fi
SENTRY_DATA_NEEDS_MIGRATION=$(docker run --rm -v sentry-data:/data alpine ash -c "[ ! -d '/data/files' ] && ls -A1x /data | wc -l || true") SENTRY_DATA_NEEDS_MIGRATION=$(docker run --rm -v sentry-data:/data alpine ash -c "[ ! -d '/data/files' ] && ls -A1x /data | wc -l || true")
if [ "$SENTRY_DATA_NEEDS_MIGRATION" ]; then if [ "$SENTRY_DATA_NEEDS_MIGRATION" ]; then
echo "Migrating file storage..." echo "Migrating file storage..."
# Use the web (Sentry) image so the file owners are kept as sentry:sentry # Use the web (Sentry) image so the file owners are kept as sentry:sentry
docker-compose run --rm --entrypoint /bin/bash web -c \ $dcr --entrypoint /bin/bash web -c \
"mkdir -p /tmp/files; mv /data/* /tmp/files/; mv /tmp/files /data/files" "mkdir -p /tmp/files; mv /data/* /tmp/files/; mv /tmp/files /data/files"
fi fi
echo "Boostrapping Snuba..." echo "Boostrapping Snuba..."
docker-compose up -d kafka redis clickhouse $dc up -d kafka redis clickhouse
until $(docker-compose run --rm clickhouse clickhouse-client -h clickhouse --query="SHOW TABLES;" | grep -q sentry_local); do until $($dcr clickhouse clickhouse-client -h clickhouse --query="SHOW TABLES;" | grep -q sentry_local); do
# `bootstrap` is for fresh installs, and `migrate` is for existing installs # `bootstrap` is for fresh installs, and `migrate` is for existing installs
# Running them both for both cases is harmless so we blindly run them # Running them both for both cases is harmless so we blindly run them
docker-compose run --rm snuba-api bootstrap --force || true; $dcr snuba-api bootstrap --force || true;
docker-compose run --rm snuba-api migrate || true; $dcr snuba-api migrate || true;
done; done;
echo "" echo ""
@ -152,7 +159,7 @@ set -o allexport
source .env source .env
set +o allexport set +o allexport
echo "Migrating old events for the last $SENTRY_EVENT_RETENTION_DAYS days..." echo "Migrating old events for the last $SENTRY_EVENT_RETENTION_DAYS days..."
docker-compose run --rm web django backfill_eventstream --no-input --last-days $SENTRY_EVENT_RETENTION_DAYS $dcr web django backfill_eventstream --no-input --last-days $SENTRY_EVENT_RETENTION_DAYS
echo "" echo ""
cleanup cleanup