Skip to content

Commit 4bff042

Browse files
committed
🚀 Add Dev Container support
1 parent 632f1ac commit 4bff042

File tree

5 files changed

+124
-0
lines changed

5 files changed

+124
-0
lines changed

.devcontainer/devcontainer.json

Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
// For format details, see https://aka.ms/devcontainer.json. For config options, see the
2+
// README at: https://github.com/devcontainers/templates/tree/main/src/docker-existing-docker-compose
3+
{
4+
"name": "full-stack-fastapi-template devcontainer",
5+
6+
// Update the 'dockerComposeFile' list if you have more compose files or use different names.
7+
// The .devcontainer/docker-compose.yml file contains any overrides you need/want to make.
8+
"dockerComposeFile": [
9+
"../docker-compose.yml",
10+
"../docker-compose.override.yml",
11+
"docker-compose.yml"
12+
],
13+
14+
// The 'service' property is the name of the service for the container that VS Code should
15+
// use. Update this value and .devcontainer/docker-compose.yml to the real service name.
16+
"service": "backend",
17+
18+
// The optional 'workspaceFolder' property is the path VS Code should open by default when
19+
// connected. This is typically a file mount in .devcontainer/docker-compose.yml
20+
"workspaceFolder": "/workspaces",
21+
22+
// Features to add to the dev container. More info: https://containers.dev/features.
23+
"features": {
24+
"ghcr.io/devcontainers/features/common-utils:2":{
25+
"installZsh": "true",
26+
"installOhMyZsh": "true",
27+
"upgradePackages": "true"
28+
},
29+
// node
30+
// host both backend and frontend in the same container
31+
"ghcr.io/devcontainers/features/node:1": {
32+
"version": "24"
33+
}
34+
},
35+
36+
// Use 'forwardPorts' to make a list of ports inside the container available locally.
37+
// "forwardPorts": [],
38+
39+
// Uncomment the next line if you want start specific services in your Docker Compose config.
40+
"runServices": ["db", "prestart", "backend"],
41+
42+
// Uncomment the next line if you want to keep your containers running after VS Code shuts down.
43+
// "shutdownAction": "none",
44+
45+
// Uncomment the next line to run commands after the container is created.
46+
// "postCreateCommand": "cat /etc/os-release",
47+
48+
// Configure tool-specific properties.
49+
// "customizations": {},
50+
51+
// Uncomment to connect as an existing user other than the container default. More info: https://aka.ms/dev-containers-non-root.
52+
// "remoteUser": "devcontainer"
53+
54+
"remoteEnv": {
55+
"VITE_API_URL": "http://localhost:8000"
56+
}
57+
}

.devcontainer/docker-compose.yml

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
version: '3.8'
2+
services:
3+
# Update this to the name of the service you want to work with in your docker-compose.yml file
4+
backend:
5+
# Uncomment if you want to override the service's Dockerfile to one in the .devcontainer
6+
# folder. Note that the path of the Dockerfile and context is relative to the *primary*
7+
# docker-compose.yml file (the first in the devcontainer.json "dockerComposeFile"
8+
# array). The sample below assumes your primary file is in the root of your project.
9+
#
10+
# build:
11+
# context: .
12+
# dockerfile: .devcontainer/Dockerfile
13+
14+
volumes:
15+
# Update this to wherever you want VS Code to mount the folder of your project
16+
- .:/workspaces
17+
18+
ports:
19+
- 5173:5173
20+
21+
# Uncomment the next four lines if you will use a ptrace-based debugger like C++, Go, and Rust.
22+
# cap_add:
23+
# - SYS_PTRACE
24+
# security_opt:
25+
# - seccomp:unconfined
26+
27+
# Overrides default command so things don't shut down after the process ends.
28+
command: sleep infinity
29+
30+
mailcatcher:
31+
hostname: ${STACK_NAME}-mailcatcher

backend/Makefile

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
SHELL := /bin/bash
2+
3+
.PHONY: dev
4+
dev:
5+
uv sync
6+
uv run fastapi dev app/main.py --host 0.0.0.0 --reload

development.md

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,31 @@ To check the logs of a specific service, add the name of the service, e.g.:
3434
docker compose logs backend
3535
```
3636

37+
## Dev Container Development
38+
39+
Run `Dev Containers: Rebuild Container` command to build and open the workspace in the dev container.
40+
41+
> [!IMPORTANT]
42+
> As Dev Container does not support a part of its features in a multi-devcontainer environment, use the backend container for both backend and frontend servers.
43+
44+
To start the server for the frontend, run:
45+
```bash
46+
cd frontend
47+
make dev
48+
# or use commands:
49+
# npm install
50+
# npm run dev --loglevel silly -- --host 0.0.0.0
51+
```
52+
53+
To start the server for the backend, run:
54+
```bash
55+
cd backend
56+
make dev
57+
# or use commands:
58+
# uv sync
59+
# uv run fastapi dev app/main.py --host 0.0.0.0 --reload
60+
```
61+
3762
## Local Development
3863

3964
The Docker Compose files are configured so that each of the services is available in a different port in `localhost`.

frontend/Makefile

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
SHELL := /bin/bash
2+
3+
.PHONY: dev
4+
dev:
5+
npm install && npm run dev --loglevel silly -- --host 0.0.0.0

0 commit comments

Comments
 (0)