Skip to content

Commit 5dd6b8c

Browse files
authored
Add Docker Compose + Postgres to devcontainer for Codespaces support (#324)
1 parent 1d0ab2e commit 5dd6b8c

2 files changed

Lines changed: 50 additions & 9 deletions

File tree

.devcontainer/devcontainer.json

Lines changed: 18 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -2,21 +2,30 @@
22
// README at: https://github.com/devcontainers/templates/tree/main/src/typescript-node
33
{
44
"name": "GitHub Copilot Metrics Viewer Dev Environment",
5-
// Or use a Dockerfile or Docker Compose file. More info: https://containers.dev/guide/dockerfile
6-
"image": "mcr.microsoft.com/devcontainers/typescript-node:1-22-bookworm",
5+
"dockerComposeFile": "docker-compose.yml",
6+
"service": "app",
7+
"workspaceFolder": "/workspaces/copilot-metrics-viewer",
78
"features": {
89
"ghcr.io/devcontainers/features/azure-cli:1": {},
910
"ghcr.io/devcontainers/features/github-cli:1": {}
1011
},
1112

12-
// Features to add to the dev container. More info: https://containers.dev/features.
13-
// "features": {},
14-
15-
// Use 'forwardPorts' to make a list of ports inside the container available locally.
16-
// "forwardPorts": [],
13+
// Forward ports for the app and PostgreSQL.
14+
"forwardPorts": [3000, 5432],
15+
"portsAttributes": {
16+
"3000": {
17+
"label": "App (Nuxt)",
18+
"onAutoForward": "notify"
19+
},
20+
"5432": {
21+
"label": "PostgreSQL",
22+
"onAutoForward": "silent"
23+
}
24+
},
1725

18-
// Use 'postCreateCommand' to run commands after the container is created.
19-
"postCreateCommand": "npm install && npm run serve"
26+
// Install dependencies on container creation. The database schema is initialized
27+
// automatically on first app startup via initSchema() in server/storage/db.ts.
28+
"postCreateCommand": "npm install",
2029

2130
// Configure tool-specific properties.
2231
// "customizations": {},

.devcontainer/docker-compose.yml

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
services:
2+
app:
3+
image: mcr.microsoft.com/devcontainers/typescript-node:1-22-bookworm
4+
volumes:
5+
- ..:/workspaces/copilot-metrics-viewer:cached
6+
environment:
7+
- DATABASE_URL=postgresql://metrics_user:metrics_password@db:5432/copilot_metrics
8+
command: sleep infinity
9+
depends_on:
10+
db:
11+
condition: service_healthy
12+
13+
db:
14+
image: postgres:15-alpine
15+
restart: unless-stopped
16+
# Development-only credentials — not suitable for production use.
17+
environment:
18+
POSTGRES_DB: copilot_metrics
19+
POSTGRES_USER: metrics_user
20+
POSTGRES_PASSWORD: metrics_password
21+
ports:
22+
- "5432:5432"
23+
volumes:
24+
- postgres_data:/var/lib/postgresql/data
25+
healthcheck:
26+
test: ["CMD-SHELL", "pg_isready -U metrics_user -d copilot_metrics"]
27+
interval: 5s
28+
timeout: 3s
29+
retries: 5
30+
31+
volumes:
32+
postgres_data:

0 commit comments

Comments
 (0)