CI: upload client sourcemaps to GlitchTip; stop serving .map files
- Dockerfile: Vite's maps move from client/dist/assets to /app/sourcemaps, outside the express.static root. caelum.network/assets/*.js.map answered 200 (889 KB for the index bundle) before this. - New main-only job sourcemaps-upload (stage deploy, needs image-build, allow_failure). It copies bundles and maps out of the just-built image and runs getsentry/sentry-cli:2.58.6 on the `web` network against http://glitchtip:8000: releases new, then sourcemaps upload for release caelum@<client version> with url prefix ~/assets. Token comes from GLITCHTIP_AUTH_TOKEN and exists only in this job, so the vite plugin still never uploads. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
co-authored by
Claude Opus 5.5
parent
713736a6a9
commit
e40467d2e2
@@ -304,6 +304,61 @@ image-test:
|
||||
[ "$ok" = 1 ] || { echo "SMOKE TEST FAILED"; exit 1; }
|
||||
echo "SMOKE TEST PASSED"
|
||||
|
||||
# ---- upload client sourcemaps to GlitchTip (main only) ----
|
||||
#
|
||||
# Release-based upload: no debug IDs are injected at build, so GlitchTip pairs
|
||||
# a frame with its map by release name plus file name. The release must equal
|
||||
# what client/src/sentry.js stamps on events, `caelum@<client package version>`.
|
||||
#
|
||||
# The maps come out of the image this pipeline just built (/app/sourcemaps,
|
||||
# kept outside the served client/dist), so they belong to the exact bundles
|
||||
# that deploy serves. Job containers cannot reach https://bugs.extant2000.com
|
||||
# (hairpin), so sentry-cli runs as a sibling container on the `web` network
|
||||
# and talks to http://glitchtip:8000. Files go in with `docker cp`, because a
|
||||
# bind mount would resolve against the host, not this job's filesystem.
|
||||
#
|
||||
# SENTRY_AUTH_TOKEN exists only in this job. The vite plugin uploads when it
|
||||
# sees that variable, and client-build and the image build never get it.
|
||||
# allow_failure: GlitchTip being down must not hold a deploy.
|
||||
sourcemaps-upload:
|
||||
stage: deploy
|
||||
image: docker:27
|
||||
needs: [image-build]
|
||||
rules:
|
||||
- if: $CI_COMMIT_BRANCH == "main"
|
||||
allow_failure: true
|
||||
variables:
|
||||
SENTRY_CLI_IMAGE: getsentry/sentry-cli:2.58.6
|
||||
SENTRY_URL: http://glitchtip:8000
|
||||
SENTRY_ORG: extant-2000
|
||||
SENTRY_PROJECT: caelum
|
||||
SENTRY_AUTH_TOKEN: $GLITCHTIP_AUTH_TOKEN
|
||||
script:
|
||||
- |
|
||||
set -eu
|
||||
[ -n "$SENTRY_AUTH_TOKEN" ] || { echo "GLITCHTIP_AUTH_TOKEN is not set; skipping"; exit 1; }
|
||||
VERSION=$(sed -n 's/^ "version": *"\([^"]*\)".*/\1/p' client/package.json | head -1)
|
||||
[ -n "$VERSION" ] || { echo "no version in client/package.json"; exit 1; }
|
||||
RELEASE="caelum@$VERSION"
|
||||
SRC="smap-src-$CI_PIPELINE_ID"
|
||||
UP="smap-up-$CI_PIPELINE_ID"
|
||||
cleanup() { docker rm -f "$SRC" "$UP" >/dev/null 2>&1 || true; }
|
||||
trap cleanup EXIT
|
||||
echo "uploading sourcemaps for $RELEASE from $IMAGE:$CI_COMMIT_SHORT_SHA"
|
||||
# Bundles plus their maps, side by side, as sentry-cli pairs x.js with x.js.map.
|
||||
docker create --name "$SRC" "$IMAGE:$CI_COMMIT_SHORT_SHA" >/dev/null
|
||||
rm -rf smap && mkdir -p smap/work
|
||||
docker cp "$SRC:/app/client/dist/assets" smap/work/assets
|
||||
docker cp "$SRC:/app/sourcemaps/assets/." smap/work/assets/
|
||||
echo "$(ls smap/work/assets/*.js | wc -l) js, $(ls smap/work/assets/*.map | wc -l) maps"
|
||||
CLI="--network web -e SENTRY_URL -e SENTRY_ORG -e SENTRY_PROJECT -e SENTRY_AUTH_TOKEN"
|
||||
docker run --rm $CLI "$SENTRY_CLI_IMAGE" releases new "$RELEASE"
|
||||
docker create --name "$UP" $CLI "$SENTRY_CLI_IMAGE" \
|
||||
sourcemaps upload --release "$RELEASE" --url-prefix "~/assets" /work/assets >/dev/null
|
||||
# Lands at /work/assets (the image WORKDIR is /work).
|
||||
docker cp smap/work "$UP:/"
|
||||
docker start -a "$UP"
|
||||
|
||||
# ---- deploy: local docker compose against the live stack ----
|
||||
deploy:
|
||||
stage: deploy
|
||||
|
||||
+10
-2
@@ -36,8 +36,15 @@ COPY client ./client
|
||||
COPY scripts ./scripts
|
||||
COPY server.js ./
|
||||
|
||||
# Build the Vue SPA.
|
||||
RUN cd client && npm run build
|
||||
# Build the Vue SPA, then move the sourcemaps out of the served tree.
|
||||
# express.static serves everything under client/dist, so a map left there is
|
||||
# public (caelum.network/assets/*.js.map answered 200 before this). Vite
|
||||
# writes every map to dist/assets. /app/sourcemaps is not served; the
|
||||
# sourcemaps-upload CI job copies it out of the image and sends it to
|
||||
# GlitchTip.
|
||||
RUN cd client && npm run build \
|
||||
&& mkdir -p /app/sourcemaps/assets \
|
||||
&& mv dist/assets/*.map /app/sourcemaps/assets/
|
||||
|
||||
# ---------- runtime stage ----------
|
||||
FROM node:22-alpine AS runtime
|
||||
@@ -55,6 +62,7 @@ WORKDIR /app
|
||||
COPY --from=build /app/server ./server
|
||||
COPY --from=build /app/nox ./nox
|
||||
COPY --from=build /app/client/dist ./client/dist
|
||||
COPY --from=build /app/sourcemaps ./sourcemaps
|
||||
COPY --from=build /app/package.json ./
|
||||
COPY --from=build /app/server.js ./
|
||||
COPY --from=build /app/node_modules ./node_modules
|
||||
|
||||
Reference in New Issue
Block a user