Skip to content

Commit ad60c5f

Browse files
Centralize to using a single .env.development for development workflows (#231)
1 parent 98ec2c9 commit ad60c5f

File tree

11 files changed

+155
-20
lines changed

11 files changed

+155
-20
lines changed

.env.development

Lines changed: 82 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,82 @@
1+
2+
# Prisma
3+
DATABASE_URL="postgresql://postgres:postgres@localhost:5432/postgres"
4+
5+
# Zoekt
6+
ZOEKT_WEBSERVER_URL="http://localhost:6070"
7+
# SHARD_MAX_MATCH_COUNT=10000
8+
# TOTAL_MAX_MATCH_COUNT=100000
9+
# The command to use for generating ctags.
10+
CTAGS_COMMAND=ctags
11+
# logging, strict
12+
SRC_TENANT_ENFORCEMENT_MODE=strict
13+
14+
# Auth.JS
15+
# You can generate a new secret with:
16+
# openssl rand -base64 33
17+
# @see: https://authjs.dev/getting-started/deployment#auth_secret
18+
AUTH_SECRET="secret"
19+
AUTH_URL="http://localhost:3000"
20+
# AUTH_CREDENTIALS_LOGIN_ENABLED=true
21+
# AUTH_GITHUB_CLIENT_ID=""
22+
# AUTH_GITHUB_CLIENT_SECRET=""
23+
# AUTH_GOOGLE_CLIENT_ID=""
24+
# AUTH_GOOGLE_CLIENT_SECRET=""
25+
26+
# Email
27+
# EMAIL_FROM="" # The from address for transactional emails.
28+
# SMTP_CONNECTION_URL="" # The SMTP connection URL for transactional emails.
29+
30+
# PostHog
31+
# POSTHOG_PAPIK=""
32+
# NEXT_PUBLIC_POSTHOG_PAPIK=""
33+
34+
# Sentry
35+
# SENTRY_BACKEND_DSN=""
36+
# NEXT_PUBLIC_SENTRY_WEBAPP_DSN=""
37+
# SENTRY_ENVIRONMENT="dev"
38+
# NEXT_PUBLIC_SENTRY_ENVIRONMENT="dev"
39+
# SENTRY_AUTH_TOKEN=
40+
41+
# Logtail
42+
# LOGTAIL_TOKEN=""
43+
# LOGTAIL_HOST=""
44+
45+
# Redis
46+
REDIS_URL="redis://localhost:6379"
47+
48+
# Stripe
49+
# STRIPE_SECRET_KEY: z.string().optional(),
50+
# STRIPE_PRODUCT_ID: z.string().optional(),
51+
# STRIPE_WEBHOOK_SECRET: z.string().optional(),
52+
53+
# Misc
54+
55+
# Set during docker build of application
56+
# Used to disable env var validation at build time
57+
# DOCKER_BUILD=1
58+
59+
# Generated using:
60+
# openssl rand -base64 24
61+
SOURCEBOT_ENCRYPTION_KEY="secret"
62+
63+
SOURCEBOT_LOG_LEVEL="debug" # valid values: info, debug, warn, error
64+
SOURCEBOT_TELEMETRY_DISABLED=true # Disables telemetry collection
65+
66+
# Code-host fallback tokens
67+
# FALLBACK_GITHUB_TOKEN=""
68+
# FALLBACK_GITLAB_TOKEN=""
69+
# FALLBACK_GITEA_TOKEN=""
70+
71+
# Controls the number of concurrent indexing jobs that can run at once
72+
# INDEX_CONCURRENCY_MULTIPLE=
73+
74+
# Controls the polling interval for the web app
75+
# NEXT_PUBLIC_POLLING_INTERVAL_MS=
76+
77+
# Controls the version of the web app
78+
# NEXT_PUBLIC_SOURCEBOT_VERSION=
79+
80+
# CONFIG_MAX_REPOS_NO_TOKEN=
81+
# SOURCEBOT_ROOT_DOMAIN=
82+
# NODE_ENV=

package.json

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,13 +6,20 @@
66
"scripts": {
77
"build": "yarn workspaces run build",
88
"test": "yarn workspaces run test",
9-
"dev": "yarn workspace @sourcebot/db prisma:migrate:dev && cross-env npm-run-all --print-label --parallel dev:zoekt dev:backend dev:web",
10-
"dev:zoekt": "export PATH=\"$PWD/bin:$PATH\" && export SRC_TENANT_ENFORCEMENT_MODE=strict && zoekt-webserver -index .sourcebot/index -rpc",
11-
"dev:backend": "yarn workspace @sourcebot/backend dev:watch",
12-
"dev:web": "yarn workspace @sourcebot/web dev"
9+
10+
"dev": "yarn dev:prisma:migrate && npm-run-all --print-label --parallel dev:zoekt dev:backend dev:web",
11+
"with-env": "cross-env PATH=\"$PWD/bin:$PATH\" dotenv -e .env.development -c --",
12+
"dev:zoekt": "yarn with-env zoekt-webserver -index .sourcebot/index -rpc",
13+
"dev:backend": "yarn with-env yarn workspace @sourcebot/backend dev:watch",
14+
"dev:web": "yarn with-env yarn workspace @sourcebot/web dev",
15+
16+
"dev:prisma:migrate": "yarn with-env yarn workspace @sourcebot/db prisma:migrate:dev",
17+
"dev:prisma:studio": "yarn with-env yarn workspace @sourcebot/db prisma:studio",
18+
"dev:prisma:migrate:reset": "yarn with-env yarn workspace @sourcebot/db prisma:migrate:reset"
1319
},
1420
"devDependencies": {
1521
"cross-env": "^7.0.3",
22+
"dotenv-cli": "^8.0.0",
1623
"npm-run-all": "^4.1.5"
1724
}
1825
}

