Skip to content

Commit e64be7a

Browse files
wip on cleanup
1 parent 47bbad5 commit e64be7a

14 files changed

+96
-148
lines changed

.github/workflows/fly-deploy-staging.yml

Lines changed: 0 additions & 29 deletions
This file was deleted.

.github/workflows/fly-deploy.yml

Lines changed: 0 additions & 31 deletions
This file was deleted.

.github/workflows/ghcr-publish.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -79,8 +79,8 @@ jobs:
7979
platforms: ${{ matrix.platform }}
8080
outputs: type=image,name=${{ env.REGISTRY_IMAGE }},push-by-digest=true,name-canonical=true,push=true
8181
build-args: |
82-
SOURCEBOT_VERSION=${{ github.ref_name }}
83-
POSTHOG_PAPIK=${{ secrets.POSTHOG_PAPIK }}
82+
NEXT_PUBLIC_SOURCEBOT_VERSION=${{ github.ref_name }}
83+
NEXT_PUBLIC_POSTHOG_PAPIK=${{ secrets.POSTHOG_PAPIK }}
8484
8585
- name: Export digest
8686
run: |

.github/workflows/staging-ghcr-public.yml

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -69,9 +69,12 @@ jobs:
6969
platforms: ${{ matrix.platform }}
7070
outputs: type=image,name=${{ env.REGISTRY_IMAGE }},push-by-digest=true,name-canonical=true,push=true
7171
build-args: |
72-
SOURCEBOT_VERSION=${{ github.ref_name }}
73-
POSTHOG_PAPIK=${{ secrets.POSTHOG_PAPIK }}
72+
NEXT_PUBLIC_SOURCEBOT_VERSION=${{ github.ref_name }}
73+
NEXT_PUBLIC_POSTHOG_PAPIK=${{ secrets.POSTHOG_PAPIK }}
7474
NEXT_PUBLIC_SOURCEBOT_CLOUD_ENVIRONMENT=staging
75+
NEXT_PUBLIC_SENTRY_ENVIRONMENT=staging
76+
NEXT_PUBLIC_SENTRY_WEBAPP_DSN=${{ secrets.SENTRY_WEBAPP_DSN }}
77+
NEXT_PUBLIC_SENTRY_BACKEND_DSN=${{ secrets.SENTRY_BACKEND_DSN }}
7578
7679
- name: Export digest
7780
run: |

Dockerfile

Lines changed: 30 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,22 @@
11
# ------ Global scope variables ------
2+
23
# Set of global build arguments.
4+
# These are considered "public" and will be baked into the image.
5+
# The convention is to prefix these with `NEXT_PUBLIC_` so that
6+
# they can be optionally be passed as client-side environment variables
7+
# in the webapp.
38
# @see: https://docs.docker.com/build/building/variables/#scoping
49

5-
ARG SOURCEBOT_VERSION
10+
ARG NEXT_PUBLIC_SOURCEBOT_VERSION
611
# PAPIK = Project API Key
712
# Note that this key does not need to be kept secret, so it's not
813
# necessary to use Docker build secrets here.
914
# @see: https://posthog.com/tutorials/api-capture-events#authenticating-with-the-project-api-key
10-
ARG POSTHOG_PAPIK
11-
ARG SENTRY_ENVIRONMENT
12-
ARG SOURCEBOT_CLOUD_ENVIRONMENT
15+
ARG NEXT_PUBLIC_POSTHOG_PAPIK
16+
ARG NEXT_PUBLIC_SENTRY_ENVIRONMENT
17+
ARG NEXT_PUBLIC_SOURCEBOT_CLOUD_ENVIRONMENT
18+
ARG NEXT_PUBLIC_SENTRY_WEBAPP_DSN
19+
ARG NEXT_PUBLIC_SENTRY_BACKEND_DSN
1320

