Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[wip] v3 effort #158

Draft
wants to merge 118 commits into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from 2 commits
Commits
Show all changes
118 commits
Select commit Hold shift + click to select a range
15b9e77
SQL Database (#157)
brendan-kellam Jan 14, 2025
95f637f
point zoekt to v3 branch
brendan-kellam Jan 14, 2025
3c3140e
bump zoekt version
msukkari Jan 14, 2025
553f5d2
Add tenant ID concept into web app and backend (#160)
msukkari Jan 15, 2025
bd027f7
bump zoekt version
msukkari Jan 15, 2025
7029aa7
parallelize repo indexing (#163)
msukkari Jan 15, 2025
6cf10b4
Authentication (#164)
brendan-kellam Jan 16, 2025
5d253ff
Add Org table (#167)
brendan-kellam Jan 17, 2025
a5091fb
Move logout button & profile picture into settings dropdown (#172)
brendan-kellam Jan 19, 2025
7c6adf1
Multi tenancy support in config syncer (#171)
msukkari Jan 21, 2025
738bbaa
add tenant mode support in docker container:
msukkari Jan 21, 2025
9c120c6
Organization switching & active org management (#173)
brendan-kellam Jan 21, 2025
8a3521b
updated syncedAt date after config sync:
msukkari Jan 23, 2025
a5006c5
Migrate to postgres (#174)
msukkari Jan 23, 2025
0322cd8
Connection creation form (#175)
brendan-kellam Jan 23, 2025
ed0d28a
fix issue with yarn dev startup
brendan-kellam Jan 23, 2025
78c9111
init (#176)
brendan-kellam Jan 23, 2025
bae7ca3
Add `@sourcebot/schemas` package (#177)
brendan-kellam Jan 24, 2025
dd8ff6e
Connection management (#178)
brendan-kellam Jan 24, 2025
31114a9
add concept of secrets (#180)
msukkari Jan 27, 2025
a88f9e6
bump zoekt version
msukkari Jan 28, 2025
75d4189
enforce tenancy on search and repo listing endpoints (#181)
msukkari Jan 28, 2025
dffbbae
adds garbage collection for repos (#182)
msukkari Jan 29, 2025
9946901
add initial logic for staging environment
msukkari Jan 30, 2025
f92acc0
try to move encryption key env decleration in docker file to fix buil…
msukkari Jan 30, 2025
92530a7
switch encryption key as build arg to se if that fixes build issues
msukkari Jan 30, 2025
2b6125b
add deployment action for staging image
msukkari Jan 30, 2025
d37a969
try using mac github action runners instead
msukkari Jan 30, 2025
d513f93
switch to using arm64 runners on arm64 build
msukkari Jan 30, 2025
bb4ff37
change workflow names to fix trigger issue
msukkari Jan 30, 2025
22e0096
trigger staging actions to see if it works
msukkari Jan 31, 2025
7b6226b
fix working directory typo and pray it doesnt push to prod
msukkari Jan 31, 2025
44dd53f
checkout v3 when deploying staging
msukkari Jan 31, 2025
4e7ac93
try to change into the staging dir manuall
msukkari Jan 31, 2025
94908c0
dummy commit to trigger v3 workflows to test
msukkari Jan 31, 2025
4d4988d
update staging deploy script to match new version in main
msukkari Jan 31, 2025
829eede
reference proper image:tag in staging fly config
msukkari Jan 31, 2025
afff36f
update staging fly config to point to ghcr
msukkari Jan 31, 2025
846d73b
Connection management (#183)
brendan-kellam Feb 4, 2025
9055018
add invite system and google oauth provider (#185)
msukkari Feb 10, 2025
70f7729
fix reference to header component in connections
msukkari Feb 10, 2025
5858e31
add google logo to google oauth
msukkari Feb 10, 2025
7da8a7f
fix web build errors
msukkari Feb 10, 2025
775138c
bump staging resources
msukkari Feb 10, 2025
568ded8
change staging cpu to perf
msukkari Feb 11, 2025
23f3c60
add side bar nav in settings page
msukkari Feb 11, 2025
04991fd
improve styling of members page
msukkari Feb 11, 2025
fde2179
wip adding stripe checkout button
msukkari Feb 11, 2025
9665f14
wip onboarding flow
msukkari Feb 12, 2025
33ae585
add stripe subscription id to org
msukkari Feb 12, 2025
e7f8f51
save stripe session id and add manage subscription button in settings
msukkari Feb 12, 2025
3ad6c2d
properly block access to pages if user isn't in an org
msukkari Feb 12, 2025
0a79f7c
wip add paywall
msukkari Feb 12, 2025
8d2c731
Domain support
brendan-kellam Feb 12, 2025
34c9c1d
Domain support (#188)
brendan-kellam Feb 12, 2025
ac15b7c
Update Makefile to include crypto package when doing a make clean
brendan-kellam Feb 12, 2025
e0976e4
Add default for AUTH_URL in attempt to fix build
brendan-kellam Feb 12, 2025
d17c90a
attempt 2
brendan-kellam Feb 12, 2025
98becf5
fix attempt #3: Do not require a encrpytion key at build time
brendan-kellam Feb 12, 2025
53dac38
merge domain changes
msukkari Feb 12, 2025
ba333dd
Fix generate script race condition
brendan-kellam Feb 12, 2025
19780aa
Attempt #4
brendan-kellam Feb 12, 2025
6caed35
add back paywall and also add support for incrememnting seat count on…
msukkari Feb 13, 2025
8ad6ba7
prevent self invite
msukkari Feb 13, 2025
258585e
action button styling in settings and toast on copy
msukkari Feb 13, 2025
84e8ec2
add ability to remove member from org
msukkari Feb 13, 2025
0b4140f
move stripe product id to env var
msukkari Feb 13, 2025
875f9b8
add await for blocking loop in backend
msukkari Feb 13, 2025
193c7e0
add subscription info to billing page
msukkari Feb 13, 2025
e2c90b8
handle trial case in billing info page
msukkari Feb 13, 2025
8929d05
add trial duration indicator to nav bar
msukkari Feb 13, 2025
a70c577
merge v3 changes into billing branch
msukkari Feb 13, 2025
5a3eab2
check if domain starts or ends with dash
msukkari Feb 13, 2025
e369925
remove unused no org component
msukkari Feb 13, 2025
e6ee45c
Generate AUTH_SECRET if not provided (#189)
brendan-kellam Feb 13, 2025
b0cbcf0
remove package lock file and fix prisma dep version
msukkari Feb 13, 2025
d463748
revert dep version updates
msukkari Feb 13, 2025
4c0805c
fix yarn.lock
brendan-kellam Feb 13, 2025
0f43c00
add auth and membership check to fetchSubscription
msukkari Feb 13, 2025
cf97955
properly handle invite redeem with no valid subscription case
msukkari Feb 13, 2025
ea4c29d
change back fetch subscription to not require org membership
msukkari Feb 13, 2025
87efbf7
add back subscription check in invite redeem page
msukkari Feb 13, 2025
7c18712
Add stripe billing logic (#190)
msukkari Feb 13, 2025
674511a
fix nits
msukkari Feb 14, 2025
8fb438b
remove providers check
brendan-kellam Feb 14, 2025
fbd3e41
fix more nits
msukkari Feb 14, 2025
6234967
merge v3 changes
msukkari Feb 14, 2025
888a2e3
change stripe init to be behind function
msukkari Feb 14, 2025
26cc70c
fix publishible stripe key handling in docker container
msukkari Feb 14, 2025
e2e5433
enforce owner perms (#191)
msukkari Feb 14, 2025
da33220
add back gitlab, gitea, and gerrit support (#184)
msukkari Feb 14, 2025
4cf3024
fix apos usage in redeem page
msukkari Feb 14, 2025
354b004
change csrf cookie to secure not host
msukkari Feb 14, 2025
86a80a4
Credentials provider (#192)
brendan-kellam Feb 15, 2025
3be3680
cleanup org's repos and shards if it's inactive (#194)
msukkari Feb 15, 2025
e0d3634
connections qol improvements (#195)
msukkari Feb 15, 2025
2111a77
Fix build with suspense boundary
brendan-kellam Feb 15, 2025
331a418
improved fix
brendan-kellam Feb 15, 2025
54d14ea
add retries for 429 issues (#196)
msukkari Feb 16, 2025
e17331a
fix build errors and add index concurrency env var
msukkari Feb 16, 2025
e09b21f
add config upsert timeout env var
msukkari Feb 16, 2025
f652ca5
Membership settings rework (#198)
brendan-kellam Feb 18, 2025
bbf8b9b
Magic links (#199)
brendan-kellam Feb 18, 2025
390d92d
Fix build
brendan-kellam Feb 18, 2025
5d7a77b
db performance improvements and job resilience (#200)
msukkari Feb 19, 2025
63af99a
remove non secret token options
msukkari Feb 19, 2025
b99a648
fix token examples in schema
msukkari Feb 19, 2025
fdd71cf
add better visualization for connection/repo errors and warnings (#201)
msukkari Feb 20, 2025
62e64c1
add orgid unique constraint to repo
msukkari Feb 20, 2025
c930fe0
revert repo compile update logic to upsert loop
msukkari Feb 20, 2025
0ac9509
log upsert stats
msukkari Feb 20, 2025
5076ee7
[temp] disable polling everywhere (#205)
brendan-kellam Feb 21, 2025
a79c162
add health check endpoint
msukkari Feb 21, 2025
fee0767
Refined onboarding flow (#202)
brendan-kellam Feb 21, 2025
70e309b
Redeem UX pass (#204)
brendan-kellam Feb 21, 2025
fa0bb82
add log for health check
msukkari Feb 21, 2025
dc42a76
fix new connection complete callback route
msukkari Feb 21, 2025
ced6c52
add cpu split logic and only wait for postgres if we're going to conn…
msukkari Feb 22, 2025
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions .gitmodules
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
[submodule "vendor/zoekt"]
path = vendor/zoekt
url = https://github.com/sourcebot-dev/zoekt
# @nocheckin : update this to main when we have a release
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nocheckin

branch=v3
15 changes: 15 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -31,13 +31,24 @@ ENV NEXT_PUBLIC_POSTHOG_PAPIK=BAKED_NEXT_PUBLIC_POSTHOG_PAPIK
ARG NEXT_PUBLIC_DOMAIN_SUB_PATH=/BAKED_NEXT_PUBLIC_DOMAIN_SUB_PATH
RUN yarn workspace @sourcebot/web build

# ------ Build Database ------
FROM node-alpine AS database-builder
WORKDIR /app

COPY package.json yarn.lock* ./
COPY ./packages/db ./packages/db
RUN yarn workspace @sourcebot/db install --frozen-lockfile


# ------ Build Backend ------
FROM node-alpine AS backend-builder
WORKDIR /app

COPY package.json yarn.lock* ./
COPY ./schemas ./schemas
COPY ./packages/backend ./packages/backend
COPY --from=database-builder /app/node_modules ./node_modules
COPY --from=database-builder /app/packages/db ./packages/db
RUN yarn workspace @sourcebot/backend install --frozen-lockfile
RUN yarn workspace @sourcebot/backend build

Expand Down Expand Up @@ -100,6 +111,10 @@ COPY --from=web-builder /app/packages/web/.next/static ./packages/web/.next/stat
COPY --from=backend-builder /app/node_modules ./node_modules
COPY --from=backend-builder /app/packages/backend ./packages/backend

# Configure the database
COPY --from=database-builder /app/node_modules ./node_modules
COPY --from=database-builder /app/packages/db ./packages/db

COPY supervisord.conf /etc/supervisor/conf.d/supervisord.conf
COPY prefix-output.sh ./prefix-output.sh
RUN chmod +x ./prefix-output.sh
Expand Down
7 changes: 5 additions & 2 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@

CMDS := zoekt ui
CMDS := zoekt yarn

ALL: $(CMDS)

ui:
yarn:
yarn install
yarn workspace @sourcebot/db prisma:migrate:dev

zoekt:
mkdir -p bin
Expand All @@ -20,6 +21,8 @@ clean:
packages/web/.next \
packages/backend/dist \
packages/backend/node_modules \
packages/db/node_modules \
packages/db/dist \
.sourcebot

.PHONY: bin
5 changes: 5 additions & 0 deletions entrypoint.sh
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,11 @@ if [ ! -d "$DATA_CACHE_DIR" ]; then
mkdir -p "$DATA_CACHE_DIR"
fi

# Run a Database migration
echo -e "\e[34m[Info] Running database migration...\e[0m"
export DATABASE_URL="file:$DATA_CACHE_DIR/db.sqlite"
yarn workspace @sourcebot/db prisma:migrate:prod

# In order to detect if this is the first run, we create a `.installed` file in
# the cache directory.
FIRST_RUN_FILE="$DATA_CACHE_DIR/.installedv2"
Expand Down
134 changes: 134 additions & 0 deletions packages/backend/src/config.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,134 @@
import { PrismaClient } from '@sourcebot/db';
import { readFile } from 'fs/promises';
import stripJsonComments from 'strip-json-comments';
import { getGitHubReposFromConfig } from "./github.js";
import { getGitLabReposFromConfig, GITLAB_CLOUD_HOSTNAME } from "./gitlab.js";
import { SourcebotConfigurationSchema } from "./schemas/v2.js";
import { AppContext } from "./types.js";
import { getTokenFromConfig, isRemotePath, marshalBool } from "./utils.js";

export const syncConfig = async (configPath: string, db: PrismaClient, signal: AbortSignal, ctx: AppContext) => {
const configContent = await (async () => {
if (isRemotePath(configPath)) {
const response = await fetch(configPath, {
signal,
});
if (!response.ok) {
throw new Error(`Failed to fetch config file ${configPath}: ${response.statusText}`);
}
return response.text();
} else {
return readFile(configPath, {
encoding: 'utf-8',
signal,
});
}
})();

// @todo: we should validate the configuration file's structure here.
const config = JSON.parse(stripJsonComments(configContent)) as SourcebotConfigurationSchema;

for (const repoConfig of config.repos ?? []) {
switch (repoConfig.type) {
case 'github': {
const token = repoConfig.token ? getTokenFromConfig(repoConfig.token, ctx) : undefined;
const gitHubRepos = await getGitHubReposFromConfig(repoConfig, signal, ctx);
const hostUrl = repoConfig.url ?? 'https://github.com';
const hostname = repoConfig.url ? new URL(repoConfig.url).hostname : 'github.com';

await Promise.all(gitHubRepos.map((repo) => {
const repoName = `${hostname}/${repo.full_name}`;
const cloneUrl = new URL(repo.clone_url!);
if (token) {
cloneUrl.username = token;
}

const data = {
external_id: repo.id.toString(),
external_codeHostType: 'github',
external_codeHostUrl: hostUrl,
cloneUrl: cloneUrl.toString(),
name: repoName,
isFork: repo.fork,
isArchived: !!repo.archived,
metadata: {
'zoekt.web-url-type': 'github',
'zoekt.web-url': repo.html_url,
'zoekt.name': repoName,
'zoekt.github-stars': (repo.stargazers_count ?? 0).toString(),
'zoekt.github-watchers': (repo.watchers_count ?? 0).toString(),
'zoekt.github-subscribers': (repo.subscribers_count ?? 0).toString(),
'zoekt.github-forks': (repo.forks_count ?? 0).toString(),
'zoekt.archived': marshalBool(repo.archived),
'zoekt.fork': marshalBool(repo.fork),
'zoekt.public': marshalBool(repo.private === false)
},
};

return db.repo.upsert({
where: {
external_id_external_codeHostUrl: {
external_id: repo.id.toString(),
external_codeHostUrl: hostUrl,
},
},
create: data,
update: data,
})
}));

break;
}
case 'gitlab': {
const hostUrl = repoConfig.url ?? 'https://gitlab.com';
const hostname = repoConfig.url ? new URL(repoConfig.url).hostname : GITLAB_CLOUD_HOSTNAME;
const token = repoConfig.token ? getTokenFromConfig(repoConfig.token, ctx) : undefined;
const gitLabRepos = await getGitLabReposFromConfig(repoConfig, ctx);

await Promise.all(gitLabRepos.map((project) => {
const repoName = `${hostname}/${project.path_with_namespace}`;
const isFork = project.forked_from_project !== undefined;

const cloneUrl = new URL(project.http_url_to_repo);
if (token) {
cloneUrl.username = 'oauth2';
cloneUrl.password = token;
}

const data = {
external_id: project.id.toString(),
external_codeHostType: 'gitlab',
external_codeHostUrl: hostUrl,
cloneUrl: cloneUrl.toString(),
name: repoName,
isFork,
isArchived: project.archived,
metadata: {
'zoekt.web-url-type': 'gitlab',
'zoekt.web-url': project.web_url,
'zoekt.name': repoName,
'zoekt.gitlab-stars': project.star_count?.toString() ?? '0',
'zoekt.gitlab-forks': project.forks_count?.toString() ?? '0',
'zoekt.archived': marshalBool(project.archived),
'zoekt.fork': marshalBool(isFork),
'zoekt.public': marshalBool(project.visibility === 'public'),
}
}

return db.repo.upsert({
where: {
external_id_external_codeHostUrl: {
external_id: project.id.toString(),
external_codeHostUrl: hostUrl,
},
},
create: data,
update: data,
})
}));

break;
}
}
}
}
4 changes: 2 additions & 2 deletions packages/backend/src/constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,6 @@ import { Settings } from "./types.js";
export const DEFAULT_SETTINGS: Settings = {
maxFileSize: 2 * 1024 * 1024, // 2MB in bytes
autoDeleteStaleRepos: true,
reindexInterval: 1000 * 60 * 60, // 1 hour in milliseconds
resyncInterval: 1000 * 60 * 60 * 24, // 1 day in milliseconds
reindexIntervalMs: 1000 * 60 * 60, // 1 hour in milliseconds
resyncIntervalMs: 1000 * 60 * 60 * 24, // 1 day in milliseconds
}
125 changes: 0 additions & 125 deletions packages/backend/src/db.test.ts

This file was deleted.

Loading
Loading