Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Reference paths relative to project root #1800

Merged
merged 24 commits into from
Feb 17, 2023
Merged
Show file tree
Hide file tree
Changes from 6 commits
Commits
Show all changes
24 commits
Select commit Hold shift + click to select a range
67b396b
Reference paths relative to the current script or project root
spawnia Nov 7, 2022
734c80f
Fix codestyle
spawnia Nov 7, 2022
227e4ba
Fix non-executables
spawnia Nov 7, 2022
4f5d509
Fix codestyle
spawnia Nov 7, 2022
a2ea008
Fix custom-ca-roots test
spawnia Nov 8, 2022
2ee767d
Fix log_path -> log_file
spawnia Nov 8, 2022
1d59507
Update _unit-test/error-handling-test.sh
spawnia Nov 8, 2022
7292db7
All paths relative to project root
spawnia Nov 10, 2022
428a2c1
Quote jq arguments
spawnia Nov 10, 2022
60c88c1
Debug in CI
spawnia Nov 11, 2022
ac90579
debug and hopefully pass
spawnia Nov 11, 2022
32bac8d
Remove debug
spawnia Nov 11, 2022
766a42e
Merge remote-tracking branch 'upstream/master' into explicit-path-ref…
spawnia Nov 17, 2022
726ef54
Remove new usages of basedir
spawnia Nov 17, 2022
ea46ec8
Merge remote-tracking branch 'upstream/master' into explicit-path-ref…
spawnia Nov 22, 2022
668f9e2
Merge branch 'master' into explicit-path-references
spawnia Dec 20, 2022
4772621
Merge remote-tracking branch 'upstream/master' into explicit-path-ref…
spawnia Jan 18, 2023
b36c297
remove basedir, quote DOCKER_PLATFORM
spawnia Jan 18, 2023
84adc23
avoid unnecessary loop
spawnia Jan 18, 2023
34a5f20
actually build each service individually
spawnia Jan 19, 2023
59a7bef
Merge branch 'master' into explicit-path-references
spawnia Jan 20, 2023
2dcc03a
fix path to test files
spawnia Jan 20, 2023
e27906d
fix shellcheck errors
spawnia Jan 20, 2023
0d8c0e0
Merge remote-tracking branch 'upstream/master' into explicit-path-ref…
spawnia Feb 8, 2023
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@
hooks:
- id: check-case-conflict
- id: check-executables-have-shebangs
exclude: ^(install/|_unit-test/_test_setup.sh)
spawnia marked this conversation as resolved.
Show resolved Hide resolved
- id: check-merge-conflict
- id: check-symlinks
- id: end-of-file-fixer
Expand Down
10 changes: 4 additions & 6 deletions _integration-test/custom-ca-roots/setup.sh
100755 → 100644
Original file line number Diff line number Diff line change
@@ -1,10 +1,8 @@
#! /usr/bin/env bash
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:./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/_integration-test/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)
Expand Down Expand Up @@ -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/_integration-test/custom-ca-roots/test.py" "$PROJECT_ROOT/sentry/test-custom-ca-roots.py"

$dc up -d fixture-custom-ca-roots
3 changes: 1 addition & 2 deletions _integration-test/custom-ca-roots/teardown.sh
100755 → 100644
Original file line number Diff line number Diff line change
@@ -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
5 changes: 3 additions & 2 deletions _integration-test/ensure-customizations-not-present.sh
Original file line number Diff line number Diff line change
@@ -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)
spawnia marked this conversation as resolved.
Show resolved Hide resolved
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"
Expand Down
5 changes: 3 additions & 2 deletions _integration-test/ensure-customizations-work.sh
Original file line number Diff line number Diff line change
@@ -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"
Expand Down
9 changes: 5 additions & 4 deletions _integration-test/run.sh
Original file line number Diff line number Diff line change
@@ -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}"
Expand Down Expand Up @@ -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}"
6 changes: 4 additions & 2 deletions _unit-test/_test_setup.sh
Original file line number Diff line number Diff line change
@@ -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)"
Expand All @@ -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,
Expand Down
10 changes: 6 additions & 4 deletions _unit-test/create-docker-volumes-test.sh
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -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"
Expand Down
15 changes: 9 additions & 6 deletions _unit-test/ensure-relay-credentials-test.sh
Original file line number Diff line number Diff line change
@@ -1,25 +1,28 @@
#!/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"

# 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"

Expand Down
24 changes: 13 additions & 11 deletions _unit-test/error-handling-test.sh
Original file line number Diff line number Diff line change
@@ -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() {
Expand All @@ -12,15 +14,15 @@ send_envelope() {

export -f send_envelope
echo "Testing initial send_event"
export log_path="$basedir/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 "$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"
Expand All @@ -33,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.
spawnia marked this conversation as resolved.
Show resolved Hide resolved
'\''local cmd="${BASH_COMMAND}"'\'' exited with status 0

Expand All @@ -45,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

Expand Down
10 changes: 6 additions & 4 deletions _unit-test/geoip-test.sh
Original file line number Diff line number Diff line change
@@ -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
5 changes: 2 additions & 3 deletions clean.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
41 changes: 21 additions & 20 deletions install.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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"
spawnia marked this conversation as resolved.
Show resolved Hide resolved
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"
27 changes: 10 additions & 17 deletions install/_lib.sh
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -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
Expand Down
2 changes: 1 addition & 1 deletion install/build-docker-images.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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."

Expand Down
3 changes: 2 additions & 1 deletion install/check-minimum-requirements.sh
Original file line number Diff line number Diff line change
@@ -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() {
Expand Down
Empty file modified install/detect-platform.sh
100755 → 100644
Empty file.
2 changes: 1 addition & 1 deletion install/ensure-files-from-examples.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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}"
4 changes: 2 additions & 2 deletions install/ensure-relay-credentials.sh
Original file line number Diff line number Diff line change
@@ -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

Expand Down
Loading