Switch to Bun instead of Deno (or Yarn) for faster web app builds

This commit is contained in:
Debanjum
2025-07-31 23:12:55 -07:00
parent b86430227c
commit 8ad38dfe11
14 changed files with 1621 additions and 10831 deletions

View File

@@ -1,14 +1,14 @@
ARG PYTHON_VERSION=3.12
FROM mcr.microsoft.com/devcontainers/python:${PYTHON_VERSION}
# Install UV and Deno
RUN curl -fsSL https://deno.land/install.sh | sh
# Install UV and Bun
RUN curl -fsSL https://bun.sh/install | bash
COPY --from=ghcr.io/astral-sh/uv:latest /uv /uvx /bin/
RUN uv python pin $PYTHON_VERSION
# create python virtual environment
RUN uv venv /opt/venv --python $PYTHON_VERSION --seed
# Add venv, deno to PATH for subsequent RUN commands and for the container environment
ENV PATH="/opt/venv/bin:/root/.deno/bin:$PATH"
ENV PATH="/opt/venv/bin:/root/.bun/bin:$PATH"
# Setup working directory
WORKDIR /workspace
@@ -31,10 +31,10 @@ RUN sed -i "s/dynamic = \\[\"version\"\\]/version = \"$VERSION\"/" pyproject.tom
# --- Web App Dependencies ---
# Copy web app manifest files
COPY src/interface/web/package.json src/interface/web/deno.json src/interface/web/deno.lock /tmp/web/
COPY src/interface/web/package.json src/interface/web/bun.lock /tmp/web/
# Install web app dependencies
RUN cd /tmp/web && deno install
RUN cd /tmp/web && bun install
# The .venv and node_modules are now populated in the image.
# The rest of the source code will be mounted by VS Code from your local checkout,

View File

@@ -51,4 +51,4 @@ jobs:
run: uv sync --all-extras
- name: 🌡️ Validate Application
run: pre-commit run --hook-stage manual --all
run: uv run pre-commit run --hook-stage manual --all

View File

