From 63a1a8e91f0d93b3a4772b2c87f3eafe32bf5666 Mon Sep 17 00:00:00 2001 From: Debanjum Date: Tue, 3 Jun 2025 04:57:00 -0700 Subject: [PATCH] Try pre-install deps, use custom launch.json for dev container Previous attempts have not been sufficient. Let's see if this works --- .devcontainer/Dockerfile | 8 +++--- .devcontainer/devcontainer.json | 32 ++---------------------- .devcontainer/launch.json | 29 ++++++++++++++++++++++ scripts/dev_setup.sh | 43 ++++++++++++++++++++++++--------- 4 files changed, 67 insertions(+), 45 deletions(-) create mode 100644 .devcontainer/launch.json diff --git a/.devcontainer/Dockerfile b/.devcontainer/Dockerfile index e22da202..45da7dda 100644 --- a/.devcontainer/Dockerfile +++ b/.devcontainer/Dockerfile @@ -10,9 +10,9 @@ WORKDIR /workspace # --- Python Server App Dependencies --- # Create Python virtual environment -RUN python3 -m venv .venv +RUN python3 -m venv /opt/venv # Add venv to PATH for subsequent RUN commands and for the container environment -ENV PATH="/workspace/.venv/bin:${PATH}" +ENV PATH="/opt/venv/bin:${PATH}" # Copy files required for Python dependency installation. COPY pyproject.toml README.md ./ @@ -30,11 +30,11 @@ 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/yarn.lock ./src/interface/web/ +COPY src/interface/web/package.json src/interface/web/yarn.lock /tmp/web/ # Install web app dependencies # note: yarn will be available from the "features" in devcontainer.json -RUN yarn install --cwd ./src/interface/web +RUN yarn install --cwd /tmp/web --cache-folder /opt/yarn-cache # 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, diff --git a/.devcontainer/devcontainer.json b/.devcontainer/devcontainer.json index 8b3cc2de..fa1cd1e3 100644 --- a/.devcontainer/devcontainer.json +++ b/.devcontainer/devcontainer.json @@ -29,7 +29,7 @@ "unifiedjs.vscode-mdx" ], "settings": { - "python.defaultInterpreterPath": "/workspace/.venv/bin/python", + "python.defaultInterpreterPath": "/opt/venv/bin/python", "python.formatting.provider": "black", "python.linting.enabled": true, "python.linting.mypyEnabled": true, @@ -47,38 +47,10 @@ ], "python.testing.unittestEnabled": false, "python.testing.pytestEnabled": true, - "launch": { - "configurations": [ - { - "name": "Launch Khoj", - "type": "debugpy", - "request": "launch", - "module": "src.khoj.main", - "console": "integratedTerminal", - "justMyCode": false, - "sudo": true, - "args": [ - "-v", - "--anonymous-mode", - "--non-interactive", - "--port=42110" - ], - "envFile": "${workspaceFolder}/.env", - "env": { - "KHOJ_ADMIN_EMAIL": "admin", - "KHOJ_ADMIN_PASSWORD": "admin", - "USE_EMBEDDED_DB": "true", - "KHOJ_DEBUG": "true", - "KHOJ_TELEMETRY_DISABLED": "true", - "PROMPTRACE_DIR": "${workspaceFolder}/promptrace" - } - } - ] - } } } }, - "postCreateCommand": "scripts/dev_setup.sh", + "postCreateCommand": "scripts/dev_setup.sh --devcontainer", "features": { "ghcr.io/devcontainers/features/github-cli:1": {}, "ghcr.io/devcontainers/features/node:1": { diff --git a/.devcontainer/launch.json b/.devcontainer/launch.json new file mode 100644 index 00000000..1bdf1aea --- /dev/null +++ b/.devcontainer/launch.json @@ -0,0 +1,29 @@ +{ + "version": "0.2.0", + "configurations": [ + { + "name": "Launch Khoj", + "type": "debugpy", + "request": "launch", + "module": "src.khoj.main", + "console": "integratedTerminal", + "justMyCode": false, + "sudo": true, + "args": [ + "-v", + "--anonymous-mode", + "--non-interactive", + "--port=42110" + ], + "envFile": "${workspaceFolder}/.env", + "env": { + "KHOJ_ADMIN_EMAIL": "admin", + "KHOJ_ADMIN_PASSWORD": "admin", + "USE_EMBEDDED_DB": "true", + "KHOJ_DEBUG": "true", + "KHOJ_TELEMETRY_DISABLED": "true", + "PROMPTRACE_DIR": "${workspaceFolder}/promptrace" + } + } + ] +} diff --git a/scripts/dev_setup.sh b/scripts/dev_setup.sh index 71a2db6e..9a9afe03 100755 --- a/scripts/dev_setup.sh +++ b/scripts/dev_setup.sh @@ -4,26 +4,47 @@ PROJECT_ROOT=$(git rev-parse --show-toplevel) # Default to minimal installation unless --full flag passed INSTALL_FULL=false +DEVCONTAINER=false for arg in "$@" do if [ "$arg" == "--full" ] then INSTALL_FULL=true fi + if [ "$arg" == "--devcontainer" ] + then + DEVCONTAINER=true + fi done -# Install Server App -# --- -echo "Installing Server App..." -cd $PROJECT_ROOT -# pip install --user pipenv && pipenv install -e '.[dev]' --skip-lock && pipenv shell -python3 -m venv .venv && . .venv/bin/activate && python3 -m pip install -e '.[dev]' +if [ "$DEVCONTAINER" = true ]; then + echo "Dev container setup - using pre-installed dependencies..." + cd "$PROJECT_ROOT" -# Install Web App -# --- -echo "Installing Web App..." -cd $PROJECT_ROOT/src/interface/web -yarn install && yarn export + # Use devcontainer launch.json + mkdir -p .vscode && cp .devcontainer/launch.json .vscode/launch.json + + # Activate the pre-installed venv (no need to create new one) + echo "Using Python environment at /opt/venv" + # PATH should already include /opt/venv/bin from Dockerfile + + # Install khoj in editable mode (dependencies already installed) + python3 -m pip install -e '.[dev]' + + # Install Web App using cached dependencies + echo "Installing Web App using cached dependencies..." + cd "$PROJECT_ROOT/src/interface/web" + yarn install --cache-folder /opt/yarn-cache && yarn export +else + # Standard setup + echo "Installing Server App..." + cd "$PROJECT_ROOT" + python3 -m venv .venv && . .venv/bin/activate && python3 -m pip install -e '.[dev]' + + echo "Installing Web App..." + cd "$PROJECT_ROOT/src/interface/web" + yarn install && yarn export +fi # Install Obsidian App # ---