-
Notifications
You must be signed in to change notification settings - Fork 94
feat: 优化开发容器配置和开发环境 #57
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from 5 commits
665dbf0
e24a8cf
fc548f3
10c6f42
e33e1b2
af69a13
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||
|---|---|---|---|---|---|---|
| @@ -1,6 +1,14 @@ | ||||||
| { | ||||||
| "name": "Python & Typescript", | ||||||
| "image": "ghcr.io/prulloac/base:bookworm", | ||||||
| "name": "Code Review GPT (Dev Environment)", | ||||||
|
|
||||||
| // 👇 使用 Docker Compose 方式支持多服务 | ||||||
| "dockerComposeFile": "docker-compose.yml", | ||||||
|
|
||||||
| // 👇 指定主开发容器服务 | ||||||
| "service": "app", | ||||||
|
|
||||||
| // 👇 工作目录 | ||||||
| "workspaceFolder": "/workspaces", | ||||||
|
|
||||||
| // 👇 Features to add to the Dev Container. More info: https://containers.dev/implementors/features. | ||||||
| "features": { | ||||||
|
|
@@ -12,14 +20,56 @@ | |||||
| }, | ||||||
|
|
||||||
| // 👇 Commands to run when the container is created. | ||||||
| "postCreateCommand": "curl -LsSf https://astral.sh/uv/install.sh | sh" | ||||||
| "postCreateCommand": "curl -LsSf https://astral.sh/uv/install.sh | sh && cd /workspaces/backend && uv sync", | ||||||
|
|
||||||
| // 👇 端口转发 - 将服务端口暴露到本地 | ||||||
| "forwardPorts": [8000, 3000, 27017], | ||||||
|
|
||||||
| // 👇 Use 'forwardPorts' to make a list of ports inside the container available locally. | ||||||
| // "forwardPorts": [], | ||||||
| // 👇 端口属性 | ||||||
| "portsAttributes": { | ||||||
| "8000": { | ||||||
| "label": "Django Backend", | ||||||
| "onAutoForward": "notify" | ||||||
| }, | ||||||
| "3000": { | ||||||
| "label": "Vue.js Frontend", | ||||||
| "onAutoForward": "notify" | ||||||
| }, | ||||||
| "27017": { | ||||||
| "label": "MongoDB", | ||||||
| "onAutoForward": "silent" | ||||||
| } | ||||||
| }, | ||||||
|
|
||||||
| // 👇 Configure tool-specific properties. | ||||||
| // "customizations": {}, | ||||||
| "customizations": { | ||||||
| "vscode": { | ||||||
| "extensions": [ | ||||||
| "ms-python.python", | ||||||
| "ms-python.black-formatter", | ||||||
| "ms-python.flake8", | ||||||
| "Vue.volar", | ||||||
| "Vue.vscode-typescript-vue-plugin", | ||||||
| "bradlc.vscode-tailwindcss", | ||||||
| "ms-azuretools.vscode-docker" | ||||||
| ], | ||||||
| "settings": { | ||||||
| "python.defaultInterpreterPath": "/usr/local/bin/python", | ||||||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🧩 Analysis chainVerify Python interpreter path for uv-managed environments. The configured Python interpreter path Once the container is running, verify the correct interpreter path by running: Then update the setting to match the actual interpreter path if needed. Alternatively, leave the setting unset and let VSCode auto-detect from the uv environment. 🏁 Script executed: cd /workspaces/backend && uv run which pythonLength of output: 69 I need to gather information about how I need to examine the actual devcontainer configuration to provide a more informed rewrite. Let me search for the full devcontainer.json file. This command didn't clonethe repository. Let me try with the repo: Length of output: 0 🏁 Script executed: #!/bin/bash
# Examine the devcontainer.json file
cat .devcontainer/devcontainer.json | head -100Length of output: 1986 Now let me search for best practices on configuring uv with VSCode devcontainers. Now I have enough information to provide a definitive rewrite. The review's concern is valid—the hardcoded Update Based on the devcontainer configuration, Change line 57 from: To: 🤖 Prompt for AI Agents |
||||||
| "python.formatting.provider": "black", | ||||||
| "editor.formatOnSave": true | ||||||
| } | ||||||
| } | ||||||
| }, | ||||||
|
|
||||||
| // 👇 挂载卷(如果有需要持久化的数据) | ||||||
| "mounts": [ | ||||||
| "source=${localWorkspaceFolder}/backend,target=/workspaces/backend,type=bind", | ||||||
| "source=${localWorkspaceFolder}/frontend,target=/workspaces/frontend,type=bind" | ||||||
| ], | ||||||
|
|
||||||
| // 👇 生命周期脚本 | ||||||
| "postStartCommand": "cd /workspaces/backend && uv run python manage.py migrate", | ||||||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Reconsider automatic database migrations on startup. Running
Consider making migrations a manual step or at least make it more robust: - "postStartCommand": "cd /workspaces/backend && uv run python manage.py migrate",
+ "postStartCommand": "cd /workspaces/backend && uv run python manage.py migrate --check || echo 'Migrations need to be applied. Run: uv run python manage.py migrate'",Or simply document that developers should run migrations manually when needed. 📝 Committable suggestion
Suggested change
🤖 Prompt for AI Agents |
||||||
|
|
||||||
| // 👇 Uncomment to connect as root instead. More info: https://aka.ms/dev-containers-non-root. | ||||||
| // "remoteUser": "root" | ||||||
| "remoteUser": "vscode" | ||||||
| } | ||||||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,50 @@ | ||
| version: '3.8' | ||
|
|
||
| services: | ||
| # 主开发容器应用 | ||
| app: | ||
| image: ghcr.io/prulloac/base:bookworm | ||
| container_name: dev_code_review_app | ||
| restart: unless-stopped | ||
| command: sleep infinity | ||
| volumes: | ||
| - ..:/workspaces:cached | ||
| - uv_cache:/root/.cache/uv | ||
| working_dir: /workspaces | ||
| networks: | ||
| - dev_network | ||
| environment: | ||
| - MONGODB_HOST=mongodb | ||
| - MONGODB_PORT=27017 | ||
| - MONGODB_USER=admin | ||
| - MONGODB_PASSWORD=password | ||
|
Comment on lines
+17
to
+20
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Use secrets or environment files for MongoDB credentials. Hard-coded credentials ( Consider using a + env_file:
+ - .env
environment:
- MONGODB_HOST=mongodb
- MONGODB_PORT=27017
- - MONGODB_USER=admin
- - MONGODB_PASSWORD=password
+ - MONGODB_USER=${MONGODB_USER}
+ - MONGODB_PASSWORD=${MONGODB_PASSWORD}
- UV_LINK_MODE=copyAnd for the MongoDB service: environment:
- MONGO_INITDB_ROOT_USERNAME: admin
- MONGO_INITDB_ROOT_PASSWORD: password
+ MONGO_INITDB_ROOT_USERNAME: ${MONGODB_USER}
+ MONGO_INITDB_ROOT_PASSWORD: ${MONGODB_PASSWORD}
MONGO_INITDB_DATABASE: code_review_gptThen create a Also applies to: 33-36 🤖 Prompt for AI Agents |
||
| - UV_LINK_MODE=copy | ||
| depends_on: | ||
| - mongodb | ||
| ports: | ||
| - "3000:3000" | ||
| - "8000:8000" | ||
|
|
||
| # MongoDB 服务 | ||
| mongodb: | ||
| image: mongo:6.0 | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🧩 Analysis chainVerify MongoDB version compatibility. MongoDB 6.0 is being used. Ensure this version is compatible with your application requirements and has no known security vulnerabilities. 🌐 Web query: 💡 Result: Latest stable MongoDB (on‑premises): 8.2.1 (current production release). [1][5] Known security issues with MongoDB 6.0 (summary):
If you want, I can list all 6.0 CVEs with affected/patched subversions and upgrade recommendations for your deployment. Upgrade MongoDB from 6.0 — version is EOL and has known security vulnerabilities. MongoDB 6.0 reached End-of-Life on July 31, 2025 and is no longer fully supported. Multiple security vulnerabilities affecting 6.0 were disclosed in 2025, including privilege escalation and denial-of-service issues. Upgrade to the latest 6.0 patch or to 8.2.x, or apply MongoDB's security patches. The latest stable version is MongoDB 8.2.1. 🤖 Prompt for AI Agents |
||
| container_name: dev_code_review_mongodb | ||
| restart: unless-stopped | ||
| environment: | ||
| MONGO_INITDB_ROOT_USERNAME: admin | ||
| MONGO_INITDB_ROOT_PASSWORD: password | ||
| MONGO_INITDB_DATABASE: code_review_gpt | ||
| ports: | ||
| - "27017:27017" | ||
| volumes: | ||
| - mongodb_dev_data:/data/db | ||
| networks: | ||
| - dev_network | ||
|
|
||
| volumes: | ||
| mongodb_dev_data: | ||
| uv_cache: | ||
|
|
||
| networks: | ||
| dev_network: | ||
| driver: bridge | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,31 @@ | ||
| [project] | ||
| name = "code-review-gpt-gitlab" | ||
| version = "1.0.0" | ||
| description = "Code Review GPT GitLab Backend" | ||
| requires-python = ">=3.11" | ||
|
|
||
| dependencies = [ | ||
| "Django==4.1.13", | ||
| "djangorestframework==3.14.0", | ||
| "django-cors-headers==4.3.1", | ||
| "requests==2.31.0", | ||
| "requests-toolbelt==1.0.0", | ||
| "retrying==1.3.4", | ||
| "openai==1.59.7", | ||
| "unionllm==0.1.23", | ||
| "litellm==1.58.2", | ||
| "python-gitlab==3.15.0", | ||
| "python-dateutil==2.8.2", | ||
| "gunicorn==21.2.0", | ||
| "gevent==23.9.1", | ||
| "python-dotenv==1.0.0", | ||
| "psutil==5.9.8", | ||
| ] | ||
|
|
||
| [dependency-groups] | ||
| dev = [ | ||
| "black>=23.0.0", | ||
| "flake8>=6.0.0", | ||
| "pytest>=7.0.0", | ||
| "pytest-django>=4.5.0", | ||
| ] | ||
|
Comment on lines
+1
to
+31
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🧩 Analysis chainVerify dependency versions for security vulnerabilities and latest releases. Several dependencies are pinned to specific versions that may be outdated or have known security vulnerabilities. Given the project involves Django and OpenAI integrations, it's critical to ensure these are secure. Run the following script to check for security advisories and available updates: 🏁 Script executed: #!/bin/bash
# Check for security vulnerabilities in Python dependencies
echo "=== Checking for security advisories ==="
for pkg in "Django" "djangorestframework" "django-cors-headers" "requests" "openai" "python-gitlab" "gunicorn" "gevent"; do
echo "--- $pkg ---"
gh api graphql -f query="
{
securityVulnerabilities(first: 5, ecosystem: PIP, package: \"$pkg\") {
nodes {
advisory {
summary
severity
publishedAt
}
vulnerableVersionRange
firstPatchedVersion {
identifier
}
}
}
}"
done
echo ""
echo "=== Checking latest versions on PyPI ==="
for pkg in "Django" "djangorestframework" "django-cors-headers" "requests" "openai" "litellm" "python-gitlab" "gunicorn"; do
echo -n "$pkg: "
curl -s "https://pypi.org/pypi/$pkg/json" | jq -r '.info.version'
doneLength of output: 4857 Update dependencies to address critical and high-severity security vulnerabilities. Verification found multiple security issues:
Recommended versions: Django ≥4.2.26, Gunicorn ≥22.0.0, requests ≥2.32.5, djangorestframework ≥3.16.1 🤖 Prompt for AI Agents |
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Inefficient uv installation on every container creation.
Installing
uvvia a shell script inpostCreateCommandruns on every container creation, which is inefficient. Theuvtool should be installed once during the Docker image build process.Move the uv installation to the
Dockerfileor a build script so it's baked into the image, then simplify thepostCreateCommand:Ensure your Docker image (referenced by
docker-compose.yml) installsuvduring the build:🤖 Prompt for AI Agents