1421
FROM node:20-alpine3.19 AS node-alpine
1522
FROM golang:1.23.4-alpine3.19 AS go-alpine
@@ -46,16 +53,14 @@ RUN yarn workspace @sourcebot/error install
4653
FROM node-alpine AS web-builder
4754
ENV SKIP_ENV_VALIDATION=1
4855
# -----------
49-
# Global args
50-
ARG SOURCEBOT_VERSION
51-
ENV NEXT_PUBLIC_SOURCEBOT_VERSION=$SOURCEBOT_VERSION
52-
ARG POSTHOG_PAPIK
53-
ENV NEXT_PUBLIC_POSTHOG_PAPIK=$POSTHOG_PAPIK
54-
ARG SENTRY_ENVIRONMENT
55-
ENV NEXT_PUBLIC_SENTRY_ENVIRONMENT=$SENTRY_ENVIRONMENT
56-
ARG SOURCEBOT_CLOUD_ENVIRONMENT
57-
ENV NEXT_PUBLIC_SOURCEBOT_CLOUD_ENVIRONMENT=$SOURCEBOT_CLOUD_ENVIRONMENT
58-
# Local args
56+
ARG NEXT_PUBLIC_SOURCEBOT_VERSION
57+
ENV NEXT_PUBLIC_SOURCEBOT_VERSION=$NEXT_PUBLIC_SOURCEBOT_VERSION
58+
ARG NEXT_PUBLIC_POSTHOG_PAPIK
59+
ENV NEXT_PUBLIC_POSTHOG_PAPIK=$NEXT_PUBLIC_POSTHOG_PAPIK
60+
ARG NEXT_PUBLIC_SENTRY_ENVIRONMENT
61+
ENV NEXT_PUBLIC_SENTRY_ENVIRONMENT=$NEXT_PUBLIC_SENTRY_ENVIRONMENT
62+
ARG NEXT_PUBLIC_SOURCEBOT_CLOUD_ENVIRONMENT
63+
ENV NEXT_PUBLIC_SOURCEBOT_CLOUD_ENVIRONMENT=$NEXT_PUBLIC_SOURCEBOT_CLOUD_ENVIRONMENT
5964
ARG NEXT_PUBLIC_SENTRY_WEBAPP_DSN
6065
ENV NEXT_PUBLIC_SENTRY_WEBAPP_DSN=$NEXT_PUBLIC_SENTRY_WEBAPP_DSN
6166
# -----------
@@ -102,17 +107,19 @@ ENV SKIP_ENV_VALIDATION=0
102107
# ------ Runner ------
103108
FROM node-alpine AS runner
104109
# -----------
105-
# Global args
106-
ARG SOURCEBOT_VERSION
107-
ENV SOURCEBOT_VERSION=$SOURCEBOT_VERSION
108-
ARG POSTHOG_PAPIK
109-
ENV POSTHOG_PAPIK=$POSTHOG_PAPIK
110-
ARG SENTRY_ENVIRONMENT
111-
ENV SENTRY_ENVIRONMENT=$SENTRY_ENVIRONMENT
112-
# Local args
110+
ARG NEXT_PUBLIC_SOURCEBOT_VERSION
111+
ENV NEXT_PUBLIC_SOURCEBOT_VERSION=$NEXT_PUBLIC_SOURCEBOT_VERSION
112+
ARG NEXT_PUBLIC_POSTHOG_PAPIK
113+
ENV NEXT_PUBLIC_POSTHOG_PAPIK=$NEXT_PUBLIC_POSTHOG_PAPIK
114+
ARG NEXT_PUBLIC_SENTRY_ENVIRONMENT
115+
ENV NEXT_PUBLIC_SENTRY_ENVIRONMENT=$NEXT_PUBLIC_SENTRY_ENVIRONMENT
116+
ARG NEXT_PUBLIC_SENTRY_WEBAPP_DSN
117+
ENV NEXT_PUBLIC_SENTRY_WEBAPP_DSN=$NEXT_PUBLIC_SENTRY_WEBAPP_DSN
118+
ARG NEXT_PUBLIC_SENTRY_BACKEND_DSN
119+
ENV NEXT_PUBLIC_SENTRY_BACKEND_DSN=$NEXT_PUBLIC_SENTRY_BACKEND_DSN
113120
# -----------
114121

115-
RUN echo "Sourcebot Version: $SOURCEBOT_VERSION"
122+
RUN echo "Sourcebot Version: $NEXT_PUBLIC_SOURCEBOT_VERSION"
116123

117124
WORKDIR /app
118125
ENV NODE_ENV=production
@@ -172,17 +179,6 @@ COPY --from=shared-libs-builder /app/packages/error ./packages/error
172179

