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

ref: allow hosted js sdk bundles #3365

Merged
merged 19 commits into from
Oct 7, 2024
Merged
Show file tree
Hide file tree
Changes from 16 commits
Commits
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
26 changes: 26 additions & 0 deletions _unit-test/js-sdk-assets-test.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
#!/usr/bin/env bash

source _unit-test/_test_setup.sh
source install/dc-detect-version.sh
$dcb --force-rm web

export SETUP_JS_SDK_ASSETS=1

source install/setup-js-sdk-assets.sh

sdk_files=$(docker compose run --no-deps --rm -v "sentry-nginx-www:/var/www" nginx ls -lah /var/www/js-sdk/)
sdk_tree=$(docker compose run --no-deps --rm -v "sentry-nginx-www:/var/www" nginx tree /var/www/js-sdk/ | tail -n 1)

# `sdk_files` should contains 2 lines, `7.*` and `8.*`
echo $sdk_files
total_directories=$(echo "$sdk_files" | grep -c '[78]\.[0-9]*\.[0-9]*$')
echo $total_directories
test "2" == "$total_directories"
echo "Pass"

# `sdk_tree` should outputs "3 directories, 10 files"
echo "$sdk_tree"
test "2 directories, 10 files" == "$(echo "$sdk_tree")"
echo "Pass"

report_success
4 changes: 4 additions & 0 deletions docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -460,6 +460,7 @@ services:
source: ./nginx
target: /etc/nginx
- sentry-nginx-cache:/var/cache/nginx
- sentry-nginx-www:/var/www
depends_on:
- web
- relay
Expand Down Expand Up @@ -529,6 +530,9 @@ volumes:
external: true
sentry-symbolicator:
external: true
# This volume stores JS SDK assets and the data inside this volume should
# be cleaned periodically on upgrades.
sentry-nginx-www:
# This volume stores profiles and should be persisted.
# Not being external will still persist data across restarts.
# It won't persist if someone does a docker compose down -v.
Expand Down
1 change: 1 addition & 0 deletions install.sh
Original file line number Diff line number Diff line change
Expand Up @@ -36,4 +36,5 @@ source install/bootstrap-snuba.sh
source install/upgrade-postgres.sh
source install/set-up-and-migrate-database.sh
source install/geoip.sh
source install/setup-js-sdk-assets.sh
source install/wrap-up.sh
37 changes: 37 additions & 0 deletions install/setup-js-sdk-assets.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
# This will only run if the SETUP_JS_SDK_ASSETS environment variable is set to 1
if [[ "${SETUP_JS_SDK_ASSETS:-}" == "1" ]]; then
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

IMO if we're going to include this as part of the install script moving forwards, I'd like to see it in the .env file just to surface this as something people can set up. We can leave it as default for opt-in

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh not you too :(

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh sorry I read that wrong. Lol.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Okay done

echo "${_group}Setting up JS SDK assets"

# If the `sentry-nginx-www` volume exists, we need to prune the contents.
# We don't want to fill the volume with old JS SDK assets.
# If people want to keep the old assets, they can set the environment variable
# `SETUP_JS_SDK_KEEP_OLD_ASSETS` to any value.
if [[ -z "${SETUP_JS_SDK_KEEP_OLD_ASSETS:-}" ]]; then
echo "Cleaning up old JS SDK assets..."
$dcr --no-deps --rm -v "sentry-nginx-www:/var/www" nginx rm -rf /var/www/js-sdk/*
fi

$dbuild -t sentry-self-hosted-jq-local --platform="$DOCKER_PLATFORM" jq

jq="docker run --rm -i sentry-self-hosted-jq-local"

loader_registry=$($dcr --no-deps --rm -T web cat /usr/src/sentry/src/sentry/loader/_registry.json)
# The `loader_registry` should start with "Updating certificates...", we want to delete that and the subsequent ca-certificates related lines.
# We want to remove everything before the first '{'.
loader_registry=$(echo "$loader_registry" | sed '0,/{/s/[^{]*//')

latest_js_v7=$(echo "$loader_registry" | $jq -r '.versions | reverse | map(select(.|any(.; startswith("7.")))) | .[0]')
latest_js_v8=$(echo "$loader_registry" | $jq -r '.versions | reverse | map(select(.|any(.; startswith("8.")))) | .[0]')

echo "Found JS SDKs v${latest_js_v7} and v${latest_js_v8}, downloading from upstream.."

# Download those two using wget
for version in "${latest_js_v7}" "${latest_js_v8}"; do
$dcr --no-deps --rm -v "sentry-nginx-www:/var/www" nginx mkdir -p /var/www/js-sdk/${version}
for variant in "tracing" "tracing.replay" "replay" "tracing.replay.feedback" "feedback"; do
$dcr --no-deps --rm -v "sentry-nginx-www:/var/www" nginx wget -q -O /var/www/js-sdk/${version}/bundle.${variant}.min.js "https://browser.sentry-cdn.com/${version}/bundle.${variant}.min.js"
done
done

echo "${_endgroup}"
fi
4 changes: 4 additions & 0 deletions nginx/nginx.conf
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,10 @@ http {
location ^~ /api/0/relays/ {
proxy_pass http://relay;
}
location ^~ /js-sdk/ {
autoindex on;
root /var/www/js-sdk;
}
location / {
proxy_pass http://sentry;
}
Expand Down
6 changes: 6 additions & 0 deletions sentry/sentry.conf.example.py
Original file line number Diff line number Diff line change
Expand Up @@ -378,6 +378,12 @@ def get_internal_network():
# JS SDK Loader #
#################

# Configure Sentry JS SDK bundle URL template for Loader Scripts.
# Learn more about the Loader Scripts: https://docs.sentry.io/platforms/javascript/install/loader/

# If you wish to host your own JS SDK bundles, set `SETUP_JS_SDK_ASSETS` environment variable to `1`
# on your `.env` or `.env.custom` file. Then, replace `browser.sentry-cdn.com` with your own public URL.
# For example: `https://sentry.example.com/bundles/sentry-bundle.min.js`
JS_SDK_LOADER_DEFAULT_SDK_URL = "https://browser.sentry-cdn.com/%s/bundle%s.min.js"


Expand Down
Loading