Skip to content

Commit 34c9c1d

Browse files
Domain support (#188)
1 parent 568ded8 commit 34c9c1d

File tree

101 files changed

+2102
-1975
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

101 files changed

+2102
-1975
lines changed

Dockerfile

Lines changed: 1 addition & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -45,10 +45,6 @@ ARG NEXT_PUBLIC_SOURCEBOT_TELEMETRY_DISABLED=BAKED_NEXT_PUBLIC_SOURCEBOT_TELEMET
4545
ARG NEXT_PUBLIC_SOURCEBOT_VERSION=BAKED_NEXT_PUBLIC_SOURCEBOT_VERSION
4646
ENV NEXT_PUBLIC_POSTHOG_PAPIK=BAKED_NEXT_PUBLIC_POSTHOG_PAPIK
4747

48-
# We declare SOURCEBOT_ENCRYPTION_KEY here since it's read during the build stage, since it's read in a server side component
49-
ARG SOURCEBOT_ENCRYPTION_KEY
50-
ENV SOURCEBOT_ENCRYPTION_KEY=$SOURCEBOT_ENCRYPTION_KEY
51-
5248
# @nocheckin: This was interfering with the the `matcher` regex in middleware.ts,
5349
# causing regular expressions parsing errors when making a request. It's unclear
5450
# why exactly this was happening, but it's likely due to a bad replacement happening
@@ -79,21 +75,16 @@ WORKDIR /app
7975
ENV NODE_ENV=production
8076
ENV NEXT_TELEMETRY_DISABLED=1
8177
ENV DATA_DIR=/data
82-
ENV CONFIG_PATH=$DATA_DIR/config.json
8378
ENV DATA_CACHE_DIR=$DATA_DIR/.sourcebot
8479
ENV DB_DATA_DIR=$DATA_CACHE_DIR/db
8580
ENV DB_NAME=sourcebot
8681
ENV DATABASE_URL="postgresql://postgres@localhost:5432/sourcebot"
82+
ENV SRC_TENANT_ENFORCEMENT_MODE=strict
8783

8884
ARG SOURCEBOT_VERSION=unknown
8985
ENV SOURCEBOT_VERSION=$SOURCEBOT_VERSION
9086
RUN echo "Sourcebot Version: $SOURCEBOT_VERSION"
9187

92-
# Redeclare SOURCEBOT_ENCRYPTION_KEY so that we have it in the runner
93-
ARG SOURCEBOT_ENCRYPTION_KEY
94-
95-
ENV SOURCEBOT_TENANT_MODE=single
96-
9788
# Valid values are: debug, info, warn, error
9889
ENV SOURCEBOT_LOG_LEVEL=info
9990

entrypoint.sh

Lines changed: 0 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -86,27 +86,6 @@ fi
8686

8787
echo "{\"version\": \"$SOURCEBOT_VERSION\", \"install_id\": \"$SOURCEBOT_INSTALL_ID\"}" > "$FIRST_RUN_FILE"
8888

89-
if [ ! -z "$SOURCEBOT_TENANT_MODE" ]; then
90-
echo -e "\e[34m[Info] Sourcebot tenant mode: $SOURCEBOT_TENANT_MODE\e[0m"
91-
else
92-
echo -e "\e[31m[Error] SOURCEBOT_TENANT_MODE is not set.\e[0m"
93-
exit 1
94-
fi
95-
96-
# If we're in single tenant mode, fallback to sample config if a config does not exist
97-
if [ "$SOURCEBOT_TENANT_MODE" = "single" ]; then
98-
if echo "$CONFIG_PATH" | grep -qE '^https?://'; then
99-
if ! curl --output /dev/null --silent --head --fail "$CONFIG_PATH"; then
100-
echo -e "\e[33m[Warning] Remote config file at '$CONFIG_PATH' not found. Falling back on sample config.\e[0m"
101-
CONFIG_PATH="./default-config.json"
102-
fi
103-
elif [ ! -f "$CONFIG_PATH" ]; then
104-
echo -e "\e[33m[Warning] Config file at '$CONFIG_PATH' not found. Falling back on sample config.\e[0m"
105-
CONFIG_PATH="./default-config.json"
106-
fi
107-
108-
echo -e "\e[34m[Info] Using config file at: '$CONFIG_PATH'.\e[0m"
109-
fi
11089

11190
# Update NextJs public env variables w/o requiring a rebuild.
11291
# @see: https://phase.dev/blog/nextjs-public-runtime-variables/

package.json

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -6,12 +6,8 @@
66
"scripts": {
77
"build": "yarn workspaces run build",
88
"test": "yarn workspaces run test",
9-
"dev": "cross-env SOURCEBOT_TENANT_MODE=single npm-run-all --print-label dev:start",
10-
"dev:mt": "cross-env SOURCEBOT_TENANT_MODE=multi npm-run-all --print-label dev:start:mt",
11-
"dev:start": "yarn workspace @sourcebot/db prisma:migrate:dev && cross-env npm-run-all --print-label --parallel dev:zoekt dev:backend dev:web",
12-
"dev:start:mt": "yarn workspace @sourcebot/db prisma:migrate:dev && cross-env npm-run-all --print-label --parallel dev:zoekt:mt dev:backend dev:web",
13-
"dev:zoekt": "export PATH=\"$PWD/bin:$PATH\" && export SRC_TENANT_ENFORCEMENT_MODE=none && zoekt-webserver -index .sourcebot/index -rpc",
14-
"dev:zoekt:mt": "export PATH=\"$PWD/bin:$PATH\" && export SRC_TENANT_ENFORCEMENT_MODE=strict && zoekt-webserver -index .sourcebot/index -rpc",
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",
1511
"dev:backend": "yarn workspace @sourcebot/backend dev:watch",
1612
"dev:web": "yarn workspace @sourcebot/web dev"
1713
},

packages/backend/package.json

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

packages/backend/src/environment.ts

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import dotenv from 'dotenv';
22

33
export const getEnv = (env: string | undefined, defaultValue?: string, required?: boolean) => {
44
if (required && !env && !defaultValue) {
5-
throw new Error(`Missing required environment variable`);
5+
throw new Error(`Missing required environment variable: ${env}`);
66
}
77

88
return env ?? defaultValue;
@@ -20,7 +20,6 @@ dotenv.config({
2020
});
2121

2222

23-
export const SOURCEBOT_TENANT_MODE = getEnv(process.env.SOURCEBOT_TENANT_MODE, undefined, true);
2423
export const SOURCEBOT_LOG_LEVEL = getEnv(process.env.SOURCEBOT_LOG_LEVEL, 'info')!;
2524
export const SOURCEBOT_TELEMETRY_DISABLED = getEnvBoolean(process.env.SOURCEBOT_TELEMETRY_DISABLED, false)!;
2625
export const SOURCEBOT_INSTALL_ID = getEnv(process.env.SOURCEBOT_INSTALL_ID, 'unknown')!;

packages/backend/src/index.ts

Lines changed: 0 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,9 @@ import { ArgumentParser } from "argparse";
22
import { existsSync } from 'fs';
33
import { mkdir } from 'fs/promises';
44
import path from 'path';
5-
import { isRemotePath } from "./utils.js";
65
import { AppContext } from "./types.js";
76
import { main } from "./main.js"
87
import { PrismaClient } from "@sourcebot/db";
9-
import { SOURCEBOT_TENANT_MODE } from "./environment.js";
108

119

1210
const parser = new ArgumentParser({
@@ -18,22 +16,12 @@ type Arguments = {
1816
cacheDir: string;
1917
}
2018

21-
parser.add_argument("--configPath", {
22-
help: "Path to config file",
23-
required: SOURCEBOT_TENANT_MODE === "single",
24-
});
25-
2619
parser.add_argument("--cacheDir", {
2720
help: "Path to .sourcebot cache directory",
2821
required: true,
2922
});
3023
const args = parser.parse_args() as Arguments;
3124

32-
if (SOURCEBOT_TENANT_MODE === "single" && !isRemotePath(args.configPath) && !existsSync(args.configPath)) {
33-
console.error(`Config file ${args.configPath} does not exist, and is required in single tenant mode`);
34-
process.exit(1);
35-
}
36-
3725
const cacheDir = args.cacheDir;
3826
const reposPath = path.join(cacheDir, 'repos');
3927
const indexPath = path.join(cacheDir, 'index');
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
/*
2+
Warnings:
3+
4+
- A unique constraint covering the columns `[domain]` on the table `Org` will be added. If there are existing duplicate values, this will fail.
5+
- Added the required column `domain` to the `Org` table without a default value. This is not possible if the table is not empty.
6+
7+
*/
8+
-- AlterTable
9+
ALTER TABLE "Org" ADD COLUMN "domain" TEXT NOT NULL;
10+
11+
-- CreateIndex
12+
CREATE UNIQUE INDEX "Org_domain_key" ON "Org"("domain");
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
/*
2+
Warnings:
3+
4+
- You are about to drop the column `activeOrgId` on the `User` table. All the data in the column will be lost.
5+
6+
*/
7+
-- AlterTable
8+
ALTER TABLE "User" DROP COLUMN "activeOrgId";

packages/db/prisma/schema.prisma

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -107,6 +107,7 @@ model Invite {
107107
model Org {
108108
id Int @id @default(autoincrement())
109109
name String
110+
domain String @unique
110111
createdAt DateTime @default(now())
111112
updatedAt DateTime @updatedAt
112113
members UserToOrg[]
@@ -161,7 +162,6 @@ model User {
161162
image String?
162163
accounts Account[]
163164
orgs UserToOrg[]
164-
activeOrgId Int?
165165
166166
/// List of pending invites that the user has created
167167
invites Invite[]

packages/schemas/src/v2/index.schema.ts

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -147,10 +147,6 @@ const schema = {
147147
]
148148
]
149149
},
150-
"tenantId": {
151-
"type": "number",
152-
"description": "@nocheckin"
153-
},
154150
"exclude": {
155151
"type": "object",
156152
"properties": {

packages/schemas/src/v2/index.type.ts

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -95,10 +95,6 @@ export interface GitHubConfig {
9595
* @minItems 1
9696
*/
9797
topics?: string[];
98-
/**
99-
* @nocheckin
100-
*/
101-
tenantId?: number;
10298
exclude?: {
10399
/**
104100
* Exclude forked repositories from syncing.

packages/web/package.json

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -104,6 +104,7 @@
104104
"next-themes": "^0.3.0",
105105
"posthog-js": "^1.161.5",
106106
"pretty-bytes": "^6.1.1",
107+
"psl": "^1.15.0",
107108
"react": "^18",
108109
"react-dom": "^18",
109110
"react-hook-form": "^7.53.0",
@@ -120,6 +121,7 @@
120121
},
121122
"devDependencies": {
122123
"@types/node": "^20",
124+
"@types/psl": "^1.1.3",
123125
"@types/react": "^18",
124126
"@types/react-dom": "^18",
125127
"@typescript-eslint/eslint-plugin": "^8.3.0",

0 commit comments

Comments
 (0)