173180
# Configure dependencies
174181
RUN apk add --no-cache git ca-certificates bind-tools tini jansson wget supervisor uuidgen curl perl jq redis postgresql postgresql-contrib openssl util-linux unzip
175-
RUN curl -sL https://sentry.io/get-cli/ | sh
176-
177-
# Install grafana alloy. libc6-compat is required because alloy dynamically links against glibc which doesn't exist in alpine by default
178-
# @nocheckin: figure out how to handle this for self hosted case (especially the config)
179-
RUN apk add --no-cache libc6-compat
180-
RUN wget https://github.com/grafana/alloy/releases/download/v1.7.0/alloy-linux-amd64.zip \
181-
&& unzip alloy-linux-amd64.zip \
182-
&& mv alloy-linux-amd64 /usr/local/bin/alloy \
183-
&& chmod +x /usr/local/bin/alloy \
184-
&& rm alloy-linux-amd64.zip
185-
COPY grafana.alloy .
186182

187183
# Configure the database
188184
RUN mkdir -p /run/postgresql && \

entrypoint.sh

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
11
#!/bin/sh
22
set -e
33

4-
echo -e "\e[34m[Info] Sourcebot version: $SOURCEBOT_VERSION\e[0m"
4+
echo -e "\e[34m[Info] Sourcebot version: $NEXT_PUBLIC_SOURCEBOT_VERSION\e[0m"
55

66
# If we don't have a PostHog key, then we need to disable telemetry.
7-
if [ -z "$POSTHOG_PAPIK" ]; then
8-
echo -e "\e[33m[Warning] POSTHOG_PAPIK was not set. Setting SOURCEBOT_TELEMETRY_DISABLED.\e[0m"
7+
if [ -z "$NEXT_PUBLIC_POSTHOG_PAPIK" ]; then
8+
echo -e "\e[33m[Warning] NEXT_PUBLIC_POSTHOG_PAPIK was not set. Setting SOURCEBOT_TELEMETRY_DISABLED.\e[0m"
99
export SOURCEBOT_TELEMETRY_DISABLED=true
1010
fi
1111

@@ -81,7 +81,7 @@ fi
8181

8282
# In order to detect if this is the first run, we create a `.installed` file in
8383
# the cache directory.
84-
FIRST_RUN_FILE="$DATA_CACHE_DIR/.installedv2"
84+
FIRST_RUN_FILE="$DATA_CACHE_DIR/.installedv3"
8585

8686
if [ ! -f "$FIRST_RUN_FILE" ]; then
8787
touch "$FIRST_RUN_FILE"
@@ -91,11 +91,11 @@ if [ ! -f "$FIRST_RUN_FILE" ]; then
9191
# (if telemetry is enabled)
9292
if [ "$SOURCEBOT_TELEMETRY_DISABLED" = "false" ]; then
9393
if ! ( curl -L --output /dev/null --silent --fail --header "Content-Type: application/json" -d '{
94-
"api_key": "'"$POSTHOG_PAPIK"'",
94+
"api_key": "'"$NEXT_PUBLIC_POSTHOG_PAPIK"'",
9595
"event": "install",
9696
"distinct_id": "'"$SOURCEBOT_INSTALL_ID"'",
9797
"properties": {
98-
"sourcebot_version": "'"$SOURCEBOT_VERSION"'"
98+
"sourcebot_version": "'"$NEXT_PUBLIC_SOURCEBOT_VERSION"'"
9999
}
100100
}' https://us.i.posthog.com/capture/ ) then
101101
echo -e "\e[33m[Warning] Failed to send install event.\e[0m"
@@ -106,17 +106,17 @@ else
106106
PREVIOUS_VERSION=$(cat "$FIRST_RUN_FILE" | jq -r '.version')
107107

108108
# If the version has changed, we assume an upgrade has occurred.
109-
if [ "$PREVIOUS_VERSION" != "$SOURCEBOT_VERSION" ]; then
110-
echo -e "\e[34m[Info] Upgraded from version $PREVIOUS_VERSION to $SOURCEBOT_VERSION\e[0m"
109+
if [ "$PREVIOUS_VERSION" != "$NEXT_PUBLIC_SOURCEBOT_VERSION" ]; then
110+
echo -e "\e[34m[Info] Upgraded from version $PREVIOUS_VERSION to $NEXT_PUBLIC_SOURCEBOT_VERSION\e[0m"
111111

