Skip to content

Commit c4ddb01

Browse files
gmrclaude
andcommitted
Add Sentry CLI, conditional source map serving, and startup upload
- Dockerfile: getsentry/sentry-cli stage copies binary to runtime image - Caddyfile: .map requests 404 unless SERVE_SOURCE_MAPS=true - entrypoint.sh: uploads source maps to Sentry at startup when SENTRY_AUTH_TOKEN, SENTRY_ORG, and SENTRY_PROJECT are all set; honours SENTRY_URL for self-hosted instances and SENTRY_RELEASE for release correlation Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
1 parent d3cbb8f commit c4ddb01

3 files changed

Lines changed: 49 additions & 1 deletion

File tree

Caddyfile

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,18 @@
3636
reverse_proxy 127.0.0.1:8000
3737
}
3838

39+
@sourcemaps path *.map
40+
handle @sourcemaps {
41+
@maps_allowed expression `{env.SERVE_SOURCE_MAPS} == "true"`
42+
handle @maps_allowed {
43+
root * /srv/ui
44+
file_server
45+
}
46+
handle {
47+
respond "Not Found" 404
48+
}
49+
}
50+
3951
handle {
4052
root * /srv/ui
4153
try_files {path} /index.html

Dockerfile

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,12 @@ RUN uv venv --python $(which python3) $UV_PROJECT_DIRECTORY \
5353
FROM caddy:${CADDY_VERSION} AS caddy
5454

5555
# ---------------------------------------------------------------------------
56-
# Stage 4: Final runtime image
56+
# Stage 4: Sentry CLI binary
57+
# ---------------------------------------------------------------------------
58+
FROM getsentry/sentry-cli AS sentry-cli
59+
60+
# ---------------------------------------------------------------------------
61+
# Stage 5: Final runtime image
5762
# ---------------------------------------------------------------------------
5863
FROM python:${PYTHON_VERSION}-slim AS runtime
5964

@@ -71,6 +76,9 @@ COPY --from=python-builder --chown=imbi:users /app/ /app/
7176
# Copy Caddy binary
7277
COPY --from=caddy /usr/bin/caddy /usr/local/bin/caddy
7378

79+
# Copy Sentry CLI binary
80+
COPY --from=sentry-cli /bin/sentry-cli /usr/local/bin/sentry-cli
81+
7482
# Copy Caddyfile
7583
COPY Caddyfile /etc/caddy/Caddyfile
7684

entrypoint.sh

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -97,6 +97,34 @@ esac
9797

9898
check_errors "service '$IMBI_SERVICE'"
9999

100+
# --------------------------------------------------------------------------
101+
# Optional: upload source maps to Sentry
102+
# --------------------------------------------------------------------------
103+
# Runs when SENTRY_AUTH_TOKEN, SENTRY_ORG, and SENTRY_PROJECT are all set.
104+
# SENTRY_RELEASE defaults to unversioned if not provided.
105+
# Maps remain in the image; whether they are served is controlled by
106+
# the SERVE_SOURCE_MAPS env var (Caddy returns 404 unless it is "true").
107+
108+
upload_sourcemaps() {
109+
if [ -z "${SENTRY_AUTH_TOKEN:-}" ] || \
110+
[ -z "${SENTRY_ORG:-}" ] || \
111+
[ -z "${SENTRY_PROJECT:-}" ]; then
112+
return
113+
fi
114+
echo "Uploading source maps to Sentry..."
115+
local args="--org $SENTRY_ORG --project $SENTRY_PROJECT"
116+
if [ -n "${SENTRY_RELEASE:-}" ]; then
117+
args="$args --release $SENTRY_RELEASE"
118+
fi
119+
if [ -n "${SENTRY_URL:-}" ]; then
120+
args="$args --url $SENTRY_URL"
121+
fi
122+
sentry-cli sourcemaps upload $args /srv/ui/assets/
123+
echo "Source maps uploaded."
124+
}
125+
126+
upload_sourcemaps
127+
100128
# --------------------------------------------------------------------------
101129
# Service startup
102130
# --------------------------------------------------------------------------

0 commit comments

Comments
 (0)