Skip to content

Commit

Permalink
fix(docker): add Sentry source map injection to Dockerfile (#1490)
Browse files Browse the repository at this point in the history
  • Loading branch information
philprime authored Feb 9, 2025
1 parent dd6c3f2 commit 3159bc6
Show file tree
Hide file tree
Showing 3 changed files with 50 additions and 35 deletions.
3 changes: 3 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,9 @@ COPY --from=build --chown=node:node /home/node/app/prisma ./prisma
COPY --from=build --chown=node:node /home/node/app/public ./public
COPY --from=build --chown=node:node /home/node/app/.next ./.next

# Inject Sentry Source Maps
RUN ./node_modules/.bin/sentry-cli sourcemaps inject .next

# select user
USER node

Expand Down
70 changes: 41 additions & 29 deletions docker/entrypoint.sh
Original file line number Diff line number Diff line change
Expand Up @@ -2,40 +2,52 @@

set -e

if [ ! -z "$SENTRY_RELEASE" ]; then
echo "Creating Sentry release '$SENTRY_RELEASE' ..."

if [ -z "$SENTRY_AUTH_TOKEN" ]; then
echo "Error: SENTRY_AUTH_TOKEN environment variable must be set"
exit 1
fi
if [ -z "$SENTRY_ORG" ]; then
echo "Error: SENTRY_ORG environment variable must be set"
exit 1
fi
if [ -z "$SENTRY_PROJECT" ]; then
echo "Error: SENTRY_PROJECT environment variable must be set"
exit 1
if [ ! -z "$SENTRY_CREATE_RELEASE" ]; then
echo "[entrypoint.sh] Configured to create release in Sentry"

if [ ! -z "$SENTRY_RELEASE" ]; then
echo "[entrypoint.sh] Creating Sentry release '$SENTRY_RELEASE' ..."

if [ -z "$SENTRY_AUTH_TOKEN" ]; then
echo "[entrypoint.sh] Error: SENTRY_AUTH_TOKEN environment variable must be set"
exit 1
fi
if [ -z "$SENTRY_ORG" ]; then
echo "[entrypoint.sh] Error: SENTRY_ORG environment variable must be set"
exit 1
fi
if [ -z "$SENTRY_PROJECT" ]; then
echo "[entrypoint.sh] Error: SENTRY_PROJECT environment variable must be set"
exit 1
fi
if [ -z "$SENTRY_ENV" ]; then
echo "[entrypoint.sh] Error: SENTRY_ENV environment variable must be set"
exit 1
fi

echo "[entrypoint.sh] Creating Sentry Release"
./node_modules/.bin/sentry-cli login --auth-token $SENTRY_AUTH_TOKEN
./node_modules/.bin/sentry-cli releases new $SENTRY_RELEASE
if [ ! -z "$SENTRY_UPLOAD_SOURCEMAPS" ]; then
echo "[entrypoint.sh] Uploading Sourcemaps"
./node_modules/.bin/sentry-cli sourcemaps upload --release $SENTRY_RELEASE .next
else
echo "[entrypoint.sh] Skipped Uploading Sourcemaps"
fi
echo "[entrypoint.sh] Finalizing Sentry Release"
./node_modules/.bin/sentry-cli releases finalize $SENTRY_RELEASE

echo "[entrypoint.sh] Sentry release created: $SENTRY_RELEASE"
else
echo "[entrypoint.sh] Create Sentry release is enabled, but not defined in SENTRY_RELEASE"
fi
if [ -z "$SENTRY_ENV" ]; then
echo "Error: SENTRY_ENV environment variable must be set"
exit 1
fi

./node_modules/.bin/sentry-cli login --auth-token $SENTRY_AUTH_TOKEN
./node_modules/.bin/sentry-cli releases new $SENTRY_RELEASE
./node_modules/.bin/sentry-cli sourcemaps inject .
./node_modules/.bin/sentry-cli sourcemaps upload --release $SENTRY_RELEASE .
./node_modules/.bin/sentry-cli releases finalize $SENTRY_RELEASE

echo "Sentry release '$SENTRY_RELEASE' created"
fi

echo "Setup environment variables..."
echo "[entrypoint.sh] Setup environment variables..."
. ./env.sh

echo "Deploying Prisma migrations..."
echo "[entrypoint.sh] eploying Prisma migrations..."
./node_modules/.bin/prisma migrate deploy

echo "Starting API..."
echo "[entrypoint.sh] Starting server..."
./node_modules/.bin/next start
12 changes: 6 additions & 6 deletions docker/env.sh
Original file line number Diff line number Diff line change
Expand Up @@ -22,18 +22,18 @@

ENVSH_SED="sed"
if [ "$(uname)" = "Darwin" ]; then
echo "macOS detected, switching to gsed"
echo "[env.sh] macOS detected, switching to gsed"

if command -v gsed >/dev/null 2>&1; then
echo "Found: $(gsed --version | head -n 1)"
echo "[env.sh] Found: $(gsed --version | head -n 1)"
else
echo "gsed not found, trying to install..."
echo "[env.sh] gsed not found, trying to install..."

if command -v brew >/dev/null 2>&1; then
echo "Found: $(brew --version | head -n 1)"
echo "[env.sh] Found: $(brew --version | head -n 1)"
brew install gnu-sed
else
echo "Homebrew not found, install it first: https://brew.sh/"
echo "[env.sh] Homebrew not found, install it first: https://brew.sh/"
exit 1
fi

Expand All @@ -48,7 +48,7 @@ env_vars=$(env | grep '^NEXT_PUBLIC_[A-Za-z0-9_]*=' | cut -d= -f1)
# Build the JavaScript object string
js_object="{"
for var_name in $env_vars; do
echo "Found variable in env: $var_name"
echo "[env.sh] Found variable in env: $var_name"

# Trim the "NEXT_PUBLIC_" prefix from the variable name
key=$(echo "$var_name" | $ENVSH_SED 's/^NEXT_PUBLIC_//')
Expand Down

0 comments on commit 3159bc6

Please sign in to comment.