112112
if [ "$SOURCEBOT_TELEMETRY_DISABLED" = "false" ]; then
113113
if ! ( curl -L --output /dev/null --silent --fail --header "Content-Type: application/json" -d '{
114-
"api_key": "'"$POSTHOG_PAPIK"'",
114+
"api_key": "'"$NEXT_PUBLIC_POSTHOG_PAPIK"'",
115115
"event": "upgrade",
116116
"distinct_id": "'"$SOURCEBOT_INSTALL_ID"'",
117117
"properties": {
118118
"from_version": "'"$PREVIOUS_VERSION"'",
119-
"to_version": "'"$SOURCEBOT_VERSION"'"
119+
"to_version": "'"$NEXT_PUBLIC_SOURCEBOT_VERSION"'"
120120
}
121121
}' https://us.i.posthog.com/capture/ ) then
122122
echo -e "\e[33m[Warning] Failed to send upgrade event.\e[0m"
@@ -125,7 +125,7 @@ else
125125
fi
126126
fi
127127

128-
echo "{\"version\": \"$SOURCEBOT_VERSION\", \"install_id\": \"$SOURCEBOT_INSTALL_ID\"}" > "$FIRST_RUN_FILE"
128+
echo "{\"version\": \"$NEXT_PUBLIC_SOURCEBOT_VERSION\", \"install_id\": \"$SOURCEBOT_INSTALL_ID\"}" > "$FIRST_RUN_FILE"
129129

130130

131131
# Start the database and wait for it to be ready before starting any other service

