Skip to content

Commit 5cade9e

Browse files
authored
Devcontainer full setup (#160)
* Dev container from docker-compose * Working dev container with mailcatcher and db * Reduce down to minimal working * Document dev container usage
1 parent f861003 commit 5cade9e

File tree

4 files changed

+49
-8
lines changed

4 files changed

+49
-8
lines changed

.devcontainer/devcontainer.json

Lines changed: 17 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,25 @@
11
// For format details, see https://aka.ms/devcontainer.json. For config options, see the
22
// README at: https://github.com/devcontainers/templates/tree/main/src/docker-existing-dockerfile
33
{
4-
"name": "Existing Dockerfile",
5-
"build": {
6-
// Sets the run context to one level up instead of the .devcontainer folder.
7-
"context": "..",
8-
"dockerfile": "../Dockerfile",
9-
"target": "dev_container"
10-
},
4+
"name": "members-app",
5+
"dockerComposeFile": "docker-compose.yaml",
6+
"service": "app",
7+
"workspaceFolder": "/workspace",
8+
"shutdownAction": "stopCompose",
9+
// Expose the application + the mailcatcher for checking emails.
10+
"forwardPorts": [8080, 1080],
11+
// Wipes the database on every start.
12+
"postStartCommand": "rm -rf /db && mkdir -p /db",
13+
"customizations": {
14+
"vscode": {
15+
"extensions": [
16+
"dbaeumer.vscode-eslint"
17+
]
18+
}
19+
}
1120

1221
// Features to add to the dev container. More info: https://containers.dev/features.
13-
"features": {}
22+
// "features": {}
1423

1524
// Use 'forwardPorts' to make a list of ports inside the container available locally.
1625
// "forwardPorts": [],

.devcontainer/docker-compose.yaml

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
services:
2+
app:
3+
build:
4+
context: ../
5+
target: dev_container
6+
dockerfile: Dockerfile
7+
env_file: "../.env"
8+
volumes:
9+
- ../:/workspace:cached
10+
command: sleep infinity
11+
network_mode: service:mailcatcher
12+
13+
mailcatcher:
14+
image: sj26/mailcatcher@sha256:238a915586b99dd957fed9dfc27fa36518e038b9d43368fbaf2e384968b6e36f

Makefile

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,3 +64,9 @@ release:
6464

6565
login-%:
6666
./scripts/login.ts $*
67+
68+
# For use with devcontainer
69+
start:
70+
npx tsx watch ./src/index.ts &
71+
npx tsx watch ./src/sync-worker/index.ts
72+

README.md

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -157,3 +157,15 @@ Not verified
157157

158158
## Fly.io
159159
- Deployment URL [makespace-app.fly.dev](https://makespace-app.fly.dev/)
160+
161+
# DevContainer
162+
Dev containers are a way to create a reproducible dev environment https://code.visualstudio.com/docs/devcontainers/containers.
163+
164+
Setup (vscode):
165+
1. Install the dev container extension from Microsoft
166+
2. Ctrl+Shift+P then type 'Dev Containers: Rebuild and Reopen in Container'
167+
3. Vscode will reload into the dev container - you can now develop with all the required tools already installed
168+
4. Type `make start` to start the application to perform manual local testing.
169+
170+
Each time you start the dev container the database will be reset to empty.
171+

0 commit comments

Comments
 (0)