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 all 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 @@ -17,7 +17,6 @@ repos:
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=docker-compose.yml:_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=_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)
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 _integration-test/custom-ca-roots/test.py 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 certificates/test-custom-ca-roots.crt sentry/test-custom-ca-roots.py
unset COMPOSE_FILE
5 changes: 2 additions & 3 deletions _integration-test/ensure-customizations-not-present.sh
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
#!/usr/bin/env bash
set -ex

source "$(dirname $0)/../install/_lib.sh"

source ../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"
Expand Down
5 changes: 2 additions & 3 deletions _integration-test/ensure-customizations-work.sh
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
#!/usr/bin/env bash
set -ex

source "$(dirname $0)/../install/_lib.sh"

source ../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"
Expand Down
23 changes: 11 additions & 12 deletions _integration-test/run.sh
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
#!/usr/bin/env bash
set -ex

source "$(dirname $0)/../install/_lib.sh"

source ../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}"
Expand Down Expand Up @@ -51,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 "['\"]" '
Expand All @@ -78,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}"
Expand Down Expand Up @@ -117,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}"
Expand Down Expand Up @@ -145,16 +144,16 @@ 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')
if [ -z "$EVENT_PROCESSED" ]; then
sleep $i
sleep "$i"
else
break
fi
Expand All @@ -167,9 +166,9 @@ fi
echo "${_endgroup}"

echo "${_group}Test custom CAs work ..."
source ./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 ./custom-ca-roots/teardown.sh
source _integration-test/custom-ca-roots/teardown.sh
echo "${_endgroup}"

# Table formatting based on https://stackoverflow.com/a/39144364
Expand Down
16 changes: 9 additions & 7 deletions _unit-test/_test_setup.sh
Original file line number Diff line number Diff line change
@@ -1,27 +1,29 @@
set -euo pipefail
source "$(dirname $0)/../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)"

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 👍"
}

teardown() {
test "${DEBUG:-}" || rm -rf "$_SANDBOX"
cd "$_ORIGIN"
}

setup() {
cd ..

# 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,
Expand All @@ -47,7 +49,7 @@ setup() {
esac
done

cd "$_SANDBOX/install"
cd "$_SANDBOX"

trap teardown EXIT
}
Expand Down
9 changes: 5 additions & 4 deletions _unit-test/create-docker-volumes-test.sh
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
#!/usr/bin/env bash
source "$(dirname $0)/_test_setup.sh"

source _unit-test/_test_setup.sh

get_volumes() {
# If grep returns no strings, we still want to return without error
Expand All @@ -20,9 +21,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 install/create-docker-volumes.sh
source install/create-docker-volumes.sh
source install/create-docker-volumes.sh

after=$(get_volumes)
test "$after" == "$expected_volumes"
Expand Down
15 changes: 8 additions & 7 deletions _unit-test/ensure-relay-credentials-test.sh
Original file line number Diff line number Diff line change
@@ -1,25 +1,26 @@
#!/usr/bin/env bash
source "$(dirname $0)/_test_setup.sh"
source 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="../relay/config.yml"
creds_file="../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 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"
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 install/ensure-relay-credentials.sh
test "$(cat $cfg_file)" = "GARBAGE"
test "$(cat $creds_file)" = "MOAR GARBAGE"

Expand Down
27 changes: 14 additions & 13 deletions _unit-test/error-handling-test.sh
Original file line number Diff line number Diff line change
@@ -1,12 +1,13 @@
#!/usr/bin/env bash
source "$(dirname $0)/_test_setup.sh"

source _unit-test/_test_setup.sh

export REPORT_SELF_HOSTED_ISSUES=1

# This is set up in dc-detect-version.sh, but for
# our purposes we don't care about proxies.
dbuild="docker build"
source error-handling.sh
source install/error-handling.sh

# mock send_envelope
send_envelope() {
Expand All @@ -15,15 +16,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=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 _unit-test/snapshots/sentry-envelope-12345123451234512345123451234512)"
echo "Pass."

echo "Testing send_event duplicate"
Expand All @@ -36,10 +37,10 @@ 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"
test "$CLEANUP_RESPONSE" == 'Error in ./_unit-test/error-handling-test.sh:40.
rm "$log_file"
test "$CLEANUP_RESPONSE" == 'Error in _unit-test/error-handling-test.sh:41.
'\''local cmd="${BASH_COMMAND}"'\'' exited with status 0

Cleaning up...'
Expand All @@ -48,10 +49,10 @@ 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"
test "$CLEANUP_RESPONSE" == 'Error in ./_unit-test/error-handling-test.sh:52.
rm "$log_file"
test "$CLEANUP_RESPONSE" == 'Error in _unit-test/error-handling-test.sh:53.
'\''local cmd="${BASH_COMMAND}"'\'' exited with status 0

*NOT* cleaning up, to clean your environment run "docker compose stop".'
Expand Down
9 changes: 5 additions & 4 deletions _unit-test/geoip-test.sh
Original file line number Diff line number Diff line change
@@ -1,16 +1,17 @@
#!/usr/bin/env bash
source "$(dirname $0)/_test_setup.sh"

mmdb="../geoip/GeoLite2-City.mmdb"
source _unit-test/_test_setup.sh

mmdb=geoip/GeoLite2-City.mmdb

# Starts with no mmdb, ends up with empty.
test ! -f $mmdb
source geoip.sh
source install/geoip.sh
diff -rub $mmdb $mmdb.empty

# Doesn't clobber existing, though.
echo GARBAGE >$mmdb
source geoip.sh
source install/geoip.sh
test "$(cat $mmdb)" = "GARBAGE"

report_success
2 changes: 0 additions & 2 deletions clean.sh
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,6 @@ if [ -n "${DEBUG:-}" ]; then
set -x
fi

cd "$(dirname $0)"

source install/dc-detect-version.sh

function confirm() {
Expand Down
40 changes: 20 additions & 20 deletions install.sh
Original file line number Diff line number Diff line change
Expand Up @@ -7,29 +7,29 @@ if [[ -n "$MSYSTEM" ]]; then
exit 1
fi

source "$(dirname $0)/install/_lib.sh" # does a `cd .../install/`, among other things
source 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 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 check-latest-commit.sh
source check-minimum-requirements.sh
source install/check-latest-commit.sh
source 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 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
Loading