From d754a43fba84736ac2f7af9690853662500b79ce Mon Sep 17 00:00:00 2001 From: Alex Date: Wed, 5 Feb 2025 11:54:06 +0000 Subject: [PATCH] feat: devcontainer --- .devcontainer/Dockerfile | 15 ++++++++ .devcontainer/devcontainer.json | 18 ++++++++++ .devcontainer/docker-compose.override.yaml | 40 ++++++++++++++++++++++ .devcontainer/post-create-command.sh | 14 ++++++++ 4 files changed, 87 insertions(+) create mode 100644 .devcontainer/Dockerfile create mode 100644 .devcontainer/devcontainer.json create mode 100644 .devcontainer/docker-compose.override.yaml create mode 100755 .devcontainer/post-create-command.sh diff --git a/.devcontainer/Dockerfile b/.devcontainer/Dockerfile new file mode 100644 index 00000000..1fa5455d --- /dev/null +++ b/.devcontainer/Dockerfile @@ -0,0 +1,15 @@ +FROM python:3.12-bookworm + +# Install Node.js 20.x +RUN curl -fsSL https://deb.nodesource.com/setup_20.x | bash - \ + && apt-get install -y nodejs \ + && rm -rf /var/lib/apt/lists/* + +# Install global npm packages +RUN npm install -g husky vite + +# Create and activate Python virtual environment +RUN python -m venv /opt/venv +ENV PATH="/opt/venv/bin:$PATH" + +WORKDIR /workspace \ No newline at end of file diff --git a/.devcontainer/devcontainer.json b/.devcontainer/devcontainer.json new file mode 100644 index 00000000..664cf64d --- /dev/null +++ b/.devcontainer/devcontainer.json @@ -0,0 +1,18 @@ +{ + "name": "DocsGPT Dev Container", + "dockerComposeFile": ["../docker-compose-dev.yaml", "docker-compose.override.yaml"], + "service": "dev", + "workspaceFolder": "/workspace", + "postCreateCommand": ".devcontainer/post-create-command.sh", + "forwardPorts": [7091, 5173, 6379, 27017], + "customizations": { + "vscode": { + "extensions": [ + "ms-python.python", + "ms-toolsai.jupyter", + "esbenp.prettier-vscode", + "dbaeumer.vscode-eslint" + ] + } + } + } \ No newline at end of file diff --git a/.devcontainer/docker-compose.override.yaml b/.devcontainer/docker-compose.override.yaml new file mode 100644 index 00000000..11db7289 --- /dev/null +++ b/.devcontainer/docker-compose.override.yaml @@ -0,0 +1,40 @@ +version: '3.8' + +services: + dev: + build: + context: . + dockerfile: .devcontainer/Dockerfile + volumes: + - .:/workspace:cached + command: sleep infinity + depends_on: + redis: + condition: service_healthy + mongo: + condition: service_healthy + environment: + - CELERY_BROKER_URL=redis://redis:6379/0 + - CELERY_RESULT_BACKEND=redis://redis:6379/1 + - MONGO_URI=mongodb://mongo:27017/docsgpt + - CACHE_REDIS_URL=redis://redis:6379/2 + networks: + - default + + redis: + healthcheck: + test: ["CMD", "redis-cli", "ping"] + interval: 5s + timeout: 30s + retries: 5 + + mongo: + healthcheck: + test: ["CMD", "mongosh", "--eval", "db.adminCommand('ping')"] + interval: 5s + timeout: 30s + retries: 5 + +networks: + default: + name: docsgpt-dev-network \ No newline at end of file diff --git a/.devcontainer/post-create-command.sh b/.devcontainer/post-create-command.sh new file mode 100755 index 00000000..93796b49 --- /dev/null +++ b/.devcontainer/post-create-command.sh @@ -0,0 +1,14 @@ +#!/bin/bash + +set -e # Exit immediately if a command exits with a non-zero status + +cp -n .env-template .env || true +mkdir -p model +if [ ! -d model/all-mpnet-base-v2 ]; then + wget -q https://d3dg1063dc54p9.cloudfront.net/models/embeddings/mpnet-base-v2.zip -O model/mpnet-base-v2.zip + unzip -q model/mpnet-base-v2.zip -d model + rm model/mpnet-base-v2.zip +fi +pip install -r application/requirements.txt +cd frontend +npm install --include=dev \ No newline at end of file