packages/backend/src/env.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -25,18 +25,18 @@ export const env = createEnv({
2525
SOURCEBOT_LOG_LEVEL: z.enum(["info", "debug", "warn", "error"]).default("info"),
2626
SOURCEBOT_TELEMETRY_DISABLED: booleanSchema.default("false"),
2727
SOURCEBOT_INSTALL_ID: z.string().default("unknown"),
28-
SOURCEBOT_VERSION: z.string().default("unknown"),
28+
NEXT_PUBLIC_SOURCEBOT_VERSION: z.string().default("unknown"),
2929

30-
POSTHOG_PAPIK: z.string().optional(),
30+
NEXT_PUBLIC_POSTHOG_PAPIK: z.string().optional(),
3131

3232
FALLBACK_GITHUB_CLOUD_TOKEN: z.string().optional(),
3333
FALLBACK_GITLAB_CLOUD_TOKEN: z.string().optional(),
3434
FALLBACK_GITEA_CLOUD_TOKEN: z.string().optional(),
3535

3636
REDIS_URL: z.string().url().default("redis://localhost:6379"),
3737

38-
SENTRY_BACKEND_DSN: z.string().optional(),
39-
SENTRY_ENVIRONMENT: z.string().optional(),
38+
NEXT_PUBLIC_SENTRY_BACKEND_DSN: z.string().optional(),
39+
NEXT_PUBLIC_SENTRY_ENVIRONMENT: z.string().optional(),
4040

4141
LOGTAIL_TOKEN: z.string().optional(),
4242
LOGTAIL_HOST: z.string().url().optional(),

packages/backend/src/instrument.ts

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,12 @@
11
import * as Sentry from "@sentry/node";
22
import { env } from "./env.js";
33

4-
Sentry.init({
5-
dsn: env.SENTRY_BACKEND_DSN,
6-
release: env.SOURCEBOT_VERSION,
7-
environment: env.SENTRY_ENVIRONMENT,
8-
});
4+
if (!!env.NEXT_PUBLIC_SENTRY_BACKEND_DSN && !!env.NEXT_PUBLIC_SENTRY_ENVIRONMENT) {
5+
Sentry.init({
6+
dsn: env.NEXT_PUBLIC_SENTRY_BACKEND_DSN,
7+
release: env.NEXT_PUBLIC_SOURCEBOT_VERSION,
8+
environment: env.NEXT_PUBLIC_SENTRY_ENVIRONMENT,
9+
});
10+
} else {
11+
console.debug("Sentry was not initialized");
12+
}

packages/backend/src/posthog.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,9 @@ import { env } from './env.js';
44

55
let posthog: PostHog | undefined = undefined;
66

7-
if (env.POSTHOG_PAPIK) {
7+
if (env.NEXT_PUBLIC_POSTHOG_PAPIK) {
88
posthog = new PostHog(
9-
env.POSTHOG_PAPIK,
9+
env.NEXT_PUBLIC_POSTHOG_PAPIK,
1010
{
1111
host: "https://us.i.posthog.com",
1212
}
@@ -23,7 +23,7 @@ export function captureEvent<E extends PosthogEvent>(event: E, properties: Posth
2323
event: event,
2424
properties: {
2525
...properties,
26-
sourcebot_version: env.SOURCEBOT_VERSION,
26+
sourcebot_version: env.NEXT_PUBLIC_SOURCEBOT_VERSION,
2727
},
2828
});
2929
}

packages/web/sentry.client.config.ts

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,14 @@
44

55
import * as Sentry from "@sentry/nextjs";
66

7-
Sentry.init({
8-
dsn: process.env.NEXT_PUBLIC_SENTRY_WEBAPP_DSN,
9-
environment: process.env.NEXT_PUBLIC_SENTRY_ENVIRONMENT || 'unknown',
7+
if (!!process.env.NEXT_PUBLIC_SENTRY_WEBAPP_DSN && !!process.env.NEXT_PUBLIC_SENTRY_ENVIRONMENT) {
8+
Sentry.init({
9+
dsn: process.env.NEXT_PUBLIC_SENTRY_WEBAPP_DSN,
10+
environment: process.env.NEXT_PUBLIC_SENTRY_ENVIRONMENT,
1011

11-
// Setting this option to true will print useful information to the console while you're setting up Sentry.
12-
debug: false,
13-
});
12+
// Setting this option to true will print useful information to the console while you're setting up Sentry.
13+
debug: false,
14+
});
15+
} else {
16+
console.debug("[client] Sentry was not initialized");
17+
}

packages/web/sentry.edge.config.ts

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -5,10 +5,14 @@
55

66
import * as Sentry from "@sentry/nextjs";
77

8-
Sentry.init({
9-
dsn: process.env.NEXT_PUBLIC_SENTRY_WEBAPP_DSN,
10-
environment: process.env.NEXT_PUBLIC_SENTRY_ENVIRONMENT || 'unknown',
8+
if (!!process.env.NEXT_PUBLIC_SENTRY_WEBAPP_DSN && !!process.env.NEXT_PUBLIC_SENTRY_ENVIRONMENT) {
9+
Sentry.init({
10+
dsn: process.env.NEXT_PUBLIC_SENTRY_WEBAPP_DSN,
11+
environment: process.env.NEXT_PUBLIC_SENTRY_ENVIRONMENT,
1112

12-
// Setting this option to true will print useful information to the console while you're setting up Sentry.
13-
debug: false,
14-
});
13+
// Setting this option to true will print useful information to the console while you're setting up Sentry.
14+
debug: false,
15+
});
16+
} else {
17+
console.debug("[edge] Sentry was not initialized");
18+
}

packages/web/sentry.server.config.ts

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,14 @@
44

55
import * as Sentry from "@sentry/nextjs";
66

7-
Sentry.init({
8-
dsn: process.env.NEXT_PUBLIC_SENTRY_WEBAPP_DSN,
9-
environment: process.env.NEXT_PUBLIC_SENTRY_ENVIRONMENT || 'unknown',
7+
if (!!process.env.NEXT_PUBLIC_SENTRY_WEBAPP_DSN && !!process.env.NEXT_PUBLIC_SENTRY_ENVIRONMENT) {
8+
Sentry.init({
9+
dsn: process.env.NEXT_PUBLIC_SENTRY_WEBAPP_DSN,
10+
environment: process.env.NEXT_PUBLIC_SENTRY_ENVIRONMENT,
1011

11-
// Setting this option to true will print useful information to the console while you're setting up Sentry.
12-
debug: false,
13-
});
12+
// Setting this option to true will print useful information to the console while you're setting up Sentry.
13+
debug: false,
14+
});
15+
} else {
16+
console.debug("[server] Sentry was not initialized");
17+
}

packages/web/src/app/posthogProvider.tsx

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,8 @@ export function PostHogProvider({ children, disabled }: PostHogProviderProps) {
7979
email: session.user.email,
8080
name: session.user.name,
8181
});
82+
} else {
83+
console.debug("PostHog identify skipped");
8284
}
8385
}, [session]);
8486

0 commit comments

Comments
 (0)