packages/backend/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
"type": "module",
77
"scripts": {
88
"dev:watch": "tsc-watch --preserveWatchOutput --onSuccess \"yarn dev --cacheDir ../../.sourcebot\"",
9-
"dev": "export PATH=\"$PWD/../../bin:$PATH\" && export CTAGS_COMMAND=ctags && node ./dist/index.js",
9+
"dev": "node ./dist/index.js",
1010
"build": "tsc",
1111
"test": "vitest --config ./vitest.config.ts"
1212
},

packages/backend/src/env.ts

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,9 @@ import { createEnv } from "@t3-oss/env-core";
22
import { z } from "zod";
33
import dotenv from 'dotenv';
44

5+
// Booleans are specified as 'true' or 'false' strings.
6+
const booleanSchema = z.enum(["true", "false"]);
7+
58
dotenv.config({
69
path: './.env',
710
});
@@ -15,18 +18,17 @@ export const env = createEnv({
1518
server: {
1619
SOURCEBOT_ENCRYPTION_KEY: z.string(),
1720
SOURCEBOT_LOG_LEVEL: z.enum(["info", "debug", "warn", "error"]).default("info"),
18-
SOURCEBOT_TELEMETRY_DISABLED: z.enum(["true", "false"]).default("false"),
21+
SOURCEBOT_TELEMETRY_DISABLED: booleanSchema.default("false"),
1922
SOURCEBOT_INSTALL_ID: z.string().default("unknown"),
2023
SOURCEBOT_VERSION: z.string().default("unknown"),
2124

2225
POSTHOG_PAPIK: z.string().optional(),
23-
POSTHOG_HOST: z.string().url().default('https://us.i.posthog.com'),
2426

2527
FALLBACK_GITHUB_TOKEN: z.string().optional(),
2628
FALLBACK_GITLAB_TOKEN: z.string().optional(),
2729
FALLBACK_GITEA_TOKEN: z.string().optional(),
2830

29-
REDIS_URL: z.string().url().optional().default("redis://localhost:6379"),
31+
REDIS_URL: z.string().url(),
3032

3133
SENTRY_BACKEND_DSN: z.string().optional(),
3234
SENTRY_ENVIRONMENT: z.string().optional(),
@@ -35,6 +37,7 @@ export const env = createEnv({
3537
LOGTAIL_HOST: z.string().url().optional(),
3638

3739
INDEX_CONCURRENCY_MULTIPLE: z.number().optional(),
40+
DATABASE_URL: z.string().url(),
3841
},
3942
runtimeEnv: process.env,
4043
emptyStringAsUndefined: true,

packages/backend/src/index.ts

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,33 @@ import { AppContext } from "./types.js";
99
import { main } from "./main.js"
1010
import { PrismaClient } from "@sourcebot/db";
1111

12+
// Register handler for normal exit
13+
process.on('exit', (code) => {
14+
console.log(`Process is exiting with code: ${code}`);
15+
});
16+
17+
// Register handlers for abnormal terminations
18+
process.on('SIGINT', () => {
19+
console.log('Process interrupted (SIGINT)');
20+
process.exit(130);
21+
});
22+
23+
process.on('SIGTERM', () => {
24+
console.log('Process terminated (SIGTERM)');
25+
process.exit(143);
26+
});
27+
28+
// Register handlers for uncaught exceptions and unhandled rejections
29+
process.on('uncaughtException', (err) => {
30+
console.log(`Uncaught exception: ${err.message}`);
31+
process.exit(1);
32+
});
33+
34+
process.on('unhandledRejection', (reason, promise) => {
35+
console.log(`Unhandled rejection at: ${promise}, reason: ${reason}`);
36+
process.exit(1);
37+
});
38+
1239

1340
const parser = new ArgumentParser({
1441
description: "Sourcebot backend tool",

packages/backend/src/posthog.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,13 +8,13 @@ if (env.POSTHOG_PAPIK) {
88
posthog = new PostHog(
99
env.POSTHOG_PAPIK,
1010
{
11-
host: env.POSTHOG_HOST,
11+
host: "https://us.i.posthog.com",
1212
}
1313
);
1414
}
1515

1616
export function captureEvent<E extends PosthogEvent>(event: E, properties: PosthogEventMap[E]) {
17-
if (env.SOURCEBOT_TELEMETRY_DISABLED) {
17+
if (env.SOURCEBOT_TELEMETRY_DISABLED === 'true') {
1818
return;
1919
}
2020

packages/crypto/package.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
11
{
22
"name": "@sourcebot/crypto",
3-
"main": "dist/index.js",
43
"version": "0.1.0",
4+
"main": "dist/index.js",
5+
"private": true,
56
"scripts": {
67
"build": "tsc",
78
"postinstall": "yarn build"

packages/web/src/app/posthogProvider.tsx

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,6 @@ export function PostHogProvider({ children, disabled }: PostHogProviderProps) {
3737
posthog.init(env.NEXT_PUBLIC_POSTHOG_PAPIK, {
3838
// @see next.config.mjs for path rewrites to the "/ingest" route.
3939
api_host: "/ingest",
40-
ui_host: env.NEXT_PUBLIC_POSTHOG_UI_HOST,
4140
person_profiles: 'identified_only',
4241
capture_pageview: false, // @nocheckin Disable automatic pageview capture if we're not in public demo mode
4342
autocapture: false, // Disable automatic event capture

packages/web/src/auth.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,7 @@ export const getProviders = () => {
7676
}));
7777
}
7878

79-
if (env.AUTH_CREDENTIALS_LOGIN_ENABLED) {
79+
if (env.AUTH_CREDENTIALS_LOGIN_ENABLED === 'true') {
8080
providers.push(Credentials({
8181
credentials: {
8282
email: {},

packages/web/src/env.mjs

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,13 @@
11
import { createEnv } from "@t3-oss/env-nextjs";
22
import { z } from "zod";
33

4+
// Booleans are specified as 'true' or 'false' strings.
5+
const booleanSchema = z.enum(["true", "false"]);
6+
47
export const env = createEnv({
58
server: {
69
// Zoekt
7-
ZOEKT_WEBSERVER_URL: z.string().url().default('http://localhost:6070'),
10+
ZOEKT_WEBSERVER_URL: z.string().url(),
811
SHARD_MAX_MATCH_COUNT: z.number().default(10000),
912
TOTAL_MAX_MATCH_COUNT: z.number().default(100000),
1013

@@ -15,7 +18,7 @@ export const env = createEnv({
1518
AUTH_GOOGLE_CLIENT_ID: z.string().optional(),
1619
AUTH_GOOGLE_CLIENT_SECRET: z.string().optional(),
1720
AUTH_URL: z.string().url(),
18-
AUTH_CREDENTIALS_LOGIN_ENABLED: z.boolean().default(true),
21+
AUTH_CREDENTIALS_LOGIN_ENABLED: booleanSchema.default('true'),
1922

2023
// Email
2124
SMTP_CONNECTION_URL: z.string().url().optional(),
@@ -30,15 +33,14 @@ export const env = createEnv({
3033
CONFIG_MAX_REPOS_NO_TOKEN: z.number().default(500),
3134
SOURCEBOT_ROOT_DOMAIN: z.string().default("localhost:3000"),
3235
NODE_ENV: z.enum(["development", "test", "production"]),
33-
SOURCEBOT_TELEMETRY_DISABLED: z.enum(["true", "false"]).default("false"),
36+
SOURCEBOT_TELEMETRY_DISABLED: booleanSchema.default('false'),
3437
DATABASE_URL: z.string().url(),
3538
},
3639
// @NOTE: Make sure you destructure all client variables in the
3740
// `experimental__runtimeEnv` block below.
3841
client: {
3942
// PostHog
4043
NEXT_PUBLIC_POSTHOG_PAPIK: z.string().optional(),
41-
NEXT_PUBLIC_POSTHOG_UI_HOST: z.string().url().default('https://us.posthog.com'),
4244

4345
// Misc
4446
NEXT_PUBLIC_SOURCEBOT_VERSION: z.string().default('unknown'),
@@ -47,7 +49,6 @@ export const env = createEnv({
4749
// For Next.js >= 13.4.4, you only need to destructure client variables:
4850
experimental__runtimeEnv: {
4951
NEXT_PUBLIC_POSTHOG_PAPIK: process.env.NEXT_PUBLIC_POSTHOG_PAPIK,
50-
NEXT_PUBLIC_POSTHOG_UI_HOST: process.env.NEXT_PUBLIC_POSTHOG_UI_HOST,
5152
NEXT_PUBLIC_SOURCEBOT_VERSION: process.env.NEXT_PUBLIC_SOURCEBOT_VERSION,
5253
NEXT_PUBLIC_POLLING_INTERVAL_MS: process.env.NEXT_PUBLIC_POLLING_INTERVAL_MS,
5354
},

0 commit comments

Comments
 (0)