From 1db7817d815bd0505eefc367269f08e535fe78cd Mon Sep 17 00:00:00 2001 From: Ethan Smith Date: Wed, 17 Aug 2022 14:38:52 -0700 Subject: [PATCH 01/21] WIP --- install.sh | 30 ++++++++++++++++++++++++++++-- install/_lib.sh | 34 ++++++++++++++++++++++++++++++++++ install/detect-platform.sh | 30 ------------------------------ 3 files changed, 62 insertions(+), 32 deletions(-) delete mode 100755 install/detect-platform.sh diff --git a/install.sh b/install.sh index efee0cdf32e..63c5d030092 100755 --- a/install.sh +++ b/install.sh @@ -1,5 +1,32 @@ #!/usr/bin/env bash -set -e +set -eE + +export SENTRY_DSN='https://5a620019b5124cbba230a9e62db9b825@o1.ingest.sentry.io/6627632' +#export SENTRY_ORG=sentry-self-hosted +#export SENTRY_PROJECT=dogfooding + +function err_info { + local retcode=$? + local cmd="${BASH_COMMAND}" + if [[ $retcode -ne 0 ]]; then + set +o xtrace + echo "Error in ${BASH_SOURCE[0]}:${BASH_LINENO[0]}." >&2 + echo "'$cmd' exited with status $retcode" >&2 + local stack_depth=${#FUNCNAME[@]} + if [ $stack_depth -gt 2 ]; then + for ((i=$(($stack_depth - 1)),j=1;i>0;i--,j++)); do + local indent="$(yes a | head -$j | tr -d '\n')" + local src=${BASH_SOURCE[$i]} + local lineno=${BASH_LINENO[$i-1]} + local funcname=${FUNCNAME[$i]} + echo "${indent//a/-}>$src:$funcname:$lineno" >&2 + done + fi + fi + echo "Exiting with code $retcode" >&2 + exit $retcode +} +trap 'err_info' EXIT # Pre-pre-flight? 🤷 if [[ -n "$MSYSTEM" ]]; then @@ -11,7 +38,6 @@ source "$(dirname $0)/install/_lib.sh" # does a `cd .../install/`, among other # Pre-flight. No impact yet. source parse-cli.sh -source detect-platform.sh source dc-detect-version.sh source error-handling.sh source check-latest-commit.sh diff --git a/install/_lib.sh b/install/_lib.sh index 3080c8d6d74..a45d357df90 100644 --- a/install/_lib.sh +++ b/install/_lib.sh @@ -4,10 +4,44 @@ test "${DEBUG:-}" && set -x # 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" exec &> >(tee -a "$log_file") +# Sentry SaaS uses stock Yandex ClickHouse, but they don't provide images that +# support ARM, which is relevant especially for Apple M1 laptops, Sentry's +# standard developer environment. As a workaround, we use an altinity image +# targeting ARM. +# +# See https://github.com/getsentry/self-hosted/issues/1385#issuecomment-1101824274 +# +# Images built on ARM also need to be tagged to use linux/arm64 on Apple +# silicon Macs to work around an issue where they are built for +# linux/amd64 by default due to virtualization. +# See https://github.com/docker/cli/issues/3286 for the Docker bug. + +export DOCKER_ARCH=$(docker info --format '{{.Architecture}}') + +if [[ "$DOCKER_ARCH" = "x86_64" ]]; then + export DOCKER_PLATFORM="linux/amd64" + export CLICKHOUSE_IMAGE="yandex/clickhouse-server:20.3.9.70" +elif [[ "$DOCKER_ARCH" = "aarch64" ]]; then + export DOCKER_PLATFORM="linux/arm64" + export CLICKHOUSE_IMAGE="altinity/clickhouse-server:21.6.1.6734-testing-arm" +else + echo "FAIL: Unsupported docker architecture $DOCKER_ARCH." + exit 1 +fi +echo "Detected Docker platform is $DOCKER_PLATFORM" + +function send_event { + # TODO: get sentry-cli images published + #docker run --rm -v $(pwd):/work -e SENTRY_DSN=$SENTRY_DSN getsentry/sentry-cli send-event -m $1 --logfile $log_file + sentry-cli send-event --no-environ -m "$1" +} + # Work from /install/ for install.sh, project root otherwise if [[ "$(basename $0)" = "install.sh" ]]; then cd "$(dirname $0)/install/" diff --git a/install/detect-platform.sh b/install/detect-platform.sh deleted file mode 100755 index 23ddd4a1cec..00000000000 --- a/install/detect-platform.sh +++ /dev/null @@ -1,30 +0,0 @@ -echo "${_group}Detecting Docker platform" - - -# Sentry SaaS uses stock Yandex ClickHouse, but they don't provide images that -# support ARM, which is relevant especially for Apple M1 laptops, Sentry's -# standard developer environment. As a workaround, we use an altinity image -# targeting ARM. -# -# See https://github.com/getsentry/self-hosted/issues/1385#issuecomment-1101824274 -# -# Images built on ARM also need to be tagged to use linux/arm64 on Apple -# silicon Macs to work around an issue where they are built for -# linux/amd64 by default due to virtualization. -# See https://github.com/docker/cli/issues/3286 for the Docker bug. - -export DOCKER_ARCH=$(docker info --format '{{.Architecture}}') - -if [[ "$DOCKER_ARCH" = "x86_64" ]]; then - export DOCKER_PLATFORM="linux/amd64" - export CLICKHOUSE_IMAGE="yandex/clickhouse-server:20.3.9.70" -elif [[ "$DOCKER_ARCH" = "aarch64" ]]; then - export DOCKER_PLATFORM="linux/arm64" - export CLICKHOUSE_IMAGE="altinity/clickhouse-server:21.6.1.6734-testing-arm" -else - echo "FAIL: Unsupported docker architecture $DOCKER_ARCH." - exit 1 -fi -echo "Detected Docker platform is $DOCKER_PLATFORM" - -echo "${_endgroup}" From 5c7b28d54fc735a2a1e657333041df4b8bd6a8ce Mon Sep 17 00:00:00 2001 From: Ethan Smith Date: Thu, 1 Sep 2022 12:54:59 -0700 Subject: [PATCH 02/21] WIP 2 --- install.sh | 92 ++++++++++++++++-------------------- install/dc-detect-version.sh | 20 ++++---- install/error-handling.sh | 26 ++++++++++ install/parse-cli.sh | 34 +++++++------ 4 files changed, 99 insertions(+), 73 deletions(-) diff --git a/install.sh b/install.sh index 63c5d030092..96bc316f446 100755 --- a/install.sh +++ b/install.sh @@ -1,32 +1,20 @@ #!/usr/bin/env bash set -eE -export SENTRY_DSN='https://5a620019b5124cbba230a9e62db9b825@o1.ingest.sentry.io/6627632' -#export SENTRY_ORG=sentry-self-hosted -#export SENTRY_PROJECT=dogfooding +echo "Would you like to opt-in to error monitoring for the Sentry installer?" +echo "This helps us catch and fix errors when installing Sentry." +echo "We retain your OS name, installer log, IP, and username for 30 days." +echo "Your information is solely used for error monitoring, we do not share your data." +select yn in "Yes" "No"; do + case $yn in + Yes ) export REPORT_ERRORS=1; break;; + No ) export REPORT_ERRORS=0; break;; + esac +done -function err_info { - local retcode=$? - local cmd="${BASH_COMMAND}" - if [[ $retcode -ne 0 ]]; then - set +o xtrace - echo "Error in ${BASH_SOURCE[0]}:${BASH_LINENO[0]}." >&2 - echo "'$cmd' exited with status $retcode" >&2 - local stack_depth=${#FUNCNAME[@]} - if [ $stack_depth -gt 2 ]; then - for ((i=$(($stack_depth - 1)),j=1;i>0;i--,j++)); do - local indent="$(yes a | head -$j | tr -d '\n')" - local src=${BASH_SOURCE[$i]} - local lineno=${BASH_LINENO[$i-1]} - local funcname=${FUNCNAME[$i]} - echo "${indent//a/-}>$src:$funcname:$lineno" >&2 - done - fi - fi - echo "Exiting with code $retcode" >&2 - exit $retcode -} -trap 'err_info' EXIT +if [ "$REPORT_ERRORS" == 1 ]; then + trap 'err_info' EXIT +fi # Pre-pre-flight? 🤷 if [[ -n "$MSYSTEM" ]]; then @@ -34,30 +22,34 @@ if [[ -n "$MSYSTEM" ]]; then exit 1 fi -source "$(dirname $0)/install/_lib.sh" # does a `cd .../install/`, among other things +function main() { + source "$(dirname $0)/install/_lib.sh" # does a `cd .../install/`, among other things -# Pre-flight. No impact yet. -source parse-cli.sh -source dc-detect-version.sh -source error-handling.sh -source check-latest-commit.sh -source check-minimum-requirements.sh + # Pre-flight. No impact yet. + source parse-cli.sh + source dc-detect-version.sh + source error-handling.sh + source check-latest-commit.sh + source 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 replace-tsdb.sh + source update-docker-images.sh + source build-docker-images.sh + source set-up-zookeeper.sh + source install-wal2json.sh + source bootstrap-snuba.sh + source create-kafka-topics.sh + source upgrade-postgres.sh + source set-up-and-migrate-database.sh + source migrate-file-storage.sh + source geoip.sh + source wrap-up.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 replace-tsdb.sh -source update-docker-images.sh -source build-docker-images.sh -source set-up-zookeeper.sh -source install-wal2json.sh -source bootstrap-snuba.sh -source create-kafka-topics.sh -source upgrade-postgres.sh -source set-up-and-migrate-database.sh -source migrate-file-storage.sh -source geoip.sh -source wrap-up.sh +main \ No newline at end of file diff --git a/install/dc-detect-version.sh b/install/dc-detect-version.sh index 2c92d6bbc22..4b98cceaf06 100644 --- a/install/dc-detect-version.sh +++ b/install/dc-detect-version.sh @@ -8,13 +8,17 @@ fi echo "${_group}Initializing Docker Compose ..." -# Some environments still use `docker-compose` even for Docker Compose v2. -dc_base="$(docker compose version &> /dev/null && echo 'docker compose' || echo 'docker-compose')" -if [[ "$(basename $0)" = "install.sh" ]]; then - dc="$dc_base --ansi never --env-file ${_ENV}" -else - dc="$dc_base --ansi never" -fi -dcr="$dc run --rm" +function detect_compose_verson() { + # Some environments still use `docker-compose` even for Docker Compose v2. + dc_base="$(docker compose version &> /dev/null && echo 'docker compose' || echo 'docker-compose')" + if [[ "$(basename $0)" = "install.sh" ]]; then + dc="$dc_base --ansi never --env-file ${_ENV}" + else + dc="$dc_base --ansi never" + fi + dcr="$dc run --rm" +} + +detect_compose_verson echo "${_endgroup}" diff --git a/install/error-handling.sh b/install/error-handling.sh index 9121bba89eb..dd2d77bfcf5 100644 --- a/install/error-handling.sh +++ b/install/error-handling.sh @@ -1,5 +1,31 @@ echo "${_group}Setting up error handling ..." +export SENTRY_DSN='https://afa81b4b7c634e318b0ec138abb2645f@self-hosted.getsentry.net/2' +export SENTRY_ORG=sentry +export SENTRY_PROJECT=dogfooding + +function err_info { + local retcode=$? + local cmd="${BASH_COMMAND}" + if [[ $retcode -ne 0 ]]; then + set +o xtrace + echo "Error in ${BASH_SOURCE[0]}:${BASH_LINENO[0]}." >&2 + echo "'$cmd' exited with status $retcode" >&2 + local stack_depth=${#FUNCNAME[@]} + if [ $stack_depth -gt 2 ]; then + for ((i=$(($stack_depth - 1)),j=1;i>0;i--,j++)); do + local indent="$(yes a | head -$j | tr -d '\n')" + local src=${BASH_SOURCE[$i]} + local lineno=${BASH_LINENO[$i-1]} + local funcname=${FUNCNAME[$i]} + echo "${indent//a/-}>$src:$funcname:$lineno" >&2 + done + fi + fi + echo "Exiting with code $retcode" >&2 + exit $retcode +} + # Courtesy of https://stackoverflow.com/a/2183063/90297 trap_with_arg() { func="$1" ; shift diff --git a/install/parse-cli.sh b/install/parse-cli.sh index 4712fd6c35e..c61f43f01f3 100644 --- a/install/parse-cli.sh +++ b/install/parse-cli.sh @@ -21,21 +21,25 @@ Options: EOF } -SKIP_USER_PROMPT="${SKIP_USER_PROMPT:-}" -MINIMIZE_DOWNTIME="${MINIMIZE_DOWNTIME:-}" -SKIP_COMMIT_CHECK="${SKIP_COMMIT_CHECK:-}" +function parse_cli() { + export SKIP_USER_PROMPT="${SKIP_USER_PROMPT:-}" + export MINIMIZE_DOWNTIME="${MINIMIZE_DOWNTIME:-}" + export SKIP_COMMIT_CHECK="${SKIP_COMMIT_CHECK:-}" -while (( $# )); do - case "$1" in - -h | --help) show_help; exit;; - --no-user-prompt) SKIP_USER_PROMPT=1;; # deprecated - --skip-user-prompt) SKIP_USER_PROMPT=1;; - --minimize-downtime) MINIMIZE_DOWNTIME=1;; - --skip-commit-check) SKIP_COMMIT_CHECK=1;; - --) ;; - *) echo "Unexpected argument: $1. Use --help for usage information."; exit 1;; - esac - shift -done + while (( $# )); do + case "$1" in + -h | --help) show_help; exit;; + --no-user-prompt) SKIP_USER_PROMPT=1;; # deprecated + --skip-user-prompt) SKIP_USER_PROMPT=1;; + --minimize-downtime) MINIMIZE_DOWNTIME=1;; + --skip-commit-check) SKIP_COMMIT_CHECK=1;; + --) ;; + *) echo "Unexpected argument: $1. Use --help for usage information."; exit 1;; + esac + shift + done +} + +parse_cli echo "${_endgroup}" From 8c9c4fb417c6c4d5e889be67946418d943245e6d Mon Sep 17 00:00:00 2001 From: Ethan Smith Date: Thu, 1 Sep 2022 16:05:15 -0700 Subject: [PATCH 03/21] More minimal but quite functional error reporting --- .gitignore | 3 ++ install.sh | 71 ++++++++++++++---------------------- install/_lib.sh | 17 ++++++--- install/dc-detect-version.sh | 20 ++++------ install/error-handling.sh | 66 +++++++++++++++++++++------------ install/parse-cli.sh | 34 ++++++++--------- 6 files changed, 107 insertions(+), 104 deletions(-) diff --git a/.gitignore b/.gitignore index abc49402887..e6daa2c5ce3 100644 --- a/.gitignore +++ b/.gitignore @@ -1,3 +1,6 @@ +# Error reporting choice cache +.reporterrors + # Byte-compiled / optimized / DLL files __pycache__/ *.py[cod] diff --git a/install.sh b/install.sh index 96bc316f446..bb64cd78906 100755 --- a/install.sh +++ b/install.sh @@ -1,55 +1,38 @@ #!/usr/bin/env bash set -eE -echo "Would you like to opt-in to error monitoring for the Sentry installer?" -echo "This helps us catch and fix errors when installing Sentry." -echo "We retain your OS name, installer log, IP, and username for 30 days." -echo "Your information is solely used for error monitoring, we do not share your data." -select yn in "Yes" "No"; do - case $yn in - Yes ) export REPORT_ERRORS=1; break;; - No ) export REPORT_ERRORS=0; break;; - esac -done - -if [ "$REPORT_ERRORS" == 1 ]; then - trap 'err_info' EXIT -fi - # Pre-pre-flight? 🤷 if [[ -n "$MSYSTEM" ]]; then echo "Seems like you are using an MSYS2-based system (such as Git Bash) which is not supported. Please use WSL instead."; exit 1 fi -function main() { - source "$(dirname $0)/install/_lib.sh" # does a `cd .../install/`, among other things - - # Pre-flight. No impact yet. - source parse-cli.sh - source dc-detect-version.sh - source error-handling.sh - source check-latest-commit.sh - source check-minimum-requirements.sh +source "$(dirname $0)/install/_lib.sh" # does a `cd .../install/`, among other things - # 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 replace-tsdb.sh - source update-docker-images.sh - source build-docker-images.sh - source set-up-zookeeper.sh - source install-wal2json.sh - source bootstrap-snuba.sh - source create-kafka-topics.sh - source upgrade-postgres.sh - source set-up-and-migrate-database.sh - source migrate-file-storage.sh - source geoip.sh - source wrap-up.sh -} +# Pre-flight. No impact yet. +source parse-cli.sh +source dc-detect-version.sh +source 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 -main \ No newline at end of file +# 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 replace-tsdb.sh +source update-docker-images.sh +source build-docker-images.sh +source set-up-zookeeper.sh +source install-wal2json.sh +source bootstrap-snuba.sh +source create-kafka-topics.sh +source upgrade-postgres.sh +source set-up-and-migrate-database.sh +source migrate-file-storage.sh +source geoip.sh +source wrap-up.sh diff --git a/install/_lib.sh b/install/_lib.sh index a45d357df90..e110bf64c93 100644 --- a/install/_lib.sh +++ b/install/_lib.sh @@ -4,8 +4,6 @@ test "${DEBUG:-}" && set -x # 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" exec &> >(tee -a "$log_file") @@ -37,9 +35,18 @@ fi echo "Detected Docker platform is $DOCKER_PLATFORM" function send_event { - # TODO: get sentry-cli images published - #docker run --rm -v $(pwd):/work -e SENTRY_DSN=$SENTRY_DSN getsentry/sentry-cli send-event -m $1 --logfile $log_file - sentry-cli send-event --no-environ -m "$1" + if [[ $DOCKER_PLATFORM == "linux/amd64" ]]; then + local sentry_cli="docker run --rm -v \$(pwd):/work -e SENTRY_DSN=$SENTRY_DSN getsentry/sentry-cli" + else + if ! command -v sentry-cli &> /dev/null; then + echo "sentry-cli could not be found, please install it" + exit 1 + fi + local sentry_cli=sentry-cli + fi + command pushd .. > /dev/null + $sentry_cli send-event --no-environ -f "$1" -m "$2" --logfile $log_file + command popd > /dev/null } # Work from /install/ for install.sh, project root otherwise diff --git a/install/dc-detect-version.sh b/install/dc-detect-version.sh index 4b98cceaf06..2c92d6bbc22 100644 --- a/install/dc-detect-version.sh +++ b/install/dc-detect-version.sh @@ -8,17 +8,13 @@ fi echo "${_group}Initializing Docker Compose ..." -function detect_compose_verson() { - # Some environments still use `docker-compose` even for Docker Compose v2. - dc_base="$(docker compose version &> /dev/null && echo 'docker compose' || echo 'docker-compose')" - if [[ "$(basename $0)" = "install.sh" ]]; then - dc="$dc_base --ansi never --env-file ${_ENV}" - else - dc="$dc_base --ansi never" - fi - dcr="$dc run --rm" -} - -detect_compose_verson +# Some environments still use `docker-compose` even for Docker Compose v2. +dc_base="$(docker compose version &> /dev/null && echo 'docker compose' || echo 'docker-compose')" +if [[ "$(basename $0)" = "install.sh" ]]; then + dc="$dc_base --ansi never --env-file ${_ENV}" +else + dc="$dc_base --ansi never" +fi +dcr="$dc run --rm" echo "${_endgroup}" diff --git a/install/error-handling.sh b/install/error-handling.sh index dd2d77bfcf5..affb397ea10 100644 --- a/install/error-handling.sh +++ b/install/error-handling.sh @@ -4,33 +4,31 @@ export SENTRY_DSN='https://afa81b4b7c634e318b0ec138abb2645f@self-hosted.getsentr export SENTRY_ORG=sentry export SENTRY_PROJECT=dogfooding -function err_info { - local retcode=$? - local cmd="${BASH_COMMAND}" - if [[ $retcode -ne 0 ]]; then - set +o xtrace - echo "Error in ${BASH_SOURCE[0]}:${BASH_LINENO[0]}." >&2 - echo "'$cmd' exited with status $retcode" >&2 - local stack_depth=${#FUNCNAME[@]} - if [ $stack_depth -gt 2 ]; then - for ((i=$(($stack_depth - 1)),j=1;i>0;i--,j++)); do - local indent="$(yes a | head -$j | tr -d '\n')" - local src=${BASH_SOURCE[$i]} - local lineno=${BASH_LINENO[$i-1]} - local funcname=${FUNCNAME[$i]} - echo "${indent//a/-}>$src:$funcname:$lineno" >&2 - done - fi +if [[ -f .reporterrors ]]; then + if [[ "$(cat .reporterrors)" == "yes" ]]; then + export REPORT_ERRORS=1 + else + export REPORT_ERRORS=0 fi - echo "Exiting with code $retcode" >&2 - exit $retcode -} +else + echo "Would you like to opt-in to error monitoring for the Sentry installer?" + echo "This helps us catch and fix errors when installing Sentry." + echo "We may retain your OS username, IP address, and installer log, for 30 days." + echo "Your information is solely used for error monitoring of the installer." + echo "You may change your preference at any time by deleting the '.reporterrors' file." + select yn in "Yes" "No"; do + case $yn in + Yes ) export REPORT_ERRORS=1; echo "yes" > .reporterrors; break;; + No ) export REPORT_ERRORS=0; echo "no" > .reporterrors; break;; + esac + done +fi # Courtesy of https://stackoverflow.com/a/2183063/90297 trap_with_arg() { func="$1" ; shift for sig ; do - trap "$func $sig "'$LINENO' "$sig" + trap "$func $sig" "$sig" done } @@ -41,9 +39,30 @@ cleanup () { return 0; fi DID_CLEAN_UP=1 - + local retcode=$? + local cmd="${BASH_COMMAND}" if [[ "$1" != "EXIT" ]]; then - echo "An error occurred, caught SIG$1 on line $2"; + set +o xtrace + printf -v err '%s' "Error in ${BASH_SOURCE[1]}:${BASH_LINENO[1]}." + printf -v cmd_exit '%s' "'$cmd' exited with status $retcode" + printf '%s\n%s\n' "$err" "$cmd_exit" + local stack_depth=${#FUNCNAME[@]} + local traceback="" + if [ $stack_depth -gt 2 ]; then + for ((i=$(($stack_depth - 1)),j=1;i>0;i--,j++)); do + local indent="$(yes a | head -$j | tr -d '\n')" + local src=${BASH_SOURCE[$i]} + local lineno=${BASH_LINENO[$i-1]} + local funcname=${FUNCNAME[$i]} + printf -v traceback '%s\n' "$traceback${indent//a/-}>$src:$funcname:$lineno" + done + fi + echo "$traceback" + + if [ "$REPORT_ERRORS" == 1 ]; then + local traceback_hash=$(echo -n $traceback | docker run --rm busybox md5sum | cut -d' ' -f1) + send_event "$traceback_hash" "$cmd_exit" + fi if [[ -n "$MINIMIZE_DOWNTIME" ]]; then echo "*NOT* cleaning up, to clean your environment run \"docker compose stop\"." @@ -56,6 +75,5 @@ cleanup () { $dc stop -t $STOP_TIMEOUT &> /dev/null fi } -trap_with_arg cleanup ERR INT TERM EXIT echo "${_endgroup}" diff --git a/install/parse-cli.sh b/install/parse-cli.sh index c61f43f01f3..4712fd6c35e 100644 --- a/install/parse-cli.sh +++ b/install/parse-cli.sh @@ -21,25 +21,21 @@ Options: EOF } -function parse_cli() { - export SKIP_USER_PROMPT="${SKIP_USER_PROMPT:-}" - export MINIMIZE_DOWNTIME="${MINIMIZE_DOWNTIME:-}" - export SKIP_COMMIT_CHECK="${SKIP_COMMIT_CHECK:-}" +SKIP_USER_PROMPT="${SKIP_USER_PROMPT:-}" +MINIMIZE_DOWNTIME="${MINIMIZE_DOWNTIME:-}" +SKIP_COMMIT_CHECK="${SKIP_COMMIT_CHECK:-}" - while (( $# )); do - case "$1" in - -h | --help) show_help; exit;; - --no-user-prompt) SKIP_USER_PROMPT=1;; # deprecated - --skip-user-prompt) SKIP_USER_PROMPT=1;; - --minimize-downtime) MINIMIZE_DOWNTIME=1;; - --skip-commit-check) SKIP_COMMIT_CHECK=1;; - --) ;; - *) echo "Unexpected argument: $1. Use --help for usage information."; exit 1;; - esac - shift - done -} - -parse_cli +while (( $# )); do + case "$1" in + -h | --help) show_help; exit;; + --no-user-prompt) SKIP_USER_PROMPT=1;; # deprecated + --skip-user-prompt) SKIP_USER_PROMPT=1;; + --minimize-downtime) MINIMIZE_DOWNTIME=1;; + --skip-commit-check) SKIP_COMMIT_CHECK=1;; + --) ;; + *) echo "Unexpected argument: $1. Use --help for usage information."; exit 1;; + esac + shift +done echo "${_endgroup}" From 4cfc994b84076e30bd9619cd0b945369cfd9325b Mon Sep 17 00:00:00 2001 From: Ethan Smith Date: Wed, 7 Sep 2022 10:44:33 -0700 Subject: [PATCH 04/21] Update project name to installer, tweak wording based on legal --- install/error-handling.sh | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/install/error-handling.sh b/install/error-handling.sh index affb397ea10..7e3299bb118 100644 --- a/install/error-handling.sh +++ b/install/error-handling.sh @@ -1,8 +1,8 @@ echo "${_group}Setting up error handling ..." -export SENTRY_DSN='https://afa81b4b7c634e318b0ec138abb2645f@self-hosted.getsentry.net/2' +export SENTRY_DSN='https://19555c489ded4769978daae92f2346ca@self-hosted.getsentry.net/3' export SENTRY_ORG=sentry -export SENTRY_PROJECT=dogfooding +export SENTRY_PROJECT=installer if [[ -f .reporterrors ]]; then if [[ "$(cat .reporterrors)" == "yes" ]]; then @@ -13,9 +13,11 @@ if [[ -f .reporterrors ]]; then else echo "Would you like to opt-in to error monitoring for the Sentry installer?" echo "This helps us catch and fix errors when installing Sentry." - echo "We may retain your OS username, IP address, and installer log, for 30 days." - echo "Your information is solely used for error monitoring of the installer." + echo "We may collect and retain your OS username, IP address, and installer log, for 30 days." + echo "Your information is solely used to improve the installer and is subject to our privacy policy[1]." echo "You may change your preference at any time by deleting the '.reporterrors' file." + echo + echo "[1] https://sentry.io/privacy/" select yn in "Yes" "No"; do case $yn in Yes ) export REPORT_ERRORS=1; echo "yes" > .reporterrors; break;; From c307013bc540e91db7b10da73f218c58ab88bc89 Mon Sep 17 00:00:00 2001 From: Ethan Smith Date: Wed, 7 Sep 2022 16:17:02 -0700 Subject: [PATCH 05/21] Update install/error-handling.sh Co-authored-by: Chad Whitacre --- install/error-handling.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/install/error-handling.sh b/install/error-handling.sh index 7e3299bb118..7fcc2dceefb 100644 --- a/install/error-handling.sh +++ b/install/error-handling.sh @@ -56,7 +56,7 @@ cleanup () { local src=${BASH_SOURCE[$i]} local lineno=${BASH_LINENO[$i-1]} local funcname=${FUNCNAME[$i]} - printf -v traceback '%s\n' "$traceback${indent//a/-}>$src:$funcname:$lineno" + printf -v traceback '%s\n' "$traceback${indent//a/-}> $src:$funcname:$lineno" done fi echo "$traceback" From d280ae0449ef7b46c9218367fb981f793785cf0b Mon Sep 17 00:00:00 2001 From: Ethan Smith Date: Thu, 8 Sep 2022 11:09:43 -0700 Subject: [PATCH 06/21] Respond to review --- install.sh | 1 + install/_lib.sh | 41 -------------------------------------- install/detect-platform.sh | 30 ++++++++++++++++++++++++++++ install/error-handling.sh | 15 ++++++++++++++ 4 files changed, 46 insertions(+), 41 deletions(-) create mode 100755 install/detect-platform.sh diff --git a/install.sh b/install.sh index bb64cd78906..5706d14a221 100755 --- a/install.sh +++ b/install.sh @@ -12,6 +12,7 @@ source "$(dirname $0)/install/_lib.sh" # does a `cd .../install/`, among other # Pre-flight. No impact yet. source parse-cli.sh source dc-detect-version.sh +source detect-platform.sh source 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 diff --git a/install/_lib.sh b/install/_lib.sh index e110bf64c93..3080c8d6d74 100644 --- a/install/_lib.sh +++ b/install/_lib.sh @@ -8,47 +8,6 @@ umask 002 log_file="sentry_install_log-`date +'%Y-%m-%d_%H-%M-%S'`.txt" exec &> >(tee -a "$log_file") -# Sentry SaaS uses stock Yandex ClickHouse, but they don't provide images that -# support ARM, which is relevant especially for Apple M1 laptops, Sentry's -# standard developer environment. As a workaround, we use an altinity image -# targeting ARM. -# -# See https://github.com/getsentry/self-hosted/issues/1385#issuecomment-1101824274 -# -# Images built on ARM also need to be tagged to use linux/arm64 on Apple -# silicon Macs to work around an issue where they are built for -# linux/amd64 by default due to virtualization. -# See https://github.com/docker/cli/issues/3286 for the Docker bug. - -export DOCKER_ARCH=$(docker info --format '{{.Architecture}}') - -if [[ "$DOCKER_ARCH" = "x86_64" ]]; then - export DOCKER_PLATFORM="linux/amd64" - export CLICKHOUSE_IMAGE="yandex/clickhouse-server:20.3.9.70" -elif [[ "$DOCKER_ARCH" = "aarch64" ]]; then - export DOCKER_PLATFORM="linux/arm64" - export CLICKHOUSE_IMAGE="altinity/clickhouse-server:21.6.1.6734-testing-arm" -else - echo "FAIL: Unsupported docker architecture $DOCKER_ARCH." - exit 1 -fi -echo "Detected Docker platform is $DOCKER_PLATFORM" - -function send_event { - if [[ $DOCKER_PLATFORM == "linux/amd64" ]]; then - local sentry_cli="docker run --rm -v \$(pwd):/work -e SENTRY_DSN=$SENTRY_DSN getsentry/sentry-cli" - else - if ! command -v sentry-cli &> /dev/null; then - echo "sentry-cli could not be found, please install it" - exit 1 - fi - local sentry_cli=sentry-cli - fi - command pushd .. > /dev/null - $sentry_cli send-event --no-environ -f "$1" -m "$2" --logfile $log_file - command popd > /dev/null -} - # Work from /install/ for install.sh, project root otherwise if [[ "$(basename $0)" = "install.sh" ]]; then cd "$(dirname $0)/install/" diff --git a/install/detect-platform.sh b/install/detect-platform.sh new file mode 100755 index 00000000000..23ddd4a1cec --- /dev/null +++ b/install/detect-platform.sh @@ -0,0 +1,30 @@ +echo "${_group}Detecting Docker platform" + + +# Sentry SaaS uses stock Yandex ClickHouse, but they don't provide images that +# support ARM, which is relevant especially for Apple M1 laptops, Sentry's +# standard developer environment. As a workaround, we use an altinity image +# targeting ARM. +# +# See https://github.com/getsentry/self-hosted/issues/1385#issuecomment-1101824274 +# +# Images built on ARM also need to be tagged to use linux/arm64 on Apple +# silicon Macs to work around an issue where they are built for +# linux/amd64 by default due to virtualization. +# See https://github.com/docker/cli/issues/3286 for the Docker bug. + +export DOCKER_ARCH=$(docker info --format '{{.Architecture}}') + +if [[ "$DOCKER_ARCH" = "x86_64" ]]; then + export DOCKER_PLATFORM="linux/amd64" + export CLICKHOUSE_IMAGE="yandex/clickhouse-server:20.3.9.70" +elif [[ "$DOCKER_ARCH" = "aarch64" ]]; then + export DOCKER_PLATFORM="linux/arm64" + export CLICKHOUSE_IMAGE="altinity/clickhouse-server:21.6.1.6734-testing-arm" +else + echo "FAIL: Unsupported docker architecture $DOCKER_ARCH." + exit 1 +fi +echo "Detected Docker platform is $DOCKER_PLATFORM" + +echo "${_endgroup}" diff --git a/install/error-handling.sh b/install/error-handling.sh index 7fcc2dceefb..463d928e7bf 100644 --- a/install/error-handling.sh +++ b/install/error-handling.sh @@ -4,6 +4,21 @@ export SENTRY_DSN='https://19555c489ded4769978daae92f2346ca@self-hosted.getsentr export SENTRY_ORG=sentry export SENTRY_PROJECT=installer +function send_event { + if [[ $DOCKER_PLATFORM == "linux/amd64" ]]; then + local sentry_cli="docker run --rm -v \$(pwd):/work -e SENTRY_DSN=$SENTRY_DSN getsentry/sentry-cli" + else + if ! command -v sentry-cli &> /dev/null; then + echo "sentry-cli could not be found, please install it" + exit 1 + fi + local sentry_cli=sentry-cli + fi + command pushd .. > /dev/null + $sentry_cli send-event --no-environ -f "$1" -m "$2" --logfile $log_file + command popd > /dev/null +} + if [[ -f .reporterrors ]]; then if [[ "$(cat .reporterrors)" == "yes" ]]; then export REPORT_ERRORS=1 From 8bb9a3314ab116f17edafe73faa3adddfbdc1f01 Mon Sep 17 00:00:00 2001 From: Ethan Smith Date: Thu, 8 Sep 2022 11:22:57 -0700 Subject: [PATCH 07/21] Change org name --- install/error-handling.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/install/error-handling.sh b/install/error-handling.sh index 463d928e7bf..70dd6226260 100644 --- a/install/error-handling.sh +++ b/install/error-handling.sh @@ -1,7 +1,7 @@ echo "${_group}Setting up error handling ..." export SENTRY_DSN='https://19555c489ded4769978daae92f2346ca@self-hosted.getsentry.net/3' -export SENTRY_ORG=sentry +export SENTRY_ORG=self-hosted export SENTRY_PROJECT=installer function send_event { From 1d78003c58b86ae6b2a70bd2740fda5bdbc97ab5 Mon Sep 17 00:00:00 2001 From: Ethan Smith Date: Thu, 8 Sep 2022 12:49:28 -0700 Subject: [PATCH 08/21] Put detect-platform in the right spot in install.sh --- install.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/install.sh b/install.sh index 5706d14a221..5eed8419f2b 100755 --- a/install.sh +++ b/install.sh @@ -11,8 +11,8 @@ source "$(dirname $0)/install/_lib.sh" # does a `cd .../install/`, among other # Pre-flight. No impact yet. source parse-cli.sh -source dc-detect-version.sh source detect-platform.sh +source dc-detect-version.sh source 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 From b1f229cebe61a88dc1b450092bfebfee7660db52 Mon Sep 17 00:00:00 2001 From: Ethan Smith Date: Thu, 8 Sep 2022 14:38:54 -0700 Subject: [PATCH 09/21] Move .reporterrors to distro root --- install/error-handling.sh | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/install/error-handling.sh b/install/error-handling.sh index 70dd6226260..ccbfa797af6 100644 --- a/install/error-handling.sh +++ b/install/error-handling.sh @@ -19,8 +19,8 @@ function send_event { command popd > /dev/null } -if [[ -f .reporterrors ]]; then - if [[ "$(cat .reporterrors)" == "yes" ]]; then +if [[ -f ../.reporterrors ]]; then + if [[ "$(cat ../.reporterrors)" == "yes" ]]; then export REPORT_ERRORS=1 else export REPORT_ERRORS=0 @@ -35,8 +35,8 @@ else echo "[1] https://sentry.io/privacy/" select yn in "Yes" "No"; do case $yn in - Yes ) export REPORT_ERRORS=1; echo "yes" > .reporterrors; break;; - No ) export REPORT_ERRORS=0; echo "no" > .reporterrors; break;; + Yes ) export REPORT_ERRORS=1; echo "yes" > ../.reporterrors; break;; + No ) export REPORT_ERRORS=0; echo "no" > ../.reporterrors; break;; esac done fi From 7fa54b285a91b58ebccb10dc31574e71ef06b2bf Mon Sep 17 00:00:00 2001 From: Chad Whitacre Date: Thu, 8 Sep 2022 20:44:26 -0400 Subject: [PATCH 10/21] Update copy and fix .reporterrors location (#1686) --- install/error-handling.sh | 62 +++++++++++++++++++++++++++++++-------- integration-test.sh | 1 + 2 files changed, 50 insertions(+), 13 deletions(-) diff --git a/install/error-handling.sh b/install/error-handling.sh index ccbfa797af6..b79fbecb5dd 100644 --- a/install/error-handling.sh +++ b/install/error-handling.sh @@ -19,26 +19,62 @@ function send_event { command popd > /dev/null } -if [[ -f ../.reporterrors ]]; then - if [[ "$(cat ../.reporterrors)" == "yes" ]]; then +reporterrors="$basedir/.reporterrors" +if [[ -f $reporterrors ]]; then + echo -n "Found a .reporterrors file. What does it say? " + cat $reporterrors + if [[ "$(cat $reporterrors)" == "yes" ]]; then export REPORT_ERRORS=1 else export REPORT_ERRORS=0 fi else - echo "Would you like to opt-in to error monitoring for the Sentry installer?" - echo "This helps us catch and fix errors when installing Sentry." - echo "We may collect and retain your OS username, IP address, and installer log, for 30 days." - echo "Your information is solely used to improve the installer and is subject to our privacy policy[1]." - echo "You may change your preference at any time by deleting the '.reporterrors' file." echo - echo "[1] https://sentry.io/privacy/" - select yn in "Yes" "No"; do - case $yn in - Yes ) export REPORT_ERRORS=1; echo "yes" > ../.reporterrors; break;; - No ) export REPORT_ERRORS=0; echo "no" > ../.reporterrors; break;; - esac + echo "Hey, so ... we would love to find out when you hit an issue with this here" + echo "installer you are running. Turns out there is an app for that, called Sentry." + echo "Are you okay with us sending info to Sentry when you run this installer?" + echo + echo " y / yes / 1" + echo " n / no / 0" + echo + echo "(Btw, we send this to our own self-hosted Sentry instance, not to Sentry SaaS," + echo "so that we can be in this together.)" + echo + echo "Here's the info we may collect:" + echo + echo " - OS username" + echo " - IP address" + echo " - install log" + echo " - performance data" + echo + echo "Thirty (30) day retention. No marketing. Privacy policy at sentry.io/privacy." + echo + + yn="" + until [ ! -z "$yn" ] + do + read -p "y or n? " yn + case $yn in + y | yes | 1) + export REPORT_ERRORS=1 + echo "yes" > $reporterrors + echo + echo -n "Thank you." + ;; + n | no | 0) + export REPORT_ERRORS=0 + echo "no" > $reporterrors + echo + echo -n "Understood." + ;; + *) yn="";; + esac done + + echo " Your answer is cached in '.reporterrors', remove it to see this" + echo "prompt again." + echo + sleep 5 fi # Courtesy of https://stackoverflow.com/a/2183063/90297 diff --git a/integration-test.sh b/integration-test.sh index 52421e8f495..244ca2da7ea 100755 --- a/integration-test.sh +++ b/integration-test.sh @@ -4,6 +4,7 @@ set -ex echo "Reset customizations" rm -f sentry/enhance-image.sh rm -f sentry/requirements.txt +echo no > .reporterrors echo "Testing initial install" ./install.sh From 45bf86569b99a475633aaeda161905c9f6f39700 Mon Sep 17 00:00:00 2001 From: hubertdeng123 Date: Thu, 8 Sep 2022 21:53:22 -0700 Subject: [PATCH 11/21] fix unexpected behavior with traceback code --- install/error-handling.sh | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/install/error-handling.sh b/install/error-handling.sh index b79fbecb5dd..f1fa6638056 100644 --- a/install/error-handling.sh +++ b/install/error-handling.sh @@ -88,15 +88,15 @@ trap_with_arg() { DID_CLEAN_UP=0 # the cleanup function will be the exit point cleanup () { + local cmd="${BASH_COMMAND}" if [[ "$DID_CLEAN_UP" -eq 1 ]]; then return 0; fi DID_CLEAN_UP=1 local retcode=$? - local cmd="${BASH_COMMAND}" if [[ "$1" != "EXIT" ]]; then set +o xtrace - printf -v err '%s' "Error in ${BASH_SOURCE[1]}:${BASH_LINENO[1]}." + printf -v err '%s' "Error in ${BASH_SOURCE[1]}:${BASH_LINENO[0]}." printf -v cmd_exit '%s' "'$cmd' exited with status $retcode" printf '%s\n%s\n' "$err" "$cmd_exit" local stack_depth=${#FUNCNAME[@]} From fee3d5105c168c995321512eeec3216082fcdcd4 Mon Sep 17 00:00:00 2001 From: Chad Whitacre Date: Fri, 9 Sep 2022 10:51:36 -0400 Subject: [PATCH 12/21] Move retcode as well --- install/error-handling.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/install/error-handling.sh b/install/error-handling.sh index f1fa6638056..8564607a50d 100644 --- a/install/error-handling.sh +++ b/install/error-handling.sh @@ -88,12 +88,12 @@ trap_with_arg() { DID_CLEAN_UP=0 # the cleanup function will be the exit point cleanup () { + local retcode=$? local cmd="${BASH_COMMAND}" if [[ "$DID_CLEAN_UP" -eq 1 ]]; then return 0; fi DID_CLEAN_UP=1 - local retcode=$? if [[ "$1" != "EXIT" ]]; then set +o xtrace printf -v err '%s' "Error in ${BASH_SOURCE[1]}:${BASH_LINENO[0]}." From c6fa96b0c731ab10daf6622dc460dfb863e167b6 Mon Sep 17 00:00:00 2001 From: Chad Whitacre Date: Fri, 9 Sep 2022 11:42:21 -0400 Subject: [PATCH 13/21] Fix over-indentation --- install/error-handling.sh | 26 +++++++++++++------------- 1 file changed, 13 insertions(+), 13 deletions(-) diff --git a/install/error-handling.sh b/install/error-handling.sh index 8564607a50d..7ff4d48c265 100644 --- a/install/error-handling.sh +++ b/install/error-handling.sh @@ -55,19 +55,19 @@ else do read -p "y or n? " yn case $yn in - y | yes | 1) - export REPORT_ERRORS=1 - echo "yes" > $reporterrors - echo - echo -n "Thank you." - ;; - n | no | 0) - export REPORT_ERRORS=0 - echo "no" > $reporterrors - echo - echo -n "Understood." - ;; - *) yn="";; + y | yes | 1) + export REPORT_ERRORS=1 + echo "yes" > $reporterrors + echo + echo -n "Thank you." + ;; + n | no | 0) + export REPORT_ERRORS=0 + echo "no" > $reporterrors + echo + echo -n "Understood." + ;; + *) yn="";; esac done From 55a8d594390e91034c280beda5144488a0bdf218 Mon Sep 17 00:00:00 2001 From: Chad Whitacre Date: Fri, 9 Sep 2022 11:47:23 -0400 Subject: [PATCH 14/21] Swing back a bit towards previous - give reason for data collection - case branches on single lines --- install/error-handling.sh | 16 +++------------- 1 file changed, 3 insertions(+), 13 deletions(-) diff --git a/install/error-handling.sh b/install/error-handling.sh index 7ff4d48c265..e5104b8b112 100644 --- a/install/error-handling.sh +++ b/install/error-handling.sh @@ -40,7 +40,7 @@ else echo "(Btw, we send this to our own self-hosted Sentry instance, not to Sentry SaaS," echo "so that we can be in this together.)" echo - echo "Here's the info we may collect:" + echo "Here's the info we may collect in order to help us improve the installer:" echo echo " - OS username" echo " - IP address" @@ -55,18 +55,8 @@ else do read -p "y or n? " yn case $yn in - y | yes | 1) - export REPORT_ERRORS=1 - echo "yes" > $reporterrors - echo - echo -n "Thank you." - ;; - n | no | 0) - export REPORT_ERRORS=0 - echo "no" > $reporterrors - echo - echo -n "Understood." - ;; + y | yes | 1) export REPORT_ERRORS=1; echo "yes" > $reporterrors; echo; echo -n "Thank you.";; + n | no | 0) export REPORT_ERRORS=0; echo "no" > $reporterrors; echo; echo -n "Understood.";; *) yn="";; esac done From 6c175d8ef0fb086e07f5b5c0880d4344ef551210 Mon Sep 17 00:00:00 2001 From: hubertdeng123 Date: Fri, 9 Sep 2022 13:53:14 -0700 Subject: [PATCH 15/21] fix sentry-cli for linux/amd64 --- install/error-handling.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/install/error-handling.sh b/install/error-handling.sh index e5104b8b112..0bbebb09ba4 100644 --- a/install/error-handling.sh +++ b/install/error-handling.sh @@ -6,7 +6,7 @@ export SENTRY_PROJECT=installer function send_event { if [[ $DOCKER_PLATFORM == "linux/amd64" ]]; then - local sentry_cli="docker run --rm -v \$(pwd):/work -e SENTRY_DSN=$SENTRY_DSN getsentry/sentry-cli" + local sentry_cli="docker run --platform linux/amd64 --rm -v $basedir:/work -e SENTRY_DSN=$SENTRY_DSN getsentry/sentry-cli" else if ! command -v sentry-cli &> /dev/null; then echo "sentry-cli could not be found, please install it" From a966c1e0c601ddc28f0f8a999d54cf274fb1fd0a Mon Sep 17 00:00:00 2001 From: hubertdeng123 Date: Fri, 9 Sep 2022 14:44:39 -0700 Subject: [PATCH 16/21] add sentry org and project to env variables for dockerized sentry-cli --- install/error-handling.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/install/error-handling.sh b/install/error-handling.sh index 0bbebb09ba4..2961673514f 100644 --- a/install/error-handling.sh +++ b/install/error-handling.sh @@ -6,7 +6,7 @@ export SENTRY_PROJECT=installer function send_event { if [[ $DOCKER_PLATFORM == "linux/amd64" ]]; then - local sentry_cli="docker run --platform linux/amd64 --rm -v $basedir:/work -e SENTRY_DSN=$SENTRY_DSN getsentry/sentry-cli" + local sentry_cli="docker run --platform linux/amd64 --rm -v $basedir:/work -e SENTRY_ORG=$SENTRY_ORG -e SENTRY_PROJECT=$SENTRY_PROJECT -e SENTRY_DSN=$SENTRY_DSN getsentry/sentry-cli" else if ! command -v sentry-cli &> /dev/null; then echo "sentry-cli could not be found, please install it" From de504d8c9fb696c2df7a33cf0c454a3477488a0f Mon Sep 17 00:00:00 2001 From: Chad Whitacre Date: Mon, 12 Sep 2022 18:46:18 -0400 Subject: [PATCH 17/21] Don't prompt for .reporterrors if non-reportable --- install/error-handling.sh | 31 ++++++++++++++++++++++++++----- 1 file changed, 26 insertions(+), 5 deletions(-) diff --git a/install/error-handling.sh b/install/error-handling.sh index 2961673514f..13902cf6326 100644 --- a/install/error-handling.sh +++ b/install/error-handling.sh @@ -4,12 +4,28 @@ export SENTRY_DSN='https://19555c489ded4769978daae92f2346ca@self-hosted.getsentr export SENTRY_ORG=self-hosted export SENTRY_PROJECT=installer +function check_for_linux_amd64 { + # This is the only platform for which we have a build of sentry-cli. + # I guess this could theoretically be dynamic (try to fetch a build). + test $DOCKER_PLATFORM == "linux/amd64" +} +function check_for_sentry_cli { + command -v sentry-cli &> /dev/null +} +function check_for_reportability { + # I'm sure this isn't the most terse syntax, but it's the one I could get to work. + if check_for_linux_amd64 || check_for_sentry_cli; then return 0; else return 1; fi +} + function send_event { - if [[ $DOCKER_PLATFORM == "linux/amd64" ]]; then + if check_for_linux_amd64; then local sentry_cli="docker run --platform linux/amd64 --rm -v $basedir:/work -e SENTRY_ORG=$SENTRY_ORG -e SENTRY_PROJECT=$SENTRY_PROJECT -e SENTRY_DSN=$SENTRY_DSN getsentry/sentry-cli" else - if ! command -v sentry-cli &> /dev/null; then - echo "sentry-cli could not be found, please install it" + if ! check_for_sentry_cli; then + echo "If you would like to report this error to Sentry, please install sentry-cli and rerun:" + echo + echo " https://docs.sentry.io/product/cli/installation/" + echo exit 1 fi local sentry_cli=sentry-cli @@ -25,10 +41,15 @@ if [[ -f $reporterrors ]]; then cat $reporterrors if [[ "$(cat $reporterrors)" == "yes" ]]; then export REPORT_ERRORS=1 + if ! check_for_reportability; then + echo "Sadly we don't have sentry-cli. Install it first in order to report errors:" + echo + echo " https://docs.sentry.io/product/cli/installation/" + fi else export REPORT_ERRORS=0 fi -else +else if check_for_reportability; then echo echo "Hey, so ... we would love to find out when you hit an issue with this here" echo "installer you are running. Turns out there is an app for that, called Sentry." @@ -65,7 +86,7 @@ else echo "prompt again." echo sleep 5 -fi +fi; fi # Courtesy of https://stackoverflow.com/a/2183063/90297 trap_with_arg() { From 6a8ee8cc6a31f4a892d640a80bb87a7e9ae456cf Mon Sep 17 00:00:00 2001 From: Chad Whitacre Date: Mon, 12 Sep 2022 19:07:59 -0400 Subject: [PATCH 18/21] Don't report errors by default --- install/error-handling.sh | 1 + 1 file changed, 1 insertion(+) diff --git a/install/error-handling.sh b/install/error-handling.sh index 13902cf6326..ecaf2643917 100644 --- a/install/error-handling.sh +++ b/install/error-handling.sh @@ -3,6 +3,7 @@ echo "${_group}Setting up error handling ..." export SENTRY_DSN='https://19555c489ded4769978daae92f2346ca@self-hosted.getsentry.net/3' export SENTRY_ORG=self-hosted export SENTRY_PROJECT=installer +export REPORT_ERRORS=0 function check_for_linux_amd64 { # This is the only platform for which we have a build of sentry-cli. From 382d2bfeb06fdec444eac0d3584b3ac49c75fcec Mon Sep 17 00:00:00 2001 From: hubertdeng123 Date: Mon, 12 Sep 2022 17:08:36 -0700 Subject: [PATCH 19/21] use dockerized sentry-cli for arm64 --- install/error-handling.sh | 31 +------------------------------ 1 file changed, 1 insertion(+), 30 deletions(-) diff --git a/install/error-handling.sh b/install/error-handling.sh index ecaf2643917..1b11e47a0b8 100644 --- a/install/error-handling.sh +++ b/install/error-handling.sh @@ -5,32 +5,8 @@ export SENTRY_ORG=self-hosted export SENTRY_PROJECT=installer export REPORT_ERRORS=0 -function check_for_linux_amd64 { - # This is the only platform for which we have a build of sentry-cli. - # I guess this could theoretically be dynamic (try to fetch a build). - test $DOCKER_PLATFORM == "linux/amd64" -} -function check_for_sentry_cli { - command -v sentry-cli &> /dev/null -} -function check_for_reportability { - # I'm sure this isn't the most terse syntax, but it's the one I could get to work. - if check_for_linux_amd64 || check_for_sentry_cli; then return 0; else return 1; fi -} - function send_event { - if check_for_linux_amd64; then - local sentry_cli="docker run --platform linux/amd64 --rm -v $basedir:/work -e SENTRY_ORG=$SENTRY_ORG -e SENTRY_PROJECT=$SENTRY_PROJECT -e SENTRY_DSN=$SENTRY_DSN getsentry/sentry-cli" - else - if ! check_for_sentry_cli; then - echo "If you would like to report this error to Sentry, please install sentry-cli and rerun:" - echo - echo " https://docs.sentry.io/product/cli/installation/" - echo - exit 1 - fi - local sentry_cli=sentry-cli - fi + local sentry_cli="docker run --rm -v $basedir:/work -e SENTRY_ORG=$SENTRY_ORG -e SENTRY_PROJECT=$SENTRY_PROJECT -e SENTRY_DSN=$SENTRY_DSN getsentry/sentry-cli" command pushd .. > /dev/null $sentry_cli send-event --no-environ -f "$1" -m "$2" --logfile $log_file command popd > /dev/null @@ -42,11 +18,6 @@ if [[ -f $reporterrors ]]; then cat $reporterrors if [[ "$(cat $reporterrors)" == "yes" ]]; then export REPORT_ERRORS=1 - if ! check_for_reportability; then - echo "Sadly we don't have sentry-cli. Install it first in order to report errors:" - echo - echo " https://docs.sentry.io/product/cli/installation/" - fi else export REPORT_ERRORS=0 fi From 0e1239c78f87f2b810576f6fc7327b6e8c908a85 Mon Sep 17 00:00:00 2001 From: hubertdeng123 Date: Mon, 12 Sep 2022 17:14:29 -0700 Subject: [PATCH 20/21] fix broken error-handling script --- install/error-handling.sh | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/install/error-handling.sh b/install/error-handling.sh index 1b11e47a0b8..2af4a95d394 100644 --- a/install/error-handling.sh +++ b/install/error-handling.sh @@ -21,7 +21,7 @@ if [[ -f $reporterrors ]]; then else export REPORT_ERRORS=0 fi -else if check_for_reportability; then +else echo echo "Hey, so ... we would love to find out when you hit an issue with this here" echo "installer you are running. Turns out there is an app for that, called Sentry." @@ -58,7 +58,7 @@ else if check_for_reportability; then echo "prompt again." echo sleep 5 -fi; fi +fi # Courtesy of https://stackoverflow.com/a/2183063/90297 trap_with_arg() { From 5df2ab645f186044e4af3b809b6ee7b334be990d Mon Sep 17 00:00:00 2001 From: Chad Whitacre Date: Tue, 13 Sep 2022 12:27:54 -0400 Subject: [PATCH 21/21] Pull sentry-cli early so we can fail gracefully --- install/error-handling.sh | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/install/error-handling.sh b/install/error-handling.sh index 2af4a95d394..74793a2bb80 100644 --- a/install/error-handling.sh +++ b/install/error-handling.sh @@ -60,6 +60,14 @@ else sleep 5 fi +# Make sure we can use sentry-cli if we need it. +if [ "$REPORT_ERRORS" == 1 ]; then + if ! docker pull getsentry/sentry-cli:latest; then + echo "Failed to pull sentry-cli, won't report errors after all." + export REPORT_ERRORS=0 + fi; +fi; + # Courtesy of https://stackoverflow.com/a/2183063/90297 trap_with_arg() { func="$1" ; shift