Skip to content

Commit 8b33e31

Browse files
authored
feat: add devcontainer setup (freeCodeCamp#61695)
1 parent 58fed4a commit 8b33e31

File tree

2 files changed

+39
-0
lines changed

2 files changed

+39
-0
lines changed

.devcontainer/devcontainer.json

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
{
2+
"name": "freeCodeCampDC",
3+
"dockerComposeFile": "docker-compose.yml",
4+
"service": "devcontainer",
5+
"workspaceFolder": "/workspaces/${localWorkspaceFolderBasename}",
6+
// "features": {},
7+
"forwardPorts": [3000, 8000]
8+
}

.devcontainer/docker-compose.yml

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
services:
2+
devcontainer:
3+
depends_on:
4+
- mongo-db
5+
- mongo-setup
6+
image: mcr.microsoft.com/devcontainers/typescript-node:22
7+
volumes:
8+
- ../..:/workspaces:cached
9+
network_mode: service:mongo-db
10+
command: sleep infinity
11+
12+
mongo-db:
13+
image: mongo
14+
command: mongod --replSet rs0
15+
restart: unless-stopped
16+
volumes:
17+
- mongodb-data:/data/db
18+
mongo-setup:
19+
image: mongo
20+
depends_on:
21+
- mongo-db
22+
restart: on-failure
23+
entrypoint: [
24+
'bash',
25+
'-c',
26+
# This will try to initiate the replica set, until it succeeds twice (i.e. until the replica set is already initialized)
27+
'mongosh --host mongo-db:27017 --eval ''try {rs.initiate();} catch (err) { if(err.codeName !== "AlreadyInitialized") throw err };'''
28+
]
29+
30+
volumes:
31+
mongodb-data:

0 commit comments

Comments
 (0)