diff --git a/.dockerignore b/.dockerignore index c37ab8a5..a589c140 100644 --- a/.dockerignore +++ b/.dockerignore @@ -7,4 +7,5 @@ README.md !.next/static !.next/standalone .git -.sourcebot \ No newline at end of file +.sourcebot +.env.local \ No newline at end of file diff --git a/.env b/.env new file mode 100644 index 00000000..8bcb9623 --- /dev/null +++ b/.env @@ -0,0 +1,4 @@ +NEXT_PUBLIC_POSTHOG_KEY=phc_VFn4CkEGHRdlVyOOw8mfkoj1DKVoG6y1007EClvzAnS +NEXT_PUBLIC_POSTHOG_HOST=https://us.i.posthog.com +NEXT_PUBLIC_POSTHOG_ASSET_HOST=https://us-assets.i.posthog.com +NEXT_PUBLIC_POSTHOG_UI_HOST=https://us.posthog.com \ No newline at end of file diff --git a/Dockerfile b/Dockerfile index 976e6b92..90854fd6 100644 --- a/Dockerfile +++ b/Dockerfile @@ -22,6 +22,8 @@ RUN yarn config set network-timeout 1200000 RUN yarn --frozen-lockfile COPY . . ENV NEXT_TELEMETRY_DISABLED=1 +# @see: https://phase.dev/blog/nextjs-public-runtime-variables/ +ARG NEXT_PUBLIC_SOURCEBOT_TELEMETRY_DISABLED=BAKED_NEXT_PUBLIC_SOURCEBOT_TELEMETRY_DISABLED RUN yarn run build # ------ Runner ------ @@ -33,6 +35,9 @@ ENV DATA_DIR=/data ENV CONFIG_PATH=$DATA_DIR/config.json ENV DATA_CACHE_DIR=$DATA_DIR/.sourcebot +# Sourcebot collects anonymous usage data using [PostHog](https://posthog.com/). Uncomment this line to disable. +# ENV SOURCEBOT_TELEMETRY_DISABLED=1 + # Configure dependencies RUN apk add --no-cache git ca-certificates bind-tools tini jansson wget supervisor diff --git a/README.md b/README.md index 23085b23..c8d15de8 100644 --- a/README.md +++ b/README.md @@ -65,20 +65,26 @@ zoekt will now index your repositories (at `HEAD`). By default, it will re-index 4. Go to `http://localhost:3000` - once a index has been created, you should get results. - - ## Building Sourcebot TODO -## GitLab +## Disabling Telemetry + +By default, Sourcebot collects anonymous usage data using [PostHog](https://posthog.com/). You can disable this by setting the environment variable `SOURCEBOT_TELEMETRY_DISABLED` to `1` in the docker run command. Example: +```sh +docker run -e SOURCEBOT_TELEMETRY_DISABLED=1 ...stuff... ghcr.io/taqlaai/sourcebot:main +``` + + +# GitLab TODO -## BitBucket +# BitBucket TODO -### Todos +# Todos - Add instructions on using GitLab and BitBucket - Add instructions on building Sourcebot locally diff --git a/entrypoint.sh b/entrypoint.sh index 83beb30b..9b6e6fca 100644 --- a/entrypoint.sh +++ b/entrypoint.sh @@ -1,7 +1,6 @@ #!/bin/sh set -e - # Check if CONFIG_PATH is set if [ -z "$CONFIG_PATH" ]; then echo "\e[33mWarning: CONFIG_PATH environment variable is not set.\e[0m" @@ -35,4 +34,17 @@ else echo -e "\e[33mWarning: GitLab repositories will not be indexed since GITLAB_TOKEN was not set. If you are not using GitLab, disregard.\e[0m" fi +# Update nextjs public env variables w/o requiring a rebuild. +# @see: https://phase.dev/blog/nextjs-public-runtime-variables/ + +# Infer NEXT_PUBLIC_SOURCEBOT_TELEMETRY_DISABLED if it is not set +if [ -z "$NEXT_PUBLIC_SOURCEBOT_TELEMETRY_DISABLED" ] && [ ! -z "$SOURCEBOT_TELEMETRY_DISABLED" ]; then + export NEXT_PUBLIC_SOURCEBOT_TELEMETRY_DISABLED="$SOURCEBOT_TELEMETRY_DISABLED" +fi + +find /app/public /app/.next -type f -name "*.js" | +while read file; do + sed -i "s|BAKED_NEXT_PUBLIC_SOURCEBOT_TELEMETRY_DISABLED|${NEXT_PUBLIC_SOURCEBOT_TELEMETRY_DISABLED}|g" "$file" +done + exec supervisord -c /etc/supervisor/conf.d/supervisord.conf \ No newline at end of file diff --git a/next.config.mjs b/next.config.mjs index 13928e00..a44d1189 100644 --- a/next.config.mjs +++ b/next.config.mjs @@ -1,6 +1,26 @@ /** @type {import('next').NextConfig} */ const nextConfig = { - output: "standalone" + output: "standalone", + + // @see : https://posthog.com/docs/advanced/proxy/nextjs + async rewrites() { + return [ + { + source: "/ingest/static/:path*", + destination: `${process.env.NEXT_PUBLIC_POSTHOG_ASSET_HOST}/static/:path*`, + }, + { + source: "/ingest/:path*", + destination: `${process.env.NEXT_PUBLIC_POSTHOG_HOST}/:path*`, + }, + { + source: "/ingest/decide", + destination: `${process.env.NEXT_PUBLIC_POSTHOG_HOST}/decide`, + }, + ]; + }, + // This is required to support PostHog trailing slash API requests + skipTrailingSlashRedirect: true, }; export default nextConfig; diff --git a/package.json b/package.json index e9bdc94d..2b66e969 100644 --- a/package.json +++ b/package.json @@ -27,17 +27,20 @@ "@tanstack/react-table": "^8.20.5", "@uiw/react-codemirror": "^4.23.0", "class-variance-authority": "^0.7.0", + "client-only": "^0.0.1", "clsx": "^2.1.1", "escape-string-regexp": "^5.0.0", "http-status-codes": "^2.3.0", "lucide-react": "^0.435.0", "next": "14.2.6", "next-themes": "^0.3.0", + "posthog-js": "^1.161.5", "react": "^18", "react-dom": "^18", "react-hook-form": "^7.53.0", "react-hotkeys-hook": "^4.5.1", "react-resizable-panels": "^2.1.1", + "server-only": "^0.0.1", "sharp": "^0.33.5", "tailwind-merge": "^2.5.2", "tailwindcss-animate": "^1.0.7", diff --git a/src/app/layout.tsx b/src/app/layout.tsx index 29214f13..d698c6ec 100644 --- a/src/app/layout.tsx +++ b/src/app/layout.tsx @@ -4,9 +4,15 @@ import "./globals.css"; import { ThemeProvider } from "next-themes"; import { Suspense } from "react"; import { QueryClientProvider } from "./queryClientProvider"; +import { PHProvider } from "./posthogProvider"; +import dynamic from "next/dynamic"; const inter = Inter({ subsets: ["latin"] }); +const PostHogPageView = dynamic(() => import('./posthogPageView'), { + ssr: false, + }) + export const metadata: Metadata = { title: "Sourcebot", description: "Sourcebot", @@ -24,22 +30,25 @@ export default function RootLayout({ suppressHydrationWarning >
-