From 67b396b98cf52b4e0193bfaf565314712a3a2a53 Mon Sep 17 00:00:00 2001 From: Benedikt Franke Date: Mon, 7 Nov 2022 15:33:49 +0100 Subject: [PATCH 01/18] Reference paths relative to the current script or project root Before this PR: - some scripts change the current working directory and use relative paths - different approaches are taken to know which directory a script is running in - paths are sometimes relative, sometimes absolute, sometimes traversing directories After this PR: - scripts do neither change nor care much about the current working directory - a unified approach determines the directory of the current script - paths are always relative to the project root This should resolve an issue I already tried to fix with https://github.com/getsentry/self-hosted/pull/1798, where the contents of `./sentry` were not copied into the built container image, thus `enhance-image.sh` did not apply. --- _integration-test/custom-ca-roots/setup.sh | 10 ++--- _integration-test/custom-ca-roots/teardown.sh | 3 +- .../ensure-customizations-not-present.sh | 5 ++- .../ensure-customizations-work.sh | 5 ++- _integration-test/run.sh | 9 ++-- _unit-test/_test_setup.sh | 6 ++- _unit-test/create-docker-volumes-test.sh | 10 +++-- _unit-test/ensure-relay-credentials-test.sh | 15 ++++--- _unit-test/error-handling-test.sh | 10 +++-- _unit-test/geoip-test.sh | 10 +++-- clean.sh | 5 +-- install.sh | 41 ++++++++++--------- install/_lib.sh | 27 +++++------- install/build-docker-images.sh | 2 +- install/check-minimum-requirements.sh | 3 +- install/ensure-files-from-examples.sh | 2 +- install/ensure-relay-credentials.sh | 4 +- install/error-handling.sh | 9 ++-- install/geoip.sh | 8 +--- install/install-wal2json.sh | 13 +++--- scripts/bump-version.sh | 4 +- scripts/post-release.sh | 4 +- 22 files changed, 103 insertions(+), 102 deletions(-) diff --git a/_integration-test/custom-ca-roots/setup.sh b/_integration-test/custom-ca-roots/setup.sh index 7a844d11508..5c68a5c14b9 100755 --- a/_integration-test/custom-ca-roots/setup.sh +++ b/_integration-test/custom-ca-roots/setup.sh @@ -1,10 +1,8 @@ -#! /usr/bin/env bash set -e +export COMPOSE_FILE="$PROJECT_ROOT/docker-compose.yml:$PROJECT_ROOT/custom-ca-roots/docker-compose.test.yml" -export COMPOSE_FILE="../docker-compose.yml:./custom-ca-roots/docker-compose.test.yml" - -TEST_NGINX_CONF_PATH="./custom-ca-roots/nginx" -CUSTOM_CERTS_PATH="../certificates" +TEST_NGINX_CONF_PATH="$PROJECT_ROOT/custom-ca-roots/nginx" +CUSTOM_CERTS_PATH="$PROJECT_ROOT/certificates" # generate tightly constrained CA # NB: `-addext` requires LibreSSL 3.1.0+, or OpenSSL (brew install openssl) @@ -42,6 +40,6 @@ openssl req -x509 -newkey rsa:2048 -nodes -days 1 -keyout $TEST_NGINX_CONF_PATH/ # openssl x509 -in nginx/fake.test.crt -text -noout -cp ./custom-ca-roots/test.py ../sentry/test-custom-ca-roots.py +cp "$PROJECT_ROOT/custom-ca-roots/test.py" "$PROJECT_ROOT/sentry/test-custom-ca-roots.py" $dc up -d fixture-custom-ca-roots diff --git a/_integration-test/custom-ca-roots/teardown.sh b/_integration-test/custom-ca-roots/teardown.sh index 059f69b93b4..5bd001ac35a 100755 --- a/_integration-test/custom-ca-roots/teardown.sh +++ b/_integration-test/custom-ca-roots/teardown.sh @@ -1,4 +1,3 @@ -#!/usr/bin/env bash $dc rm -s -f -v fixture-custom-ca-roots -rm -f ../certificates/test-custom-ca-roots.crt ../sentry/test-custom-ca-roots.py +rm -f "$PROJECT_ROOT/certificates/test-custom-ca-roots.crt" "$PROJECT_ROOT/sentry/test-custom-ca-roots.py" unset COMPOSE_FILE diff --git a/_integration-test/ensure-customizations-not-present.sh b/_integration-test/ensure-customizations-not-present.sh index 99ae6ba039c..5fb5412e203 100755 --- a/_integration-test/ensure-customizations-not-present.sh +++ b/_integration-test/ensure-customizations-not-present.sh @@ -1,9 +1,10 @@ #!/usr/bin/env bash set -ex -source "$(dirname $0)/../install/_lib.sh" +SCRIPT_DIR=$( cd -- "$( dirname -- "${BASH_SOURCE[0]}" )" &> /dev/null && pwd ) +source "$SCRIPT_DIR/../install/_lib.sh" -source ../install/dc-detect-version.sh +source "$PROJECT_ROOT/install/dc-detect-version.sh" # Negated version of ensure-customizations-work.sh, make changes in sync echo "${_group}Ensure customizations not present" diff --git a/_integration-test/ensure-customizations-work.sh b/_integration-test/ensure-customizations-work.sh index 8c92c62c995..642f8770e3a 100755 --- a/_integration-test/ensure-customizations-work.sh +++ b/_integration-test/ensure-customizations-work.sh @@ -1,9 +1,10 @@ #!/usr/bin/env bash set -ex -source "$(dirname $0)/../install/_lib.sh" +SCRIPT_DIR=$( cd -- "$( dirname -- "${BASH_SOURCE[0]}" )" &> /dev/null && pwd ) +source "$SCRIPT_DIR/../install/_lib.sh" -source ../install/dc-detect-version.sh +source "$PROJECT_ROOT/install/dc-detect-version.sh" # Negated version of ensure-customizations-not-present.sh, make changes in sync echo "${_group}Ensure customizations work" diff --git a/_integration-test/run.sh b/_integration-test/run.sh index 198da9c409f..da4500e5001 100755 --- a/_integration-test/run.sh +++ b/_integration-test/run.sh @@ -1,9 +1,10 @@ #!/usr/bin/env bash set -ex -source "$(dirname $0)/../install/_lib.sh" +SCRIPT_DIR=$( cd -- "$( dirname -- "${BASH_SOURCE[0]}" )" &> /dev/null && pwd ) +source "$SCRIPT_DIR/../install/_lib.sh" -source ../install/dc-detect-version.sh +source "$PROJECT_ROOT/install/dc-detect-version.sh" echo "${_group}Setting up variables and helpers ..." export SENTRY_TEST_HOST="${SENTRY_TEST_HOST:-http://localhost:9000}" @@ -131,7 +132,7 @@ echo '------------------------------------------' echo "${_endgroup}" echo "${_group}Test custom CAs work ..." -source ./custom-ca-roots/setup.sh +source "$PROJECT_ROOT/_integration-test/custom-ca-roots/setup.sh" $dcr --no-deps web python3 /etc/sentry/test-custom-ca-roots.py -source ./custom-ca-roots/teardown.sh +source "$PROJECT_ROOT/_integration-test/custom-ca-roots/teardown.sh" echo "${_endgroup}" diff --git a/_unit-test/_test_setup.sh b/_unit-test/_test_setup.sh index 72222324ff2..1869bb04956 100644 --- a/_unit-test/_test_setup.sh +++ b/_unit-test/_test_setup.sh @@ -1,5 +1,7 @@ set -euo pipefail -source "$(dirname $0)/../install/_lib.sh" + +SCRIPT_DIR=$( cd -- "$( dirname -- "${BASH_SOURCE[0]}" )" &> /dev/null && pwd ) +source "$SCRIPT_DIR/../install/_lib.sh" rm -rf /tmp/sentry-self-hosted-test-sandbox.* _SANDBOX="$(mktemp -d /tmp/sentry-self-hosted-test-sandbox.XXX)" @@ -13,7 +15,7 @@ teardown() { } setup() { - cd .. + cd "$PROJECT_ROOT" # Clone the local repo into a temp dir. FWIW `git clone --local` breaks for # me because it depends on hard-linking, which doesn't work across devices, diff --git a/_unit-test/create-docker-volumes-test.sh b/_unit-test/create-docker-volumes-test.sh index ddc53d3aee0..5ce5bccd7c7 100755 --- a/_unit-test/create-docker-volumes-test.sh +++ b/_unit-test/create-docker-volumes-test.sh @@ -1,5 +1,7 @@ #!/usr/bin/env bash -source "$(dirname $0)/_test_setup.sh" + +SCRIPT_DIR=$( cd -- "$( dirname -- "${BASH_SOURCE[0]}" )" &> /dev/null && pwd ) +source "$SCRIPT_DIR/_test_setup.sh" get_volumes() { # If grep returns no strings, we still want to return without error @@ -20,9 +22,9 @@ before=$(get_volumes) test "$before" == "" || test "$before" == "$expected_volumes" -source create-docker-volumes.sh -source create-docker-volumes.sh -source create-docker-volumes.sh +source "$PROJECT_ROOT/install/create-docker-volumes.sh" +source "$PROJECT_ROOT/install/create-docker-volumes.sh" +source "$PROJECT_ROOT/install/create-docker-volumes.sh" after=$(get_volumes) test "$after" == "$expected_volumes" diff --git a/_unit-test/ensure-relay-credentials-test.sh b/_unit-test/ensure-relay-credentials-test.sh index fbc7bbf4316..dd9661f6ae8 100755 --- a/_unit-test/ensure-relay-credentials-test.sh +++ b/_unit-test/ensure-relay-credentials-test.sh @@ -1,17 +1,20 @@ #!/usr/bin/env bash -source "$(dirname $0)/_test_setup.sh" -source dc-detect-version.sh + +SCRIPT_DIR=$( cd -- "$( dirname -- "${BASH_SOURCE[0]}" )" &> /dev/null && pwd ) +source "$SCRIPT_DIR/_test_setup.sh" + +source "$PROJECT_ROOT/install/dc-detect-version.sh" # using _file format for these variables since there is a creds defined in dc-detect-version.sh -cfg_file="../relay/config.yml" -creds_file="../relay/credentials.json" +cfg_file="$PROJECT_ROOT/relay/config.yml" +creds_file="$PROJECT_ROOT/relay/credentials.json" # Relay files don't exist in a clean clone. test ! -f $cfg_file test ! -f $creds_file # Running the install script adds them. -source ensure-relay-credentials.sh +source "$PROJECT_ROOT/install/ensure-relay-credentials.sh" test -f $cfg_file test -f $creds_file test "$(jq -r 'keys[2]' $creds_file)" = "secret_key" @@ -19,7 +22,7 @@ test "$(jq -r 'keys[2]' $creds_file)" = "secret_key" # If the files exist we don't touch it. echo GARBAGE >$cfg_file echo MOAR GARBAGE >$creds_file -source ensure-relay-credentials.sh +source "$PROJECT_ROOT/install/ensure-relay-credentials.sh" test "$(cat $cfg_file)" = "GARBAGE" test "$(cat $creds_file)" = "MOAR GARBAGE" diff --git a/_unit-test/error-handling-test.sh b/_unit-test/error-handling-test.sh index e6e4990fde6..53026d135c8 100755 --- a/_unit-test/error-handling-test.sh +++ b/_unit-test/error-handling-test.sh @@ -1,9 +1,11 @@ #!/usr/bin/env bash -source "$(dirname $0)/_test_setup.sh" + +SCRIPT_DIR=$( cd -- "$( dirname -- "${BASH_SOURCE[0]}" )" &> /dev/null && pwd ) +source "$SCRIPT_DIR/_test_setup.sh" export REPORT_SELF_HOSTED_ISSUES=1 -source error-handling.sh +source "$PROJECT_ROOT/install/error-handling.sh" # mock send_envelope send_envelope() { @@ -12,7 +14,7 @@ send_envelope() { export -f send_envelope echo "Testing initial send_event" -export log_path="$basedir/test_log.txt" +export log_path="$PROJECT_ROOT/test_log.txt" echo "Test Logs" >"$log_path" echo "Error Msg" >>"$log_path" breadcrumbs=$(generate_breadcrumb_json | sed '$d' | jq -s -c) @@ -20,7 +22,7 @@ SEND_EVENT_RESPONSE=$(send_event "12345123451234512345123451234512" "Test exited rm "$log_path" test "$SEND_EVENT_RESPONSE" == 'Test Sending sentry-envelope-12345123451234512345123451234512' ENVELOPE_CONTENTS=$(cat /tmp/sentry-envelope-12345123451234512345123451234512) -test "$ENVELOPE_CONTENTS" == "$(cat "$basedir/_unit-test/snapshots/sentry-envelope-12345123451234512345123451234512")" +test "$ENVELOPE_CONTENTS" == "$(cat "$PROJECT_ROOT/_unit-test/snapshots/sentry-envelope-12345123451234512345123451234512")" echo "Pass." echo "Testing send_event duplicate" diff --git a/_unit-test/geoip-test.sh b/_unit-test/geoip-test.sh index 2244a43adcf..4b7153785f9 100755 --- a/_unit-test/geoip-test.sh +++ b/_unit-test/geoip-test.sh @@ -1,16 +1,18 @@ #!/usr/bin/env bash -source "$(dirname $0)/_test_setup.sh" -mmdb="../geoip/GeoLite2-City.mmdb" +SCRIPT_DIR=$( cd -- "$( dirname -- "${BASH_SOURCE[0]}" )" &> /dev/null && pwd ) +source "$SCRIPT_DIR/_test_setup.sh" + +mmdb="$PROJECT_ROOT/geoip/GeoLite2-City.mmdb" # Starts with no mmdb, ends up with empty. test ! -f $mmdb -source geoip.sh +source "$PROJECT_ROOT/install/geoip.sh" diff -rub $mmdb $mmdb.empty # Doesn't clobber existing, though. echo GARBAGE >$mmdb -source geoip.sh +source "$PROJECT_ROOT/install/geoip.sh" test "$(cat $mmdb)" = "GARBAGE" report_success diff --git a/clean.sh b/clean.sh index 7a66ed5d03c..b6f7880169f 100755 --- a/clean.sh +++ b/clean.sh @@ -9,9 +9,8 @@ if [ -n "${DEBUG:-}" ]; then set -x fi -cd "$(dirname $0)" - -source install/dc-detect-version.sh +SCRIPT_DIR=$( cd -- "$( dirname -- "${BASH_SOURCE[0]}" )" &> /dev/null && pwd ) +source "$SCRIPT_DIR/install/dc-detect-version.sh" function confirm() { read -p "$1 [y/n] " confirmation diff --git a/install.sh b/install.sh index c5b61124bb0..f4ac2874538 100755 --- a/install.sh +++ b/install.sh @@ -7,29 +7,30 @@ if [[ -n "$MSYSTEM" ]]; then exit 1 fi -source "$(dirname $0)/install/_lib.sh" # does a `cd .../install/`, among other things +SCRIPT_DIR=$( cd -- "$( dirname -- "${BASH_SOURCE[0]}" )" &> /dev/null && pwd ) +source "$SCRIPT_DIR/install/_lib.sh" # Pre-flight. No impact yet. -source parse-cli.sh -source detect-platform.sh -source dc-detect-version.sh -source error-handling.sh +source "$PROJECT_ROOT/install/parse-cli.sh" +source "$PROJECT_ROOT/install/detect-platform.sh" +source "$PROJECT_ROOT/install/dc-detect-version.sh" +source "$PROJECT_ROOT/install/error-handling.sh" # We set the trap at the top level so that we get better tracebacks. trap_with_arg cleanup ERR INT TERM EXIT -source check-latest-commit.sh -source check-minimum-requirements.sh +source "$PROJECT_ROOT/install/check-latest-commit.sh" +source "$PROJECT_ROOT/install/check-minimum-requirements.sh" # Let's go! Start impacting things. -source turn-things-off.sh -source create-docker-volumes.sh -source ensure-files-from-examples.sh -source ensure-relay-credentials.sh -source generate-secret-key.sh -source update-docker-images.sh -source build-docker-images.sh -source install-wal2json.sh -source bootstrap-snuba.sh -source create-kafka-topics.sh -source set-up-and-migrate-database.sh -source geoip.sh -source wrap-up.sh +source "$PROJECT_ROOT/install/turn-things-off.sh" +source "$PROJECT_ROOT/install/create-docker-volumes.sh" +source "$PROJECT_ROOT/install/ensure-files-from-examples.sh" +source "$PROJECT_ROOT/install/ensure-relay-credentials.sh" +source "$PROJECT_ROOT/install/generate-secret-key.sh" +source "$PROJECT_ROOT/install/update-docker-images.sh" +source "$PROJECT_ROOT/install/build-docker-images.sh" +source "$PROJECT_ROOT/install/install-wal2json.sh" +source "$PROJECT_ROOT/install/bootstrap-snuba.sh" +source "$PROJECT_ROOT/install/create-kafka-topics.sh" +source "$PROJECT_ROOT/install/set-up-and-migrate-database.sh" +source "$PROJECT_ROOT/install/geoip.sh" +source "$PROJECT_ROOT/install/wrap-up.sh" diff --git a/install/_lib.sh b/install/_lib.sh index 5ddbabd8b96..40ae7f7477e 100644 --- a/install/_lib.sh +++ b/install/_lib.sh @@ -1,30 +1,22 @@ set -euo pipefail test "${DEBUG:-}" && set -x +SCRIPT_DIR=$( cd -- "$( dirname -- "${BASH_SOURCE[0]}" )" &> /dev/null && pwd ) +PROJECT_ROOT="$( dirname "$SCRIPT_DIR" )" + # Override any user-supplied umask that could cause problems, see #1222 umask 002 # Thanks to https://unix.stackexchange.com/a/145654/108960 -log_file="sentry_install_log-$(date +'%Y-%m-%d_%H-%M-%S').txt" +log_file="$PROJECT_ROOT/sentry_install_log-$(date +'%Y-%m-%d_%H-%M-%S').txt" exec &> >(tee -a "$log_file") -# Work from /install/ for install.sh, project root otherwise -if [[ "$(basename $0)" = "install.sh" ]]; then - cd "$(dirname $0)/install/" -else - cd "$(dirname $0)" # assume we're a test script or some such -fi - # Allow `.env` overrides using the `.env.custom` file. # We pass this to docker compose in a couple places. -basedir="$( - cd .. - pwd -P -)" # realpath is missing on stock macOS -if [[ -f "$basedir/.env.custom" ]]; then - _ENV="$basedir/.env.custom" +if [[ -f "$PROJECT_ROOT/.env.custom" ]]; then + _ENV="$PROJECT_ROOT/.env.custom" else - _ENV="$basedir/.env" + _ENV="$PROJECT_ROOT/.env" fi # Read .env for default values with a tip o' the hat to https://stackoverflow.com/a/59831605/90297 @@ -49,8 +41,9 @@ function ensure_file_from_example { # sed from https://stackoverflow.com/a/25123013/90297 fi } -SENTRY_CONFIG_PY='../sentry/sentry.conf.py' -SENTRY_CONFIG_YML='../sentry/config.yml' + +SENTRY_CONFIG_PY="$PROJECT_ROOT/sentry/sentry.conf.py" +SENTRY_CONFIG_YML="$PROJECT_ROOT/sentry/config.yml" # Increase the default 10 second SIGTERM timeout # to ensure celery queues are properly drained diff --git a/install/build-docker-images.sh b/install/build-docker-images.sh index 7e96a2c17ef..4363def9d91 100644 --- a/install/build-docker-images.sh +++ b/install/build-docker-images.sh @@ -6,7 +6,7 @@ echo "" $dc build --build-arg "http_proxy=${http_proxy:-}" --build-arg "https_proxy=${https_proxy:-}" --build-arg "no_proxy=${no_proxy:-}" --force-rm web $dc build --build-arg "http_proxy=${http_proxy:-}" --build-arg "https_proxy=${https_proxy:-}" --build-arg "no_proxy=${no_proxy:-}" --force-rm # Used in error-handling.sh for error envelope payloads -docker build -t sentry-self-hosted-jq-local $basedir/jq +docker build -t sentry-self-hosted-jq-local "$PROJECT_ROOT/jq" echo "" echo "Docker images built." diff --git a/install/check-minimum-requirements.sh b/install/check-minimum-requirements.sh index 42cccf123b5..c40efcf5b07 100644 --- a/install/check-minimum-requirements.sh +++ b/install/check-minimum-requirements.sh @@ -1,6 +1,7 @@ echo "${_group}Checking minimum requirements ..." -source "$(dirname $0)/_min-requirements.sh" +SCRIPT_DIR=$( cd -- "$( dirname -- "${BASH_SOURCE[0]}" )" &> /dev/null && pwd ) +source "$SCRIPT_DIR/_min-requirements.sh" # Check the version of $1 is greater than or equal to $2 using sort. Note: versions must be stripped of "v" function vergte() { diff --git a/install/ensure-files-from-examples.sh b/install/ensure-files-from-examples.sh index f96f7caf638..5631e780e93 100644 --- a/install/ensure-files-from-examples.sh +++ b/install/ensure-files-from-examples.sh @@ -2,6 +2,6 @@ echo "${_group}Ensuring files from examples ..." ensure_file_from_example "$SENTRY_CONFIG_PY" ensure_file_from_example "$SENTRY_CONFIG_YML" -ensure_file_from_example '../symbolicator/config.yml' +ensure_file_from_example "$PROJECT_ROOT/symbolicator/config.yml" echo "${_endgroup}" diff --git a/install/ensure-relay-credentials.sh b/install/ensure-relay-credentials.sh index 6932e7444b6..16835c7ca66 100644 --- a/install/ensure-relay-credentials.sh +++ b/install/ensure-relay-credentials.sh @@ -1,7 +1,7 @@ echo "${_group}Ensuring Relay credentials ..." -RELAY_CONFIG_YML="../relay/config.yml" -RELAY_CREDENTIALS_JSON="../relay/credentials.json" +RELAY_CONFIG_YML="$PROJECT_ROOT/relay/config.yml" +RELAY_CREDENTIALS_JSON="$PROJECT_ROOT/relay/credentials.json" ensure_file_from_example $RELAY_CONFIG_YML diff --git a/install/error-handling.sh b/install/error-handling.sh index a3f34959e8a..0abcfc28959 100644 --- a/install/error-handling.sh +++ b/install/error-handling.sh @@ -6,7 +6,6 @@ export SENTRY_PROJECT=installer jq="docker run --rm -i sentry-self-hosted-jq-local" sentry_cli="docker run --rm -v /tmp:/work -e SENTRY_ORG=$SENTRY_ORG -e SENTRY_PROJECT=$SENTRY_PROJECT -e SENTRY_DSN=$SENTRY_DSN getsentry/sentry-cli" -log_path="$basedir/$log_file" send_envelope() { # Send envelope @@ -20,7 +19,7 @@ generate_breadcrumb_json() { --arg category log \ --arg level info \ '$ARGS.named' - done <$log_path + done <$log_file } send_event() { @@ -39,7 +38,7 @@ send_event() { # If we haven't sent the envelope file, make it and send to Sentry # The format is documented at https://develop.sentry.dev/sdk/envelopes/ # Grab length of log file, needed for the envelope header to send an attachment - local file_length=$(wc -c <$log_path | awk '{print $1}') + local file_length=$(wc -c <$log_file | awk '{print $1}') # Add header for initial envelope information jq -n -c --arg event_id "$event_hash" \ @@ -80,7 +79,7 @@ send_event() { '{"type": $type,"length": $length|tonumber,"content_type": $content_type,"filename": $filename}' ) echo "$attachment" >>$envelope_file_path - cat $log_path >>$envelope_file_path + cat $log_file >>$envelope_file_path # Send envelope send_envelope $envelope_file } @@ -169,7 +168,7 @@ cleanup() { if [[ "$1" != "EXIT" ]]; then set +o xtrace # Save the error message that comes from the last line of the log file - error_msg=$(tail -n 1 "$log_path") + error_msg=$(tail -n 1 "$log_file") # Create the breadcrumb payload now before stacktrace is printed # https://develop.sentry.dev/sdk/event-payloads/breadcrumbs/ # Use sed to remove the last line, that is reported through the error message diff --git a/install/geoip.sh b/install/geoip.sh index bc5d84b64a5..16a5730f0c5 100644 --- a/install/geoip.sh +++ b/install/geoip.sh @@ -1,10 +1,8 @@ echo "${_group}Setting up GeoIP integration ..." install_geoip() { - cd ../geoip - - local mmdb='GeoLite2-City.mmdb' - local conf='GeoIP.conf' + local mmdb="$PROJECT_ROOT/geoip/GeoLite2-City.mmdb" + local conf="$PROJECT_ROOT/geoip/GeoIP.conf" local result='Done' echo "Setting up IP address geolocation ..." @@ -29,8 +27,6 @@ install_geoip() { echo "$result updating IP address geolocation database." fi echo "$result setting up IP address geolocation." - - cd ../install } install_geoip diff --git a/install/install-wal2json.sh b/install/install-wal2json.sh index 8caa4019717..8e22d803dd7 100644 --- a/install/install-wal2json.sh +++ b/install/install-wal2json.sh @@ -1,6 +1,7 @@ echo "${_group}Downloading and installing wal2json ..." -FILE_TO_USE="../postgres/wal2json/wal2json.so" +WAL2JSON_DIR="$PROJECT_ROOT/postgres/wal2json" +FILE_TO_USE="$WAL2JSON_DIR/wal2json.so" ARCH=$(uname -m) FILE_NAME="wal2json-Linux-$ARCH-glibc.so" @@ -25,13 +26,13 @@ else VERSION=$WAL2JSON_VERSION fi -mkdir -p ../postgres/wal2json -if [ ! -f "../postgres/wal2json/$VERSION/$FILE_NAME" ]; then - mkdir -p "../postgres/wal2json/$VERSION" +mkdir -p "$WAL2JSON_DIR" +if [ ! -f "$WAL2JSON_DIR/$VERSION/$FILE_NAME" ]; then + mkdir -p "$WAL2JSON_DIR/$VERSION" docker_curl -L \ "https://github.com/getsentry/wal2json/releases/download/$VERSION/$FILE_NAME" \ - >"../postgres/wal2json/$VERSION/$FILE_NAME" + >"$WAL2JSON_DIR/$VERSION/$FILE_NAME" fi -cp "../postgres/wal2json/$VERSION/$FILE_NAME" "$FILE_TO_USE" +cp "$WAL2JSON_DIR/$VERSION/$FILE_NAME" "$FILE_TO_USE" echo "${_endgroup}" diff --git a/scripts/bump-version.sh b/scripts/bump-version.sh index 18f854ca9b5..3cd1b646f1b 100755 --- a/scripts/bump-version.sh +++ b/scripts/bump-version.sh @@ -1,8 +1,8 @@ #!/bin/bash set -eu -SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)" -cd $SCRIPT_DIR/.. +SCRIPT_DIR=$( cd -- "$( dirname -- "${BASH_SOURCE[0]}" )" &> /dev/null && pwd ) +cd "$SCRIPT_DIR/.." OLD_VERSION="$1" NEW_VERSION="$2" diff --git a/scripts/post-release.sh b/scripts/post-release.sh index 265543115d4..d03e93bef78 100755 --- a/scripts/post-release.sh +++ b/scripts/post-release.sh @@ -1,8 +1,8 @@ #!/bin/bash set -eu -SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)" -cd $SCRIPT_DIR/.. +SCRIPT_DIR=$( cd -- "$( dirname -- "${BASH_SOURCE[0]}" )" &> /dev/null && pwd ) +cd "$SCRIPT_DIR/.." # Bring master back to nightlies after merge from release branch git checkout master && git pull From 734c80f59fe26b9e372bcafdaaf5999d9c207a03 Mon Sep 17 00:00:00 2001 From: Benedikt Franke Date: Mon, 7 Nov 2022 15:38:38 +0100 Subject: [PATCH 02/18] Fix codestyle --- _integration-test/ensure-customizations-not-present.sh | 2 +- _integration-test/ensure-customizations-work.sh | 2 +- _integration-test/run.sh | 2 +- _unit-test/_test_setup.sh | 2 +- _unit-test/create-docker-volumes-test.sh | 2 +- _unit-test/ensure-relay-credentials-test.sh | 2 +- _unit-test/error-handling-test.sh | 2 +- _unit-test/geoip-test.sh | 2 +- clean.sh | 2 +- install.sh | 2 +- install/_lib.sh | 2 +- install/check-minimum-requirements.sh | 2 +- scripts/bump-version.sh | 2 +- scripts/post-release.sh | 2 +- 14 files changed, 14 insertions(+), 14 deletions(-) diff --git a/_integration-test/ensure-customizations-not-present.sh b/_integration-test/ensure-customizations-not-present.sh index 5fb5412e203..9dddb4d4445 100755 --- a/_integration-test/ensure-customizations-not-present.sh +++ b/_integration-test/ensure-customizations-not-present.sh @@ -1,7 +1,7 @@ #!/usr/bin/env bash set -ex -SCRIPT_DIR=$( cd -- "$( dirname -- "${BASH_SOURCE[0]}" )" &> /dev/null && pwd ) +SCRIPT_DIR=$(cd -- "$(dirname -- "${BASH_SOURCE[0]}")" &>/dev/null && pwd) source "$SCRIPT_DIR/../install/_lib.sh" source "$PROJECT_ROOT/install/dc-detect-version.sh" diff --git a/_integration-test/ensure-customizations-work.sh b/_integration-test/ensure-customizations-work.sh index 642f8770e3a..f5a008ec40d 100755 --- a/_integration-test/ensure-customizations-work.sh +++ b/_integration-test/ensure-customizations-work.sh @@ -1,7 +1,7 @@ #!/usr/bin/env bash set -ex -SCRIPT_DIR=$( cd -- "$( dirname -- "${BASH_SOURCE[0]}" )" &> /dev/null && pwd ) +SCRIPT_DIR=$(cd -- "$(dirname -- "${BASH_SOURCE[0]}")" &>/dev/null && pwd) source "$SCRIPT_DIR/../install/_lib.sh" source "$PROJECT_ROOT/install/dc-detect-version.sh" diff --git a/_integration-test/run.sh b/_integration-test/run.sh index da4500e5001..007c31757ba 100755 --- a/_integration-test/run.sh +++ b/_integration-test/run.sh @@ -1,7 +1,7 @@ #!/usr/bin/env bash set -ex -SCRIPT_DIR=$( cd -- "$( dirname -- "${BASH_SOURCE[0]}" )" &> /dev/null && pwd ) +SCRIPT_DIR=$(cd -- "$(dirname -- "${BASH_SOURCE[0]}")" &>/dev/null && pwd) source "$SCRIPT_DIR/../install/_lib.sh" source "$PROJECT_ROOT/install/dc-detect-version.sh" diff --git a/_unit-test/_test_setup.sh b/_unit-test/_test_setup.sh index 1869bb04956..04afd37793e 100644 --- a/_unit-test/_test_setup.sh +++ b/_unit-test/_test_setup.sh @@ -1,6 +1,6 @@ set -euo pipefail -SCRIPT_DIR=$( cd -- "$( dirname -- "${BASH_SOURCE[0]}" )" &> /dev/null && pwd ) +SCRIPT_DIR=$(cd -- "$(dirname -- "${BASH_SOURCE[0]}")" &>/dev/null && pwd) source "$SCRIPT_DIR/../install/_lib.sh" rm -rf /tmp/sentry-self-hosted-test-sandbox.* diff --git a/_unit-test/create-docker-volumes-test.sh b/_unit-test/create-docker-volumes-test.sh index 5ce5bccd7c7..ae620f7ba0f 100755 --- a/_unit-test/create-docker-volumes-test.sh +++ b/_unit-test/create-docker-volumes-test.sh @@ -1,6 +1,6 @@ #!/usr/bin/env bash -SCRIPT_DIR=$( cd -- "$( dirname -- "${BASH_SOURCE[0]}" )" &> /dev/null && pwd ) +SCRIPT_DIR=$(cd -- "$(dirname -- "${BASH_SOURCE[0]}")" &>/dev/null && pwd) source "$SCRIPT_DIR/_test_setup.sh" get_volumes() { diff --git a/_unit-test/ensure-relay-credentials-test.sh b/_unit-test/ensure-relay-credentials-test.sh index dd9661f6ae8..45e89f2f682 100755 --- a/_unit-test/ensure-relay-credentials-test.sh +++ b/_unit-test/ensure-relay-credentials-test.sh @@ -1,6 +1,6 @@ #!/usr/bin/env bash -SCRIPT_DIR=$( cd -- "$( dirname -- "${BASH_SOURCE[0]}" )" &> /dev/null && pwd ) +SCRIPT_DIR=$(cd -- "$(dirname -- "${BASH_SOURCE[0]}")" &>/dev/null && pwd) source "$SCRIPT_DIR/_test_setup.sh" source "$PROJECT_ROOT/install/dc-detect-version.sh" diff --git a/_unit-test/error-handling-test.sh b/_unit-test/error-handling-test.sh index 53026d135c8..781816c3727 100755 --- a/_unit-test/error-handling-test.sh +++ b/_unit-test/error-handling-test.sh @@ -1,6 +1,6 @@ #!/usr/bin/env bash -SCRIPT_DIR=$( cd -- "$( dirname -- "${BASH_SOURCE[0]}" )" &> /dev/null && pwd ) +SCRIPT_DIR=$(cd -- "$(dirname -- "${BASH_SOURCE[0]}")" &>/dev/null && pwd) source "$SCRIPT_DIR/_test_setup.sh" export REPORT_SELF_HOSTED_ISSUES=1 diff --git a/_unit-test/geoip-test.sh b/_unit-test/geoip-test.sh index 4b7153785f9..de842537750 100755 --- a/_unit-test/geoip-test.sh +++ b/_unit-test/geoip-test.sh @@ -1,6 +1,6 @@ #!/usr/bin/env bash -SCRIPT_DIR=$( cd -- "$( dirname -- "${BASH_SOURCE[0]}" )" &> /dev/null && pwd ) +SCRIPT_DIR=$(cd -- "$(dirname -- "${BASH_SOURCE[0]}")" &>/dev/null && pwd) source "$SCRIPT_DIR/_test_setup.sh" mmdb="$PROJECT_ROOT/geoip/GeoLite2-City.mmdb" diff --git a/clean.sh b/clean.sh index b6f7880169f..9598ba205e1 100755 --- a/clean.sh +++ b/clean.sh @@ -9,7 +9,7 @@ if [ -n "${DEBUG:-}" ]; then set -x fi -SCRIPT_DIR=$( cd -- "$( dirname -- "${BASH_SOURCE[0]}" )" &> /dev/null && pwd ) +SCRIPT_DIR=$(cd -- "$(dirname -- "${BASH_SOURCE[0]}")" &>/dev/null && pwd) source "$SCRIPT_DIR/install/dc-detect-version.sh" function confirm() { diff --git a/install.sh b/install.sh index f4ac2874538..f7c3bc76954 100755 --- a/install.sh +++ b/install.sh @@ -7,7 +7,7 @@ if [[ -n "$MSYSTEM" ]]; then exit 1 fi -SCRIPT_DIR=$( cd -- "$( dirname -- "${BASH_SOURCE[0]}" )" &> /dev/null && pwd ) +SCRIPT_DIR=$(cd -- "$(dirname -- "${BASH_SOURCE[0]}")" &>/dev/null && pwd) source "$SCRIPT_DIR/install/_lib.sh" # Pre-flight. No impact yet. diff --git a/install/_lib.sh b/install/_lib.sh index 40ae7f7477e..feeb1102c11 100644 --- a/install/_lib.sh +++ b/install/_lib.sh @@ -1,7 +1,7 @@ set -euo pipefail test "${DEBUG:-}" && set -x -SCRIPT_DIR=$( cd -- "$( dirname -- "${BASH_SOURCE[0]}" )" &> /dev/null && pwd ) +SCRIPT_DIR=$(cd -- "$(dirname -- "${BASH_SOURCE[0]}")" &>/dev/null && pwd) PROJECT_ROOT="$( dirname "$SCRIPT_DIR" )" # Override any user-supplied umask that could cause problems, see #1222 diff --git a/install/check-minimum-requirements.sh b/install/check-minimum-requirements.sh index c40efcf5b07..3b662314823 100644 --- a/install/check-minimum-requirements.sh +++ b/install/check-minimum-requirements.sh @@ -1,6 +1,6 @@ echo "${_group}Checking minimum requirements ..." -SCRIPT_DIR=$( cd -- "$( dirname -- "${BASH_SOURCE[0]}" )" &> /dev/null && pwd ) +SCRIPT_DIR=$(cd -- "$(dirname -- "${BASH_SOURCE[0]}")" &>/dev/null && pwd) source "$SCRIPT_DIR/_min-requirements.sh" # Check the version of $1 is greater than or equal to $2 using sort. Note: versions must be stripped of "v" diff --git a/scripts/bump-version.sh b/scripts/bump-version.sh index 3cd1b646f1b..8a08ef4595c 100755 --- a/scripts/bump-version.sh +++ b/scripts/bump-version.sh @@ -1,7 +1,7 @@ #!/bin/bash set -eu -SCRIPT_DIR=$( cd -- "$( dirname -- "${BASH_SOURCE[0]}" )" &> /dev/null && pwd ) +SCRIPT_DIR=$(cd -- "$(dirname -- "${BASH_SOURCE[0]}")" &>/dev/null && pwd) cd "$SCRIPT_DIR/.." OLD_VERSION="$1" diff --git a/scripts/post-release.sh b/scripts/post-release.sh index d03e93bef78..12af90818a6 100755 --- a/scripts/post-release.sh +++ b/scripts/post-release.sh @@ -1,7 +1,7 @@ #!/bin/bash set -eu -SCRIPT_DIR=$( cd -- "$( dirname -- "${BASH_SOURCE[0]}" )" &> /dev/null && pwd ) +SCRIPT_DIR=$(cd -- "$(dirname -- "${BASH_SOURCE[0]}")" &>/dev/null && pwd) cd "$SCRIPT_DIR/.." # Bring master back to nightlies after merge from release branch From 227e4ba8dd04a750ae1d1bd9a38858332ca7bd8e Mon Sep 17 00:00:00 2001 From: Benedikt Franke Date: Mon, 7 Nov 2022 15:40:34 +0100 Subject: [PATCH 03/18] Fix non-executables --- .pre-commit-config.yaml | 1 - _integration-test/custom-ca-roots/setup.sh | 0 _integration-test/custom-ca-roots/teardown.sh | 0 install/detect-platform.sh | 0 4 files changed, 1 deletion(-) mode change 100755 => 100644 _integration-test/custom-ca-roots/setup.sh mode change 100755 => 100644 _integration-test/custom-ca-roots/teardown.sh mode change 100755 => 100644 install/detect-platform.sh diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index 9e94a2051eb..c7c7b156fbd 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -16,7 +16,6 @@ hooks: - id: check-case-conflict - id: check-executables-have-shebangs - exclude: ^(install/|_unit-test/_test_setup.sh) - id: check-merge-conflict - id: check-symlinks - id: end-of-file-fixer diff --git a/_integration-test/custom-ca-roots/setup.sh b/_integration-test/custom-ca-roots/setup.sh old mode 100755 new mode 100644 diff --git a/_integration-test/custom-ca-roots/teardown.sh b/_integration-test/custom-ca-roots/teardown.sh old mode 100755 new mode 100644 diff --git a/install/detect-platform.sh b/install/detect-platform.sh old mode 100755 new mode 100644 From 4f5d50944daf7ef80a7c92c316ba9b7082432e42 Mon Sep 17 00:00:00 2001 From: Benedikt Franke Date: Mon, 7 Nov 2022 15:44:22 +0100 Subject: [PATCH 04/18] Fix codestyle --- install/_lib.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/install/_lib.sh b/install/_lib.sh index feeb1102c11..1354ec9b19c 100644 --- a/install/_lib.sh +++ b/install/_lib.sh @@ -2,7 +2,7 @@ set -euo pipefail test "${DEBUG:-}" && set -x SCRIPT_DIR=$(cd -- "$(dirname -- "${BASH_SOURCE[0]}")" &>/dev/null && pwd) -PROJECT_ROOT="$( dirname "$SCRIPT_DIR" )" +PROJECT_ROOT="$(dirname "$SCRIPT_DIR")" # Override any user-supplied umask that could cause problems, see #1222 umask 002 From a2ea0088ffbda051479742cd0b54a1d0f9757ece Mon Sep 17 00:00:00 2001 From: Benedikt Franke Date: Tue, 8 Nov 2022 14:26:21 +0100 Subject: [PATCH 05/18] Fix custom-ca-roots test --- _integration-test/custom-ca-roots/setup.sh | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/_integration-test/custom-ca-roots/setup.sh b/_integration-test/custom-ca-roots/setup.sh index 5c68a5c14b9..b954a61a31a 100644 --- a/_integration-test/custom-ca-roots/setup.sh +++ b/_integration-test/custom-ca-roots/setup.sh @@ -1,7 +1,7 @@ set -e -export COMPOSE_FILE="$PROJECT_ROOT/docker-compose.yml:$PROJECT_ROOT/custom-ca-roots/docker-compose.test.yml" +export COMPOSE_FILE="$PROJECT_ROOT/docker-compose.yml:$PROJECT_ROOT/_integration-test/custom-ca-roots/docker-compose.test.yml" -TEST_NGINX_CONF_PATH="$PROJECT_ROOT/custom-ca-roots/nginx" +TEST_NGINX_CONF_PATH="$PROJECT_ROOT/_integration-test/custom-ca-roots/nginx" CUSTOM_CERTS_PATH="$PROJECT_ROOT/certificates" # generate tightly constrained CA @@ -40,6 +40,6 @@ openssl req -x509 -newkey rsa:2048 -nodes -days 1 -keyout $TEST_NGINX_CONF_PATH/ # openssl x509 -in nginx/fake.test.crt -text -noout -cp "$PROJECT_ROOT/custom-ca-roots/test.py" "$PROJECT_ROOT/sentry/test-custom-ca-roots.py" +cp "$PROJECT_ROOT/_integration-test/custom-ca-roots/test.py" "$PROJECT_ROOT/sentry/test-custom-ca-roots.py" $dc up -d fixture-custom-ca-roots From 2ee767d42a394c245d8a51d1917b91aed4e86f77 Mon Sep 17 00:00:00 2001 From: Benedikt Franke Date: Tue, 8 Nov 2022 14:29:35 +0100 Subject: [PATCH 06/18] Fix log_path -> log_file --- _unit-test/error-handling-test.sh | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/_unit-test/error-handling-test.sh b/_unit-test/error-handling-test.sh index 781816c3727..74ae4f9af77 100755 --- a/_unit-test/error-handling-test.sh +++ b/_unit-test/error-handling-test.sh @@ -14,12 +14,12 @@ send_envelope() { export -f send_envelope echo "Testing initial send_event" -export log_path="$PROJECT_ROOT/test_log.txt" -echo "Test Logs" >"$log_path" -echo "Error Msg" >>"$log_path" +export log_file="$PROJECT_ROOT/test_log.txt" +echo "Test Logs" >"$log_file" +echo "Error Msg" >>"$log_file" breadcrumbs=$(generate_breadcrumb_json | sed '$d' | jq -s -c) SEND_EVENT_RESPONSE=$(send_event "12345123451234512345123451234512" "Test exited with status 1" "{\"ignore\": \"me\"}" "$breadcrumbs") -rm "$log_path" +rm "$log_file" test "$SEND_EVENT_RESPONSE" == 'Test Sending sentry-envelope-12345123451234512345123451234512' ENVELOPE_CONTENTS=$(cat /tmp/sentry-envelope-12345123451234512345123451234512) test "$ENVELOPE_CONTENTS" == "$(cat "$PROJECT_ROOT/_unit-test/snapshots/sentry-envelope-12345123451234512345123451234512")" @@ -35,9 +35,9 @@ echo "Testing cleanup without minimizing downtime" export REPORT_SELF_HOSTED_ISSUES=0 export MINIMIZE_DOWNTIME='' export dc=':' -echo "Test Logs" >"$log_path" +echo "Test Logs" >"$log_file" CLEANUP_RESPONSE=$(cleanup ERROR) -rm "$log_path" +rm "$log_file" test "$CLEANUP_RESPONSE" == 'Error in ./_unit-test/error-handling-test.sh:37. '\''local cmd="${BASH_COMMAND}"'\'' exited with status 0 @@ -47,9 +47,9 @@ echo "Pass." echo "Testing cleanup while minimizing downtime" export REPORT_SELF_HOSTED_ISSUES=0 export MINIMIZE_DOWNTIME=1 -echo "Test Logs" >"$log_path" +echo "Test Logs" >"$log_file" CLEANUP_RESPONSE=$(cleanup ERROR) -rm "$log_path" +rm "$log_file" test "$CLEANUP_RESPONSE" == 'Error in ./_unit-test/error-handling-test.sh:49. '\''local cmd="${BASH_COMMAND}"'\'' exited with status 0 From 1d59507d761e8b05ba30eefeba38fac7d8fa3ea1 Mon Sep 17 00:00:00 2001 From: Benedikt Franke Date: Tue, 8 Nov 2022 18:53:21 +0100 Subject: [PATCH 07/18] Update _unit-test/error-handling-test.sh Co-authored-by: Amin Vakil --- _unit-test/error-handling-test.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/_unit-test/error-handling-test.sh b/_unit-test/error-handling-test.sh index 74ae4f9af77..15fcf01dbf5 100755 --- a/_unit-test/error-handling-test.sh +++ b/_unit-test/error-handling-test.sh @@ -38,7 +38,7 @@ export dc=':' echo "Test Logs" >"$log_file" CLEANUP_RESPONSE=$(cleanup ERROR) rm "$log_file" -test "$CLEANUP_RESPONSE" == 'Error in ./_unit-test/error-handling-test.sh:37. +test "$CLEANUP_RESPONSE" == 'Error in ./_unit-test/error-handling-test.sh:24. '\''local cmd="${BASH_COMMAND}"'\'' exited with status 0 Cleaning up...' From 7292db720a721de2a4930e5ddd58732502eba932 Mon Sep 17 00:00:00 2001 From: Benedikt Franke Date: Thu, 10 Nov 2022 10:05:15 +0100 Subject: [PATCH 08/18] All paths relative to project root --- _integration-test/custom-ca-roots/setup.sh | 8 ++-- _integration-test/custom-ca-roots/teardown.sh | 2 +- .../ensure-customizations-not-present.sh | 6 +-- .../ensure-customizations-work.sh | 6 +-- _integration-test/run.sh | 10 ++--- _unit-test/_test_setup.sh | 12 +++--- _unit-test/create-docker-volumes-test.sh | 9 ++-- _unit-test/ensure-relay-credentials-test.sh | 14 +++---- _unit-test/error-handling-test.sh | 13 +++--- _unit-test/geoip-test.sh | 9 ++-- clean.sh | 3 +- install.sh | 41 +++++++++---------- install/_lib.sh | 15 +++---- install/build-docker-images.sh | 2 +- install/check-minimum-requirements.sh | 3 +- install/ensure-files-from-examples.sh | 2 +- install/ensure-relay-credentials.sh | 4 +- install/geoip.sh | 4 +- install/install-wal2json.sh | 2 +- integration-test.sh | 8 ++-- reset.sh | 1 + scripts/bump-version.sh | 3 -- scripts/post-release.sh | 3 -- test.sh | 2 +- unit-test.sh | 5 ++- 25 files changed, 83 insertions(+), 104 deletions(-) diff --git a/_integration-test/custom-ca-roots/setup.sh b/_integration-test/custom-ca-roots/setup.sh index b954a61a31a..7cb6dd4fcf0 100644 --- a/_integration-test/custom-ca-roots/setup.sh +++ b/_integration-test/custom-ca-roots/setup.sh @@ -1,8 +1,8 @@ set -e -export COMPOSE_FILE="$PROJECT_ROOT/docker-compose.yml:$PROJECT_ROOT/_integration-test/custom-ca-roots/docker-compose.test.yml" +export COMPOSE_FILE=docker-compose.yml:_integration-test/custom-ca-roots/docker-compose.test.yml -TEST_NGINX_CONF_PATH="$PROJECT_ROOT/_integration-test/custom-ca-roots/nginx" -CUSTOM_CERTS_PATH="$PROJECT_ROOT/certificates" +TEST_NGINX_CONF_PATH=_integration-test/custom-ca-roots/nginx +CUSTOM_CERTS_PATH=certificates # generate tightly constrained CA # NB: `-addext` requires LibreSSL 3.1.0+, or OpenSSL (brew install openssl) @@ -40,6 +40,6 @@ openssl req -x509 -newkey rsa:2048 -nodes -days 1 -keyout $TEST_NGINX_CONF_PATH/ # openssl x509 -in nginx/fake.test.crt -text -noout -cp "$PROJECT_ROOT/_integration-test/custom-ca-roots/test.py" "$PROJECT_ROOT/sentry/test-custom-ca-roots.py" +cp _integration-test/custom-ca-roots/test.py sentry/test-custom-ca-roots.py $dc up -d fixture-custom-ca-roots diff --git a/_integration-test/custom-ca-roots/teardown.sh b/_integration-test/custom-ca-roots/teardown.sh index 5bd001ac35a..8b89299666e 100644 --- a/_integration-test/custom-ca-roots/teardown.sh +++ b/_integration-test/custom-ca-roots/teardown.sh @@ -1,3 +1,3 @@ $dc rm -s -f -v fixture-custom-ca-roots -rm -f "$PROJECT_ROOT/certificates/test-custom-ca-roots.crt" "$PROJECT_ROOT/sentry/test-custom-ca-roots.py" +rm -f certificates/test-custom-ca-roots.crt sentry/test-custom-ca-roots.py unset COMPOSE_FILE diff --git a/_integration-test/ensure-customizations-not-present.sh b/_integration-test/ensure-customizations-not-present.sh index 9dddb4d4445..78939ae6a06 100755 --- a/_integration-test/ensure-customizations-not-present.sh +++ b/_integration-test/ensure-customizations-not-present.sh @@ -1,10 +1,8 @@ #!/usr/bin/env bash set -ex -SCRIPT_DIR=$(cd -- "$(dirname -- "${BASH_SOURCE[0]}")" &>/dev/null && pwd) -source "$SCRIPT_DIR/../install/_lib.sh" - -source "$PROJECT_ROOT/install/dc-detect-version.sh" +source install/_lib.sh +source install/dc-detect-version.sh # Negated version of ensure-customizations-work.sh, make changes in sync echo "${_group}Ensure customizations not present" diff --git a/_integration-test/ensure-customizations-work.sh b/_integration-test/ensure-customizations-work.sh index f5a008ec40d..674cf0710aa 100755 --- a/_integration-test/ensure-customizations-work.sh +++ b/_integration-test/ensure-customizations-work.sh @@ -1,10 +1,8 @@ #!/usr/bin/env bash set -ex -SCRIPT_DIR=$(cd -- "$(dirname -- "${BASH_SOURCE[0]}")" &>/dev/null && pwd) -source "$SCRIPT_DIR/../install/_lib.sh" - -source "$PROJECT_ROOT/install/dc-detect-version.sh" +source install/_lib.sh +source install/dc-detect-version.sh # Negated version of ensure-customizations-not-present.sh, make changes in sync echo "${_group}Ensure customizations work" diff --git a/_integration-test/run.sh b/_integration-test/run.sh index 007c31757ba..49824a2bf24 100755 --- a/_integration-test/run.sh +++ b/_integration-test/run.sh @@ -1,10 +1,8 @@ #!/usr/bin/env bash set -ex -SCRIPT_DIR=$(cd -- "$(dirname -- "${BASH_SOURCE[0]}")" &>/dev/null && pwd) -source "$SCRIPT_DIR/../install/_lib.sh" - -source "$PROJECT_ROOT/install/dc-detect-version.sh" +source install/_lib.sh +source install/dc-detect-version.sh echo "${_group}Setting up variables and helpers ..." export SENTRY_TEST_HOST="${SENTRY_TEST_HOST:-http://localhost:9000}" @@ -132,7 +130,7 @@ echo '------------------------------------------' echo "${_endgroup}" echo "${_group}Test custom CAs work ..." -source "$PROJECT_ROOT/_integration-test/custom-ca-roots/setup.sh" +source _integration-test/custom-ca-roots/setup.sh $dcr --no-deps web python3 /etc/sentry/test-custom-ca-roots.py -source "$PROJECT_ROOT/_integration-test/custom-ca-roots/teardown.sh" +source _integration-test/custom-ca-roots/teardown.sh echo "${_endgroup}" diff --git a/_unit-test/_test_setup.sh b/_unit-test/_test_setup.sh index 04afd37793e..5762b59dea6 100644 --- a/_unit-test/_test_setup.sh +++ b/_unit-test/_test_setup.sh @@ -1,7 +1,8 @@ set -euo pipefail -SCRIPT_DIR=$(cd -- "$(dirname -- "${BASH_SOURCE[0]}")" &>/dev/null && pwd) -source "$SCRIPT_DIR/../install/_lib.sh" +source install/_lib.sh + +_ORIGIN=$(pwd) rm -rf /tmp/sentry-self-hosted-test-sandbox.* _SANDBOX="$(mktemp -d /tmp/sentry-self-hosted-test-sandbox.XXX)" @@ -12,15 +13,14 @@ report_success() { teardown() { test "${DEBUG:-}" || rm -rf "$_SANDBOX" + cd "$_ORIGIN" } setup() { - cd "$PROJECT_ROOT" - # Clone the local repo into a temp dir. FWIW `git clone --local` breaks for # me because it depends on hard-linking, which doesn't work across devices, # and I happen to have my workspace and /tmp on separate devices. - git -c advice.detachedHead=false clone --depth=1 "file://$(pwd)" "$_SANDBOX" + git -c advice.detachedHead=false clone --depth=1 "file://$_ORIGIN" "$_SANDBOX" # Now propagate any local changes from the working copy to the sandbox. This # provides a pretty nice dev experience: edit the files in the working copy, @@ -46,7 +46,7 @@ setup() { esac done - cd "$_SANDBOX/install" + cd "$_SANDBOX" trap teardown EXIT } diff --git a/_unit-test/create-docker-volumes-test.sh b/_unit-test/create-docker-volumes-test.sh index ae620f7ba0f..88931964e34 100755 --- a/_unit-test/create-docker-volumes-test.sh +++ b/_unit-test/create-docker-volumes-test.sh @@ -1,7 +1,6 @@ #!/usr/bin/env bash -SCRIPT_DIR=$(cd -- "$(dirname -- "${BASH_SOURCE[0]}")" &>/dev/null && pwd) -source "$SCRIPT_DIR/_test_setup.sh" +source _unit-test/_test_setup.sh get_volumes() { # If grep returns no strings, we still want to return without error @@ -22,9 +21,9 @@ before=$(get_volumes) test "$before" == "" || test "$before" == "$expected_volumes" -source "$PROJECT_ROOT/install/create-docker-volumes.sh" -source "$PROJECT_ROOT/install/create-docker-volumes.sh" -source "$PROJECT_ROOT/install/create-docker-volumes.sh" +source install/create-docker-volumes.sh +source install/create-docker-volumes.sh +source install/create-docker-volumes.sh after=$(get_volumes) test "$after" == "$expected_volumes" diff --git a/_unit-test/ensure-relay-credentials-test.sh b/_unit-test/ensure-relay-credentials-test.sh index 45e89f2f682..f5e110e86e8 100755 --- a/_unit-test/ensure-relay-credentials-test.sh +++ b/_unit-test/ensure-relay-credentials-test.sh @@ -1,20 +1,18 @@ #!/usr/bin/env bash -SCRIPT_DIR=$(cd -- "$(dirname -- "${BASH_SOURCE[0]}")" &>/dev/null && pwd) -source "$SCRIPT_DIR/_test_setup.sh" - -source "$PROJECT_ROOT/install/dc-detect-version.sh" +source _unit-test/_test_setup.sh +source install/dc-detect-version.sh # using _file format for these variables since there is a creds defined in dc-detect-version.sh -cfg_file="$PROJECT_ROOT/relay/config.yml" -creds_file="$PROJECT_ROOT/relay/credentials.json" +cfg_file=relay/config.yml +creds_file=relay/credentials.json # Relay files don't exist in a clean clone. test ! -f $cfg_file test ! -f $creds_file # Running the install script adds them. -source "$PROJECT_ROOT/install/ensure-relay-credentials.sh" +source install/ensure-relay-credentials.sh test -f $cfg_file test -f $creds_file test "$(jq -r 'keys[2]' $creds_file)" = "secret_key" @@ -22,7 +20,7 @@ test "$(jq -r 'keys[2]' $creds_file)" = "secret_key" # If the files exist we don't touch it. echo GARBAGE >$cfg_file echo MOAR GARBAGE >$creds_file -source "$PROJECT_ROOT/install/ensure-relay-credentials.sh" +source install/ensure-relay-credentials.sh test "$(cat $cfg_file)" = "GARBAGE" test "$(cat $creds_file)" = "MOAR GARBAGE" diff --git a/_unit-test/error-handling-test.sh b/_unit-test/error-handling-test.sh index 15fcf01dbf5..864b6989b8a 100755 --- a/_unit-test/error-handling-test.sh +++ b/_unit-test/error-handling-test.sh @@ -1,11 +1,10 @@ #!/usr/bin/env bash -SCRIPT_DIR=$(cd -- "$(dirname -- "${BASH_SOURCE[0]}")" &>/dev/null && pwd) -source "$SCRIPT_DIR/_test_setup.sh" +source _unit-test/_test_setup.sh export REPORT_SELF_HOSTED_ISSUES=1 -source "$PROJECT_ROOT/install/error-handling.sh" +source install/error-handling.sh # mock send_envelope send_envelope() { @@ -14,7 +13,7 @@ send_envelope() { export -f send_envelope echo "Testing initial send_event" -export log_file="$PROJECT_ROOT/test_log.txt" +export log_file=test_log.txt echo "Test Logs" >"$log_file" echo "Error Msg" >>"$log_file" breadcrumbs=$(generate_breadcrumb_json | sed '$d' | jq -s -c) @@ -22,7 +21,7 @@ SEND_EVENT_RESPONSE=$(send_event "12345123451234512345123451234512" "Test exited rm "$log_file" test "$SEND_EVENT_RESPONSE" == 'Test Sending sentry-envelope-12345123451234512345123451234512' ENVELOPE_CONTENTS=$(cat /tmp/sentry-envelope-12345123451234512345123451234512) -test "$ENVELOPE_CONTENTS" == "$(cat "$PROJECT_ROOT/_unit-test/snapshots/sentry-envelope-12345123451234512345123451234512")" +test "$ENVELOPE_CONTENTS" == "$(cat _unit-test/snapshots/sentry-envelope-12345123451234512345123451234512)" echo "Pass." echo "Testing send_event duplicate" @@ -38,7 +37,7 @@ export dc=':' echo "Test Logs" >"$log_file" CLEANUP_RESPONSE=$(cleanup ERROR) rm "$log_file" -test "$CLEANUP_RESPONSE" == 'Error in ./_unit-test/error-handling-test.sh:24. +test "$CLEANUP_RESPONSE" == 'Error in ./_unit-test/error-handling-test.sh:38. '\''local cmd="${BASH_COMMAND}"'\'' exited with status 0 Cleaning up...' @@ -50,7 +49,7 @@ export MINIMIZE_DOWNTIME=1 echo "Test Logs" >"$log_file" CLEANUP_RESPONSE=$(cleanup ERROR) rm "$log_file" -test "$CLEANUP_RESPONSE" == 'Error in ./_unit-test/error-handling-test.sh:49. +test "$CLEANUP_RESPONSE" == 'Error in ./_unit-test/error-handling-test.sh:50. '\''local cmd="${BASH_COMMAND}"'\'' exited with status 0 *NOT* cleaning up, to clean your environment run "docker compose stop".' diff --git a/_unit-test/geoip-test.sh b/_unit-test/geoip-test.sh index de842537750..64a78c783b5 100755 --- a/_unit-test/geoip-test.sh +++ b/_unit-test/geoip-test.sh @@ -1,18 +1,17 @@ #!/usr/bin/env bash -SCRIPT_DIR=$(cd -- "$(dirname -- "${BASH_SOURCE[0]}")" &>/dev/null && pwd) -source "$SCRIPT_DIR/_test_setup.sh" +source _unit-test/_test_setup.sh -mmdb="$PROJECT_ROOT/geoip/GeoLite2-City.mmdb" +mmdb=geoip/GeoLite2-City.mmdb # Starts with no mmdb, ends up with empty. test ! -f $mmdb -source "$PROJECT_ROOT/install/geoip.sh" +source install/geoip.sh diff -rub $mmdb $mmdb.empty # Doesn't clobber existing, though. echo GARBAGE >$mmdb -source "$PROJECT_ROOT/install/geoip.sh" +source install/geoip.sh test "$(cat $mmdb)" = "GARBAGE" report_success diff --git a/clean.sh b/clean.sh index 9598ba205e1..062f00f7434 100755 --- a/clean.sh +++ b/clean.sh @@ -9,8 +9,7 @@ if [ -n "${DEBUG:-}" ]; then set -x fi -SCRIPT_DIR=$(cd -- "$(dirname -- "${BASH_SOURCE[0]}")" &>/dev/null && pwd) -source "$SCRIPT_DIR/install/dc-detect-version.sh" +source install/dc-detect-version.sh function confirm() { read -p "$1 [y/n] " confirmation diff --git a/install.sh b/install.sh index f7c3bc76954..c9f8674e52b 100755 --- a/install.sh +++ b/install.sh @@ -7,30 +7,29 @@ if [[ -n "$MSYSTEM" ]]; then exit 1 fi -SCRIPT_DIR=$(cd -- "$(dirname -- "${BASH_SOURCE[0]}")" &>/dev/null && pwd) -source "$SCRIPT_DIR/install/_lib.sh" +source install/_lib.sh # Pre-flight. No impact yet. -source "$PROJECT_ROOT/install/parse-cli.sh" -source "$PROJECT_ROOT/install/detect-platform.sh" -source "$PROJECT_ROOT/install/dc-detect-version.sh" -source "$PROJECT_ROOT/install/error-handling.sh" +source install/parse-cli.sh +source install/detect-platform.sh +source install/dc-detect-version.sh +source install/error-handling.sh # We set the trap at the top level so that we get better tracebacks. trap_with_arg cleanup ERR INT TERM EXIT -source "$PROJECT_ROOT/install/check-latest-commit.sh" -source "$PROJECT_ROOT/install/check-minimum-requirements.sh" +source install/check-latest-commit.sh +source install/check-minimum-requirements.sh # Let's go! Start impacting things. -source "$PROJECT_ROOT/install/turn-things-off.sh" -source "$PROJECT_ROOT/install/create-docker-volumes.sh" -source "$PROJECT_ROOT/install/ensure-files-from-examples.sh" -source "$PROJECT_ROOT/install/ensure-relay-credentials.sh" -source "$PROJECT_ROOT/install/generate-secret-key.sh" -source "$PROJECT_ROOT/install/update-docker-images.sh" -source "$PROJECT_ROOT/install/build-docker-images.sh" -source "$PROJECT_ROOT/install/install-wal2json.sh" -source "$PROJECT_ROOT/install/bootstrap-snuba.sh" -source "$PROJECT_ROOT/install/create-kafka-topics.sh" -source "$PROJECT_ROOT/install/set-up-and-migrate-database.sh" -source "$PROJECT_ROOT/install/geoip.sh" -source "$PROJECT_ROOT/install/wrap-up.sh" +source install/turn-things-off.sh +source install/create-docker-volumes.sh +source install/ensure-files-from-examples.sh +source install/ensure-relay-credentials.sh +source install/generate-secret-key.sh +source install/update-docker-images.sh +source install/build-docker-images.sh +source install/install-wal2json.sh +source install/bootstrap-snuba.sh +source install/create-kafka-topics.sh +source install/set-up-and-migrate-database.sh +source install/geoip.sh +source install/wrap-up.sh diff --git a/install/_lib.sh b/install/_lib.sh index 1354ec9b19c..69d5645fcad 100644 --- a/install/_lib.sh +++ b/install/_lib.sh @@ -1,22 +1,19 @@ set -euo pipefail test "${DEBUG:-}" && set -x -SCRIPT_DIR=$(cd -- "$(dirname -- "${BASH_SOURCE[0]}")" &>/dev/null && pwd) -PROJECT_ROOT="$(dirname "$SCRIPT_DIR")" - # Override any user-supplied umask that could cause problems, see #1222 umask 002 # Thanks to https://unix.stackexchange.com/a/145654/108960 -log_file="$PROJECT_ROOT/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") # Allow `.env` overrides using the `.env.custom` file. # We pass this to docker compose in a couple places. -if [[ -f "$PROJECT_ROOT/.env.custom" ]]; then - _ENV="$PROJECT_ROOT/.env.custom" +if [[ -f .env.custom ]]; then + _ENV=.env.custom else - _ENV="$PROJECT_ROOT/.env" + _ENV=.env fi # Read .env for default values with a tip o' the hat to https://stackoverflow.com/a/59831605/90297 @@ -42,8 +39,8 @@ function ensure_file_from_example { fi } -SENTRY_CONFIG_PY="$PROJECT_ROOT/sentry/sentry.conf.py" -SENTRY_CONFIG_YML="$PROJECT_ROOT/sentry/config.yml" +SENTRY_CONFIG_PY=sentry/sentry.conf.py +SENTRY_CONFIG_YML=sentry/config.yml # Increase the default 10 second SIGTERM timeout # to ensure celery queues are properly drained diff --git a/install/build-docker-images.sh b/install/build-docker-images.sh index 4363def9d91..73b65123703 100644 --- a/install/build-docker-images.sh +++ b/install/build-docker-images.sh @@ -6,7 +6,7 @@ echo "" $dc build --build-arg "http_proxy=${http_proxy:-}" --build-arg "https_proxy=${https_proxy:-}" --build-arg "no_proxy=${no_proxy:-}" --force-rm web $dc build --build-arg "http_proxy=${http_proxy:-}" --build-arg "https_proxy=${https_proxy:-}" --build-arg "no_proxy=${no_proxy:-}" --force-rm # Used in error-handling.sh for error envelope payloads -docker build -t sentry-self-hosted-jq-local "$PROJECT_ROOT/jq" +docker build -t sentry-self-hosted-jq-local jq echo "" echo "Docker images built." diff --git a/install/check-minimum-requirements.sh b/install/check-minimum-requirements.sh index 3b662314823..40f9c9166f2 100644 --- a/install/check-minimum-requirements.sh +++ b/install/check-minimum-requirements.sh @@ -1,7 +1,6 @@ echo "${_group}Checking minimum requirements ..." -SCRIPT_DIR=$(cd -- "$(dirname -- "${BASH_SOURCE[0]}")" &>/dev/null && pwd) -source "$SCRIPT_DIR/_min-requirements.sh" +source install/_min-requirements.sh # Check the version of $1 is greater than or equal to $2 using sort. Note: versions must be stripped of "v" function vergte() { diff --git a/install/ensure-files-from-examples.sh b/install/ensure-files-from-examples.sh index 5631e780e93..97a7ed9f48f 100644 --- a/install/ensure-files-from-examples.sh +++ b/install/ensure-files-from-examples.sh @@ -2,6 +2,6 @@ echo "${_group}Ensuring files from examples ..." ensure_file_from_example "$SENTRY_CONFIG_PY" ensure_file_from_example "$SENTRY_CONFIG_YML" -ensure_file_from_example "$PROJECT_ROOT/symbolicator/config.yml" +ensure_file_from_example symbolicator/config.yml echo "${_endgroup}" diff --git a/install/ensure-relay-credentials.sh b/install/ensure-relay-credentials.sh index 16835c7ca66..d1eaaa2baae 100644 --- a/install/ensure-relay-credentials.sh +++ b/install/ensure-relay-credentials.sh @@ -1,7 +1,7 @@ echo "${_group}Ensuring Relay credentials ..." -RELAY_CONFIG_YML="$PROJECT_ROOT/relay/config.yml" -RELAY_CREDENTIALS_JSON="$PROJECT_ROOT/relay/credentials.json" +RELAY_CONFIG_YML=relay/config.yml +RELAY_CREDENTIALS_JSON=relay/credentials.json ensure_file_from_example $RELAY_CONFIG_YML diff --git a/install/geoip.sh b/install/geoip.sh index 16a5730f0c5..577b6ba5ca5 100644 --- a/install/geoip.sh +++ b/install/geoip.sh @@ -1,8 +1,8 @@ echo "${_group}Setting up GeoIP integration ..." install_geoip() { - local mmdb="$PROJECT_ROOT/geoip/GeoLite2-City.mmdb" - local conf="$PROJECT_ROOT/geoip/GeoIP.conf" + local mmdb=geoip/GeoLite2-City.mmdb + local conf=geoip/GeoIP.conf local result='Done' echo "Setting up IP address geolocation ..." diff --git a/install/install-wal2json.sh b/install/install-wal2json.sh index 8e22d803dd7..c9bec4864f6 100644 --- a/install/install-wal2json.sh +++ b/install/install-wal2json.sh @@ -1,6 +1,6 @@ echo "${_group}Downloading and installing wal2json ..." -WAL2JSON_DIR="$PROJECT_ROOT/postgres/wal2json" +WAL2JSON_DIR=postgres/wal2json FILE_TO_USE="$WAL2JSON_DIR/wal2json.so" ARCH=$(uname -m) FILE_NAME="wal2json-Linux-$ARCH-glibc.so" diff --git a/integration-test.sh b/integration-test.sh index a4ebb488dea..68ff0dfd71b 100755 --- a/integration-test.sh +++ b/integration-test.sh @@ -8,8 +8,8 @@ export REPORT_SELF_HOSTED_ISSUES=0 echo "Testing initial install" ./install.sh -./_integration-test/run.sh -./_integration-test/ensure-customizations-not-present.sh +_integration-test/run.sh +_integration-test/ensure-customizations-not-present.sh echo "Make customizations" cat <sentry/enhance-image.sh @@ -23,5 +23,5 @@ printf "python-ldap" >sentry/requirements.txt echo "Testing in-place upgrade and customizations" ./install.sh --minimize-downtime -./_integration-test/run.sh -./_integration-test/ensure-customizations-work.sh +_integration-test/run.sh +_integration-test/ensure-customizations-work.sh diff --git a/reset.sh b/reset.sh index f8378f79634..5c87afdf293 100755 --- a/reset.sh +++ b/reset.sh @@ -1,3 +1,4 @@ #!/usr/bin/env bash + ./clean.sh "$1" ./install.sh diff --git a/scripts/bump-version.sh b/scripts/bump-version.sh index 8a08ef4595c..b6a1000beec 100755 --- a/scripts/bump-version.sh +++ b/scripts/bump-version.sh @@ -1,9 +1,6 @@ #!/bin/bash set -eu -SCRIPT_DIR=$(cd -- "$(dirname -- "${BASH_SOURCE[0]}")" &>/dev/null && pwd) -cd "$SCRIPT_DIR/.." - OLD_VERSION="$1" NEW_VERSION="$2" diff --git a/scripts/post-release.sh b/scripts/post-release.sh index 12af90818a6..9501ac4e4ec 100755 --- a/scripts/post-release.sh +++ b/scripts/post-release.sh @@ -1,9 +1,6 @@ #!/bin/bash set -eu -SCRIPT_DIR=$(cd -- "$(dirname -- "${BASH_SOURCE[0]}")" &>/dev/null && pwd) -cd "$SCRIPT_DIR/.." - # Bring master back to nightlies after merge from release branch git checkout master && git pull SYMBOLICATOR_VERSION=nightly ./scripts/bump-version.sh '' 'nightly' diff --git a/test.sh b/test.sh index 0f90fd5dfac..c7831de3a6b 100755 --- a/test.sh +++ b/test.sh @@ -3,4 +3,4 @@ set -e # This file runs in https://github.com/getsentry/sentry/blob/fe4795f5eae9e0d7c33e0ecb736c9d1369535eca/docker/cloudbuild.yaml#L59 -./_integration-test/run.sh +_integration-test/run.sh diff --git a/unit-test.sh b/unit-test.sh index fe15a429223..383b90a0e58 100755 --- a/unit-test.sh +++ b/unit-test.sh @@ -1,7 +1,8 @@ #!/usr/bin/env bash -FORCE_CLEAN=1 "$(dirname $0)/clean.sh" + +FORCE_CLEAN=1 "./clean.sh" fail=0 -for test_file in ./_unit-test/*-test.sh; do +for test_file in _unit-test/*-test.sh; do echo "🙈 Running $test_file ..." $test_file if [ $? != 0 ]; then From 428a2c1cd833b1940c33e17483544ee8247cc580 Mon Sep 17 00:00:00 2001 From: Benedikt Franke Date: Thu, 10 Nov 2022 10:31:43 +0100 Subject: [PATCH 09/18] Quote jq arguments --- _unit-test/ensure-relay-credentials-test.sh | 2 +- install/error-handling.sh | 10 +++++----- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/_unit-test/ensure-relay-credentials-test.sh b/_unit-test/ensure-relay-credentials-test.sh index f5e110e86e8..e116675a802 100755 --- a/_unit-test/ensure-relay-credentials-test.sh +++ b/_unit-test/ensure-relay-credentials-test.sh @@ -15,7 +15,7 @@ test ! -f $creds_file source install/ensure-relay-credentials.sh test -f $cfg_file test -f $creds_file -test "$(jq -r 'keys[2]' $creds_file)" = "secret_key" +test "$(jq -r 'keys[2]' "$creds_file")" = "secret_key" # If the files exist we don't touch it. echo GARBAGE >$cfg_file diff --git a/install/error-handling.sh b/install/error-handling.sh index 0abcfc28959..9ef29ead229 100644 --- a/install/error-handling.sh +++ b/install/error-handling.sh @@ -43,9 +43,9 @@ send_event() { # Add header for initial envelope information jq -n -c --arg event_id "$event_hash" \ --arg dsn "$SENTRY_DSN" \ - '$ARGS.named' >$envelope_file_path + '$ARGS.named' >"$envelope_file_path" # Add header to specify the event type of envelope to be sent - echo '{"type":"event"}' >>$envelope_file_path + echo '{"type":"event"}' >>"$envelope_file_path" # Next we construct the meat of the event payload, which we build up # inside out using jq @@ -73,7 +73,7 @@ send_event() { # Add attachment to the event attachment=$( jq -n -c --arg "type" attachment \ - --arg length $file_length \ + --arg length "$file_length" \ --arg content_type "text/plain" \ --arg filename install_log.txt \ '{"type": $type,"length": $length|tonumber,"content_type": $content_type,"filename": $filename}' @@ -186,8 +186,8 @@ cleanup() { local lineno=${BASH_LINENO[$i - 1]} local funcname=${FUNCNAME[$i]} JSON=$( - jq -n -c --arg filename $src \ - --arg "function" $funcname \ + jq -n -c --arg filename "$src" \ + --arg "function" "$funcname" \ --arg lineno "$lineno" \ '{"filename": $filename, "function": $function, "lineno": $lineno|tonumber}' ) From 60c88c11742df80fb88b6ce1e5c3ade923e2abe3 Mon Sep 17 00:00:00 2001 From: Benedikt Franke Date: Fri, 11 Nov 2022 10:16:43 +0100 Subject: [PATCH 10/18] Debug in CI --- _unit-test/error-handling-test.sh | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/_unit-test/error-handling-test.sh b/_unit-test/error-handling-test.sh index 864b6989b8a..3ba9b25fbd0 100755 --- a/_unit-test/error-handling-test.sh +++ b/_unit-test/error-handling-test.sh @@ -37,6 +37,11 @@ export dc=':' echo "Test Logs" >"$log_file" CLEANUP_RESPONSE=$(cleanup ERROR) rm "$log_file" +echo "$CLEANUP_RESPONSE" +echo 'Error in ./_unit-test/error-handling-test.sh:38. +'\''local cmd="${BASH_COMMAND}"'\'' exited with status 0 + +Cleaning up...' test "$CLEANUP_RESPONSE" == 'Error in ./_unit-test/error-handling-test.sh:38. '\''local cmd="${BASH_COMMAND}"'\'' exited with status 0 @@ -48,6 +53,11 @@ export REPORT_SELF_HOSTED_ISSUES=0 export MINIMIZE_DOWNTIME=1 echo "Test Logs" >"$log_file" CLEANUP_RESPONSE=$(cleanup ERROR) +echo "$CLEANUP_RESPONSE" +echo 'Error in ./_unit-test/error-handling-test.sh:50. +'\''local cmd="${BASH_COMMAND}"'\'' exited with status 0 + +*NOT* cleaning up, to clean your environment run "docker compose stop".' rm "$log_file" test "$CLEANUP_RESPONSE" == 'Error in ./_unit-test/error-handling-test.sh:50. '\''local cmd="${BASH_COMMAND}"'\'' exited with status 0 From ac905796c51711d1816db23a48d6b897725e37eb Mon Sep 17 00:00:00 2001 From: Benedikt Franke Date: Fri, 11 Nov 2022 10:20:53 +0100 Subject: [PATCH 11/18] debug and hopefully pass --- _unit-test/error-handling-test.sh | 18 ++++-------------- 1 file changed, 4 insertions(+), 14 deletions(-) diff --git a/_unit-test/error-handling-test.sh b/_unit-test/error-handling-test.sh index 3ba9b25fbd0..f60b2d1f18b 100755 --- a/_unit-test/error-handling-test.sh +++ b/_unit-test/error-handling-test.sh @@ -36,13 +36,8 @@ export MINIMIZE_DOWNTIME='' export dc=':' echo "Test Logs" >"$log_file" CLEANUP_RESPONSE=$(cleanup ERROR) -rm "$log_file" -echo "$CLEANUP_RESPONSE" -echo 'Error in ./_unit-test/error-handling-test.sh:38. -'\''local cmd="${BASH_COMMAND}"'\'' exited with status 0 - -Cleaning up...' -test "$CLEANUP_RESPONSE" == 'Error in ./_unit-test/error-handling-test.sh:38. +rm "$log_file" && echo "$CLEANUP_RESPONSE" +test "$CLEANUP_RESPONSE" == 'Error in _unit-test/error-handling-test.sh:38. '\''local cmd="${BASH_COMMAND}"'\'' exited with status 0 Cleaning up...' @@ -53,13 +48,8 @@ export REPORT_SELF_HOSTED_ISSUES=0 export MINIMIZE_DOWNTIME=1 echo "Test Logs" >"$log_file" CLEANUP_RESPONSE=$(cleanup ERROR) -echo "$CLEANUP_RESPONSE" -echo 'Error in ./_unit-test/error-handling-test.sh:50. -'\''local cmd="${BASH_COMMAND}"'\'' exited with status 0 - -*NOT* cleaning up, to clean your environment run "docker compose stop".' -rm "$log_file" -test "$CLEANUP_RESPONSE" == 'Error in ./_unit-test/error-handling-test.sh:50. +rm "$log_file" && echo "$CLEANUP_RESPONSE" +test "$CLEANUP_RESPONSE" == 'Error in _unit-test/error-handling-test.sh:50. '\''local cmd="${BASH_COMMAND}"'\'' exited with status 0 *NOT* cleaning up, to clean your environment run "docker compose stop".' From 32bac8d62dcfa7ef72fcf8d16b0fac49afd9f5c5 Mon Sep 17 00:00:00 2001 From: Benedikt Franke Date: Fri, 11 Nov 2022 10:22:10 +0100 Subject: [PATCH 12/18] Remove debug --- _unit-test/error-handling-test.sh | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/_unit-test/error-handling-test.sh b/_unit-test/error-handling-test.sh index f60b2d1f18b..c7867da9182 100755 --- a/_unit-test/error-handling-test.sh +++ b/_unit-test/error-handling-test.sh @@ -36,7 +36,7 @@ export MINIMIZE_DOWNTIME='' export dc=':' echo "Test Logs" >"$log_file" CLEANUP_RESPONSE=$(cleanup ERROR) -rm "$log_file" && echo "$CLEANUP_RESPONSE" +rm "$log_file" test "$CLEANUP_RESPONSE" == 'Error in _unit-test/error-handling-test.sh:38. '\''local cmd="${BASH_COMMAND}"'\'' exited with status 0 @@ -48,7 +48,7 @@ export REPORT_SELF_HOSTED_ISSUES=0 export MINIMIZE_DOWNTIME=1 echo "Test Logs" >"$log_file" CLEANUP_RESPONSE=$(cleanup ERROR) -rm "$log_file" && echo "$CLEANUP_RESPONSE" +rm "$log_file" test "$CLEANUP_RESPONSE" == 'Error in _unit-test/error-handling-test.sh:50. '\''local cmd="${BASH_COMMAND}"'\'' exited with status 0 From 726ef54bfefd0bcbf387ba363b722b73bce1b856 Mon Sep 17 00:00:00 2001 From: Benedikt Franke Date: Thu, 17 Nov 2022 09:42:06 +0100 Subject: [PATCH 13/18] Remove new usages of basedir --- _unit-test/_test_setup.sh | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/_unit-test/_test_setup.sh b/_unit-test/_test_setup.sh index 44f53f24c56..57ebd57c060 100644 --- a/_unit-test/_test_setup.sh +++ b/_unit-test/_test_setup.sh @@ -7,8 +7,8 @@ _ORIGIN=$(pwd) rm -rf /tmp/sentry-self-hosted-test-sandbox.* _SANDBOX="$(mktemp -d /tmp/sentry-self-hosted-test-sandbox.XXX)" -source "$basedir/install/detect-platform.sh" -docker build -t sentry-self-hosted-jq-local --platform=$DOCKER_PLATFORM "$basedir/jq" +source install/detect-platform.sh +docker build -t sentry-self-hosted-jq-local --platform=$DOCKER_PLATFORM jq report_success() { echo "$(basename $0) - Success 👍" From b36c297ea24852b0b43c0935ae06917f521e16bc Mon Sep 17 00:00:00 2001 From: Benedikt Franke Date: Wed, 18 Jan 2023 09:56:26 +0100 Subject: [PATCH 14/18] remove basedir, quote DOCKER_PLATFORM --- _unit-test/_test_setup.sh | 2 +- install/error-handling.sh | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/_unit-test/_test_setup.sh b/_unit-test/_test_setup.sh index 57ebd57c060..8572dd8a329 100644 --- a/_unit-test/_test_setup.sh +++ b/_unit-test/_test_setup.sh @@ -8,7 +8,7 @@ rm -rf /tmp/sentry-self-hosted-test-sandbox.* _SANDBOX="$(mktemp -d /tmp/sentry-self-hosted-test-sandbox.XXX)" source install/detect-platform.sh -docker build -t sentry-self-hosted-jq-local --platform=$DOCKER_PLATFORM jq +docker build -t sentry-self-hosted-jq-local --platform="$DOCKER_PLATFORM" jq report_success() { echo "$(basename $0) - Success 👍" diff --git a/install/error-handling.sh b/install/error-handling.sh index 49738b49d02..ba30fff3215 100644 --- a/install/error-handling.sh +++ b/install/error-handling.sh @@ -4,7 +4,7 @@ export SENTRY_DSN='https://19555c489ded4769978daae92f2346ca@self-hosted.getsentr export SENTRY_ORG=self-hosted export SENTRY_PROJECT=installer -$dbuild -t sentry-self-hosted-jq-local --platform=$DOCKER_PLATFORM $basedir/jq +$dbuild -t sentry-self-hosted-jq-local --platform="$DOCKER_PLATFORM" jq jq="docker run --rm -i sentry-self-hosted-jq-local" sentry_cli="docker run --rm -v /tmp:/work -e SENTRY_ORG=$SENTRY_ORG -e SENTRY_PROJECT=$SENTRY_PROJECT -e SENTRY_DSN=$SENTRY_DSN getsentry/sentry-cli" From 84adc234ee5207477f51cd87a583cc50082e4a74 Mon Sep 17 00:00:00 2001 From: Benedikt Franke Date: Wed, 18 Jan 2023 10:03:11 +0100 Subject: [PATCH 15/18] avoid unnecessary loop --- install/build-docker-images.sh | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/install/build-docker-images.sh b/install/build-docker-images.sh index 2e5879d998e..52a3e4e452e 100644 --- a/install/build-docker-images.sh +++ b/install/build-docker-images.sh @@ -4,9 +4,7 @@ echo "" # Build any service that provides the image sentry-self-hosted-local first, # as it is used as the base image for sentry-cleanup-self-hosted-local. $dcb --force-rm web -for service in "$($dc config --services)"; do - $dcb --force-rm "$service" -done +$dcb --force-rm $($dc config --services) echo "" echo "Docker images built." From 34a5f2046c7fae120ef78e7047a6946e50e14ee6 Mon Sep 17 00:00:00 2001 From: Benedikt Franke Date: Thu, 19 Jan 2023 09:27:31 +0100 Subject: [PATCH 16/18] actually build each service individually --- install/build-docker-images.sh | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/install/build-docker-images.sh b/install/build-docker-images.sh index 52a3e4e452e..c793b9ea9c8 100644 --- a/install/build-docker-images.sh +++ b/install/build-docker-images.sh @@ -4,7 +4,10 @@ echo "" # Build any service that provides the image sentry-self-hosted-local first, # as it is used as the base image for sentry-cleanup-self-hosted-local. $dcb --force-rm web -$dcb --force-rm $($dc config --services) +# Build each other service individually to localize potential failures better. +for service in $($dc config --services); do + $dcb --force-rm "$service" +done echo "" echo "Docker images built." From 2dcc03af29909fc40982a2cb0c846fcd1d9337be Mon Sep 17 00:00:00 2001 From: Benedikt Franke Date: Fri, 20 Jan 2023 12:11:31 +0100 Subject: [PATCH 17/18] fix path to test files --- _integration-test/run.sh | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/_integration-test/run.sh b/_integration-test/run.sh index 9ee21cebb1f..6d6f09912fe 100755 --- a/_integration-test/run.sh +++ b/_integration-test/run.sh @@ -144,11 +144,11 @@ SCOPES=$(jq -n -c --argjson scopes '["event:admin", "event:read", "member:read", SENTRY_AUTH_TOKEN=$(sentry_api_request "api/0/api-tokens/" -X POST --data "$SCOPES" | jq -r '.token') SENTRY_DSN=$(sentry_api_request "api/0/projects/sentry/native/keys/" | jq -r '.[0].dsn.secret') # Then upload the symbols to that project (note the container mounts pwd to /work) -SENTRY_URL="$SENTRY_TEST_HOST" sentry-cli upload-dif --org "$SENTRY_ORG" --project "$SENTRY_PROJECT" --auth-token "$SENTRY_AUTH_TOKEN" windows.sym +SENTRY_URL="$SENTRY_TEST_HOST" sentry-cli upload-dif --org "$SENTRY_ORG" --project "$SENTRY_PROJECT" --auth-token "$SENTRY_AUTH_TOKEN" _integration-test/windows.sym # Get public key for minidump upload PUBLIC_KEY=$(sentry_api_request "api/0/projects/sentry/native/keys/" | jq -r '.[0].public') # Upload the minidump to be processed, this returns the event ID of the crash dump -EVENT_ID=$(sentry_api_request "api/$NATIVE_PROJECT_ID/minidump/?sentry_key=$PUBLIC_KEY" -X POST -F 'upload_file_minidump=@windows.dmp' | sed 's/\-//g') +EVENT_ID=$(sentry_api_request "api/$NATIVE_PROJECT_ID/minidump/?sentry_key=$PUBLIC_KEY" -X POST -F 'upload_file_minidump=@_integration-test/windows.dmp' | sed 's/\-//g') # We have to wait for the item to be processed for i in {0..60..10}; do EVENT_PROCESSED=$(sentry_api_request "api/0/projects/$SENTRY_ORG/$SENTRY_PROJECT/events/" | jq -r '.[]|select(.id == "'"$EVENT_ID"'")|.id') From e27906d9a14304e245b42bf71228a199e3aa6725 Mon Sep 17 00:00:00 2001 From: Benedikt Franke Date: Fri, 20 Jan 2023 12:11:39 +0100 Subject: [PATCH 18/18] fix shellcheck errors --- _integration-test/run.sh | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/_integration-test/run.sh b/_integration-test/run.sh index 6d6f09912fe..6dd0cd811e8 100755 --- a/_integration-test/run.sh +++ b/_integration-test/run.sh @@ -50,14 +50,14 @@ echo "${_endgroup}" echo "${_group}Running tests ..." get_csrf_token() { awk '$6 == "sc" { print $7 }' $COOKIE_FILE; } -sentry_api_request() { curl -s -H 'Accept: application/json; charset=utf-8' -H "Referer: $SENTRY_TEST_HOST" -H 'Content-Type: application/json' -H "X-CSRFToken: $(get_csrf_token)" -b "$COOKIE_FILE" -c "$COOKIE_FILE" "$SENTRY_TEST_HOST/$1" ${@:2}; } +sentry_api_request() { curl -s -H 'Accept: application/json; charset=utf-8' -H "Referer: $SENTRY_TEST_HOST" -H 'Content-Type: application/json' -H "X-CSRFToken: $(get_csrf_token)" -b "$COOKIE_FILE" -c "$COOKIE_FILE" "$SENTRY_TEST_HOST/$1" "${@:2}"; } login() { INITIAL_AUTH_REDIRECT=$(curl -sL -o /dev/null $SENTRY_TEST_HOST -w %{url_effective}) if [ "$INITIAL_AUTH_REDIRECT" != "$SENTRY_TEST_HOST/auth/login/sentry/" ]; then echo "Initial /auth/login/ redirect failed, exiting..." echo "$INITIAL_AUTH_REDIRECT" - exit -1 + exit 1 fi CSRF_TOKEN_FOR_LOGIN=$(curl $SENTRY_TEST_HOST -sL -c "$COOKIE_FILE" | awk -F "['\"]" ' @@ -77,7 +77,7 @@ declare -a LOGIN_TEST_STRINGS=( ) for i in "${LOGIN_TEST_STRINGS[@]}"; do echo "Testing '$i'..." - echo "$LOGIN_RESPONSE" | grep "$i[,}]" >&/dev/null + echo "$LOGIN_RESPONSE" | grep "${i}[,}]" >&/dev/null echo "Pass." done echo "${_endgroup}" @@ -116,7 +116,7 @@ declare -a EVENT_TEST_STRINGS=( ) for i in "${EVENT_TEST_STRINGS[@]}"; do echo "Testing '$i'..." - echo "$EVENT_RESPONSE" | grep "$i[,}]" >&/dev/null + echo "$EVENT_RESPONSE" | grep "${i}[,}]" >&/dev/null echo "Pass." done echo "${_endgroup}" @@ -153,7 +153,7 @@ EVENT_ID=$(sentry_api_request "api/$NATIVE_PROJECT_ID/minidump/?sentry_key=$PUBL for i in {0..60..10}; do EVENT_PROCESSED=$(sentry_api_request "api/0/projects/$SENTRY_ORG/$SENTRY_PROJECT/events/" | jq -r '.[]|select(.id == "'"$EVENT_ID"'")|.id') if [ -z "$EVENT_PROCESSED" ]; then - sleep $i + sleep "$i" else break fi