Skip to content

Commit 90c89e9

Browse files
fix DOOD config
1 parent 06e5b8d commit 90c89e9

File tree

3 files changed

+20
-34
lines changed

3 files changed

+20
-34
lines changed

.devcontainer/devcontainer.json

Lines changed: 8 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,27 +1,24 @@
11
{
22
"name": "FastAPI Jinja2 Postgres WebApp",
3+
"image": "mcr.microsoft.com/devcontainers/python:3.13-bookworm",
34
"workspaceFolder": "/workspaces/${localWorkspaceFolderBasename}",
45

5-
// Ensure .env exists before Docker Compose processes env_file entries
6-
"initializeCommand": "bash \"${localWorkspaceFolder}/.devcontainer/ensure-env.sh\"",
6+
"features": {
7+
"ghcr.io/devcontainers/features/docker-outside-of-docker:1": {}
8+
},
79

8-
// Start the Postgres sidecar using the existing compose file
9-
"dockerComposeFile": [
10-
"../docker-compose.yml",
11-
"docker-compose.yml"
10+
"runArgs": [
11+
"--add-host=host.docker.internal:host-gateway"
1212
],
13-
"service": "app",
14-
"runServices": ["db"],
15-
"shutdownAction": "stopCompose",
1613

17-
// Forward common app/db ports
1814
"forwardPorts": [8000, 5432],
1915
"portsAttributes": {
2016
"8000": { "label": "FastAPI", "onAutoForward": "openBrowser" },
2117
"5432": { "label": "PostgreSQL" }
2218
},
2319

24-
// Prepare env, install uv, and sync deps
20+
"initializeCommand": "bash \"${localWorkspaceFolder}/.devcontainer/ensure-env.sh\"",
21+
"postStartCommand": "docker compose -f .devcontainer/docker-compose.yml up -d",
2522
"postCreateCommand": "bash .devcontainer/init-env.sh && curl -LsSf https://astral.sh/uv/install.sh | sh && ~/.local/bin/uv sync",
2623

2724
"customizations": {
@@ -33,4 +30,3 @@
3330
}
3431
}
3532
}
36-

.devcontainer/docker-compose.yml

Lines changed: 8 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,25 +1,15 @@
11
services:
2-
app:
3-
image: mcr.microsoft.com/devcontainers/python:3.13-bookworm
4-
container_name: fastapi-jinja2-postgres-webapp-app
5-
volumes:
6-
- ..:/workspaces/${localWorkspaceFolderBasename}:cached
7-
working_dir: /workspaces/${localWorkspaceFolderBasename}
8-
depends_on:
9-
- db
10-
command: sleep infinity
11-
12-
# Override/augment settings for the db service defined in the root compose file
132
db:
14-
# Avoid requiring a project-level .env during compose evaluation
15-
env_file: []
3+
image: postgres:16
4+
restart: unless-stopped
5+
ports:
6+
- "5432:5432"
167
environment:
178
POSTGRES_USER: ${DB_USER:-postgres}
189
POSTGRES_PASSWORD: ${DB_PASSWORD:-postgres}
1910
POSTGRES_DB: ${DB_NAME:-fastapi-jinja2-postgres-webapp}
20-
ports:
21-
- "5432:5432"
22-
23-
# Note: The 'db' service is defined in the repository root docker-compose.yml.
24-
# This file is merged with that one via devcontainer.json dockerComposeFile array.
11+
volumes:
12+
- pgdata:/var/lib/postgresql/data
2513

14+
volumes:
15+
pgdata:

.devcontainer/init-env.sh

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -13,11 +13,11 @@ if [ ! -f ".env" ]; then
1313
fi
1414
fi
1515

16-
# Ensure DB_HOST points to the compose service name for in-container access
16+
# Ensure DB_HOST points to host.docker.internal for DooD sibling container access
1717
if grep -q '^DB_HOST=' .env; then
18-
sed -i 's/^DB_HOST=.*/DB_HOST=db/' .env
18+
sed -i 's/^DB_HOST=.*/DB_HOST=host.docker.internal/' .env
1919
else
20-
echo 'DB_HOST=db' >> .env
20+
echo 'DB_HOST=host.docker.internal' >> .env
2121
fi
2222

2323
generate_secret() {
@@ -42,5 +42,5 @@ else
4242
echo "SECRET_KEY=$(generate_secret)" >> .env
4343
fi
4444

45-
echo "Environment prepared. DB_HOST set to 'db' and SECRET_KEY ensured."
45+
echo "Environment prepared. DB_HOST set to 'host.docker.internal' and SECRET_KEY ensured."
4646

0 commit comments

Comments
 (0)