@@ -40,22 +40,22 @@ jobs:
version: "latest"
- name: Set up Python 3.11
run: uv python install 3.11
run: uv python install 3.11.12
- name: ⬇️ Install Server
run: uv sync --all-extras
- name: Install bun
uses: oven-sh/setup-bun@v2
with:
bun-version: latest
- name: ⬇️ Install Web Client
run: |
yarn install
yarn pypiciexport
bun install
bun pypiciexport
working-directory: src/interface/web
- name: 📂 Copy Generated Files
run: |
mkdir -p src/khoj/interface/compiled
cp -r $(uv python find-python 3.11)/lib/python3.11/site-packages/khoj/interface/compiled/* src/khoj/interface/compiled/
- name: ⚙️ Build Python Package
run: |
# Setup Environment for Reproducible Builds

View File

@@ -88,5 +88,5 @@ jobs:
POSTGRES_PASSWORD: postgres
POSTGRES_DB: postgres
GEMINI_API_KEY: ${{ secrets.GEMINI_API_KEY }}
run: pytest
run: uv run pytest
timeout-minutes: 10

View File

@@ -35,17 +35,17 @@ RUN sed -i "s/dynamic = \\[\"version\"\\]/version = \"$VERSION\"/" pyproject.tom
pip install --no-cache-dir .
# Build Web App
FROM node:23-alpine AS web-app
FROM oven/bun:1-alpine AS web-app
# Set build optimization env vars
ENV NODE_ENV=production
ENV NEXT_TELEMETRY_DISABLED=1
WORKDIR /app/src/interface/web
# Install dependencies first (cache layer)
COPY src/interface/web/package.json src/interface/web/yarn.lock ./
RUN yarn install --frozen-lockfile
COPY src/interface/web/package.json src/interface/web/bun.lock ./
RUN bun install --frozen-lockfile
# Copy source and build
COPY src/interface/web/. ./
RUN yarn build
RUN bun run build
# Merge the Server and Web App into a Single Image
FROM base

View File

@@ -34,17 +34,17 @@ RUN sed -i "s/dynamic = \\[\"version\"\\]/version = \"$VERSION\"/" pyproject.tom
pip install --no-cache-dir -e .[prod]
# Build Web App
FROM node:20-alpine AS web-app
FROM oven/bun:1-alpine AS web-app
# Set build optimization env vars
ENV NODE_ENV=production
ENV NEXT_TELEMETRY_DISABLED=1
WORKDIR /app/src/interface/web
# Install dependencies first (cache layer)
COPY src/interface/web/package.json src/interface/web/yarn.lock ./
RUN yarn install --frozen-lockfile
COPY src/interface/web/package.json src/interface/web/bun.lock ./
RUN bun install --frozen-lockfile
# Copy source and build
COPY src/interface/web/. ./
RUN yarn build
RUN bun run build
# Merge the Server and Web App into a Single Image
FROM base

View File

@@ -40,10 +40,10 @@ if [ "$DEVCONTAINER" = true ]; then
# Install Web App using cached dependencies
echo "Installing Web App using cached dependencies..."
cd "$PROJECT_ROOT/src/interface/web"
if command -v deno &> /dev/null
if command -v bun &> /dev/null
then
echo "using Deno."
deno install && deno run ciexport
echo "using Bun."
bun install && bun run ciexport
else
echo "using Yarn."
yarn install && yarn ciexport
@@ -63,10 +63,10 @@ else
echo "Installing Web App..."
cd "$PROJECT_ROOT/src/interface/web"
if command -v deno &> /dev/null
if command -v bun &> /dev/null
then
echo "using Deno."
deno install && deno run export
echo "using Bun."
bun install && bun run export
else
echo "using Yarn."
yarn install && yarn export

View File

@@ -1,5 +1,5 @@
#!/usr/bin/env sh
. "$(dirname "$0")/_/husky.sh"
yarn run lint-staged
yarn test
bun run lint-staged
bun run test

View File

@@ -5,19 +5,19 @@ This is a [Next.js](https://nextjs.org/) project.
First, install the dependencies:
```bash
yarn install
bun install
```
In case you run into any dependency linking issues, you can try running:
```bash
yarn add next
bun add next
```
### Run the development server:
```bash
yarn dev
bun dev
```
Make sure the `rewrites` in `next.config.mjs` are set up correctly for your environment. The rewrites are used to proxy requests to the API server.
@@ -44,27 +44,30 @@ You can start editing the page by modifying any of the `.tsx` pages. The page au
We've setup a utility command for building and serving the built files. This is useful for testing the production build locally.
1. Exporting code
To build the files once and serve them, run:
To build the files once and serve them, run:
```bash
yarn export
bun export
```
If you're using Windows:
```bash
yarn windowsexport
```
```bash
bun windowsexport
```
2. Continuously building code
To keep building the files and serving them, run:
```bash
yarn watch
bun watch
```
If you're using Windows:
```bash
yarn windowswatch
bun windowswatch
```
Now you should be able to load your custom pages from the Khoj app at http://localhost:42110/. To server any of the built files, you should update the routes in the `web_client.py` like so, where `new_file` is the new page you've added in this repo:

1568
src/interface/web/bun.lock Normal file

File diff suppressed because it is too large Load Diff

View File

@@ -1,10 +0,0 @@
{
"tasks": {
"hook": "deno run --allow-read --allow-run --allow-write https://deno.land/x/deno_hooks@0.1.1/mod.ts"
},
"fmt": {
"indentWidth": 4,
"lineWidth": 100,
"proseWrap": "preserve"
}
}

File diff suppressed because it is too large Load Diff

View File

@@ -6,16 +6,16 @@
"dev": "next dev",
"build": "next build",
"start": "next start",
"lint": "deno fmt",
"lint": "next lint",
"collectstatic": "bash -c 'pushd ../../../ && source .venv/bin/activate && python3 src/khoj/manage.py collectstatic --noinput && deactivate && popd'",
"cicollectstatic": "bash -c 'pushd ../../../ && python3 src/khoj/manage.py collectstatic --noinput && popd'",
"export": "yarn build && cp -r out/ ../../khoj/interface/built && yarn collectstatic",
"ciexport": "yarn build && cp -r out/ ../../khoj/interface/built && yarn cicollectstatic",
"pypiciexport": "yarn build && cp -r out/ /opt/hostedtoolcache/Python/3.11.12/x64/lib/python3.11/site-packages/khoj/interface/compiled && yarn cicollectstatic",
"watch": "nodemon --watch . --ext js,jsx,ts,tsx,css --ignore 'out/**/*' --exec 'yarn export'",
"windowswatch": "nodemon --watch . --ext js,jsx,ts,tsx,css --ignore 'out/**/*' --exec 'yarn windowsexport'",
"cicollectstatic": "bash -c 'pushd ../../../ && uv run python src/khoj/manage.py collectstatic --noinput && popd'",
"export": "bun run build && cp -r out/ ../../khoj/interface/built && bun run collectstatic",
"ciexport": "bun run build && cp -r out/ ../../khoj/interface/built && bun run cicollectstatic",
"pypiciexport": "bun run build && mkdir -p ../../khoj/interface/compiled && cp -r out/. ../../khoj/interface/compiled && bun run cicollectstatic",
"watch": "nodemon --watch . --ext js,jsx,ts,tsx,css --ignore 'out/**/*' --exec 'bun run export'",
"windowswatch": "nodemon --watch . --ext js,jsx,ts,tsx,css --ignore 'out/**/*' --exec 'bun run windowsexport'",
"windowscollectstatic": "cd ..\\..\\.. && .\\.venv\\Scripts\\Activate.bat && py .\\src\\khoj\\manage.py collectstatic --noinput && .\\.venv\\Scripts\\deactivate.bat && cd ..",
"windowsexport": "yarn build && xcopy out ..\\..\\khoj\\interface\\built /E /Y && yarn windowscollectstatic",
"windowsexport": "bun run build && xcopy out ..\\..\\khoj\\interface\\built /E /Y && bun run windowscollectstatic",
"prepare": "husky"
},
"dependencies": {
@@ -100,6 +100,6 @@
"printWidth": 100
},
"lint-staged": {
"*": "yarn lint --fix"
"*": "bun run lint"
}
}

File diff suppressed because it is too large Load Diff