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 ARG PYTHON_VERSION=3.12
FROM mcr.microsoft.com/devcontainers/python:${PYTHON_VERSION} FROM mcr.microsoft.com/devcontainers/python:${PYTHON_VERSION}
# Install UV and Deno # Install UV and Bun
RUN curl -fsSL https://deno.land/install.sh | sh RUN curl -fsSL https://bun.sh/install | bash
COPY --from=ghcr.io/astral-sh/uv:latest /uv /uvx /bin/ COPY --from=ghcr.io/astral-sh/uv:latest /uv /uvx /bin/
RUN uv python pin $PYTHON_VERSION RUN uv python pin $PYTHON_VERSION
# create python virtual environment # create python virtual environment
RUN uv venv /opt/venv --python $PYTHON_VERSION --seed RUN uv venv /opt/venv --python $PYTHON_VERSION --seed
# Add venv, deno to PATH for subsequent RUN commands and for the container environment # 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 # Setup working directory
WORKDIR /workspace WORKDIR /workspace
@@ -31,10 +31,10 @@ RUN sed -i "s/dynamic = \\[\"version\"\\]/version = \"$VERSION\"/" pyproject.tom
# --- Web App Dependencies --- # --- Web App Dependencies ---
# Copy web app manifest files # 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 # 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 .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, # 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 run: uv sync --all-extras
- name: 🌡️ Validate Application - 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" version: "latest"
- name: Set up Python 3.11 - name: Set up Python 3.11
run: uv python install 3.11 run: uv python install 3.11.12
- name: ⬇️ Install Server - name: ⬇️ Install Server
run: uv sync --all-extras run: uv sync --all-extras
- name: Install bun
uses: oven-sh/setup-bun@v2
with:
bun-version: latest
- name: ⬇️ Install Web Client - name: ⬇️ Install Web Client
run: | run: |
yarn install bun install
yarn pypiciexport bun pypiciexport
working-directory: src/interface/web 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 - name: ⚙️ Build Python Package
run: | run: |
# Setup Environment for Reproducible Builds # Setup Environment for Reproducible Builds

View File

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

View File

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

View File

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

View File

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

View File

@@ -5,19 +5,19 @@ This is a [Next.js](https://nextjs.org/) project.
First, install the dependencies: First, install the dependencies:
```bash ```bash
yarn install bun install
``` ```
In case you run into any dependency linking issues, you can try running: In case you run into any dependency linking issues, you can try running:
```bash ```bash
yarn add next bun add next
``` ```
### Run the development server: ### Run the development server:
```bash ```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. 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.
@@ -45,26 +45,29 @@ We've setup a utility command for building and serving the built files. This is
1. Exporting code 1. Exporting code
To build the files once and serve them, run: To build the files once and serve them, run:
```bash ```bash
yarn export bun export
``` ```
If you're using Windows: If you're using Windows:
```bash
yarn windowsexport
```
```bash
bun windowsexport
```
2. Continuously building code 2. Continuously building code
To keep building the files and serving them, run: To keep building the files and serving them, run:
```bash ```bash
yarn watch bun watch
``` ```
If you're using Windows: If you're using Windows:
```bash ```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: 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", "dev": "next dev",
"build": "next build", "build": "next build",
"start": "next start", "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'", "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'", "cicollectstatic": "bash -c 'pushd ../../../ && uv run python src/khoj/manage.py collectstatic --noinput && popd'",
"export": "yarn build && cp -r out/ ../../khoj/interface/built && yarn collectstatic", "export": "bun run build && cp -r out/ ../../khoj/interface/built && bun run collectstatic",
"ciexport": "yarn build && cp -r out/ ../../khoj/interface/built && yarn cicollectstatic", "ciexport": "bun run build && cp -r out/ ../../khoj/interface/built && bun run cicollectstatic",
"pypiciexport": "yarn build && cp -r out/ /opt/hostedtoolcache/Python/3.11.12/x64/lib/python3.11/site-packages/khoj/interface/compiled && yarn 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 'yarn export'", "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 'yarn windowsexport'", "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 ..", "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" "prepare": "husky"
}, },
"dependencies": { "dependencies": {
@@ -100,6 +100,6 @@
"printWidth": 100 "printWidth": 100
}, },
"lint-staged": { "lint-staged": {
"*": "yarn lint --fix" "*": "bun run lint"
} }
} }

File diff suppressed because it is too large Load Diff