Skip to content

Commit 699efd5

Browse files
feat: Setup postgres and node devcontainer
1 parent a5de2f5 commit 699efd5

File tree

3 files changed

+98
-23
lines changed

3 files changed

+98
-23
lines changed

.devcontainer/devcontainer.json

Lines changed: 34 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -1,32 +1,43 @@
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
13
{
2-
"name": "crunchloop-nestjs-interview",
4+
"name": "Existing Docker Compose (Extend)",
35

4-
// Or use a Dockerfile or Docker Compose file. More info: https://containers.dev/guide/dockerfile
5-
"image": "mcr.microsoft.com/devcontainers/typescript-node:0-18",
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.yml"
11+
],
612

7-
// Set the workspace folder
8-
"workspaceFolder": "/workspaces/${localWorkspaceFolderBasename}",
13+
// The 'service' property is the name of the service for the container that VS Code should
14+
// use. Update this value and .devcontainer/docker-compose.yml to the real service name.
15+
"service": "app",
916

10-
// Features to add to the dev container. More info: https://containers.dev/features.
11-
"features": {
12-
"ghcr.io/devcontainers-contrib/features/nestjs-cli:2": {}
13-
},
17+
// The optional 'workspaceFolder' property is the path VS Code should open by default when
18+
// connected. This is typically a file mount in .devcontainer/docker-compose.yml
19+
"workspaceFolder": "/workspaces/${localWorkspaceFolderBasename}",
1420

15-
// Use 'forwardPorts' to make a list of ports inside the container available locally.
16-
"forwardPorts": [3000],
21+
// Features to add to the dev container. More info: https://containers.dev/features.
22+
"features": {
23+
"ghcr.io/devcontainers-extra/features/nestjs-cli:2": {}
24+
}
1725

18-
// Use 'postCreateCommand' to run commands after the container is created.
19-
"postCreateCommand": "npm install",
26+
// Use 'forwardPorts' to make a list of ports inside the container available locally.
27+
// "forwardPorts": [],
2028

21-
// Configure tool-specific properties.
22-
"customizations": {
23-
"vscode": {
24-
"extensions": [
25-
"Postman.postman-for-vscode"
26-
]
27-
}
28-
}
29+
// Uncomment the next line if you want start specific services in your Docker Compose config.
30+
// "runServices": [],
2931

30-
// Uncomment to connect as root instead. More info: https://aka.ms/dev-containers-non-root.
31-
// "remoteUser": "root"
32+
// Uncomment the next line if you want to keep your containers running after VS Code shuts down.
33+
// "shutdownAction": "none",
34+
35+
// Uncomment the next line to run commands after the container is created.
36+
// "postCreateCommand": "cat /etc/os-release",
37+
38+
// Configure tool-specific properties.
39+
// "customizations": {},
40+
41+
// Uncomment to connect as an existing user other than the container default. More info: https://aka.ms/dev-containers-non-root.
42+
// "remoteUser": "devcontainer"
3243
}

.devcontainer/docker-compose.yml

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
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+
app:
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:cached
17+
18+
# Uncomment the next four lines if you will use a ptrace-based debugger like C++, Go, and Rust.
19+
# cap_add:
20+
# - SYS_PTRACE
21+
# security_opt:
22+
# - seccomp:unconfined
23+
24+
# Overrides default command so things don't shut down after the process ends.
25+
command: sleep infinity
26+

docker-compose.yml

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
version: '3.8'
2+
services:
3+
app:
4+
image: mcr.microsoft.com/devcontainers/typescript-node:0-18
5+
volumes:
6+
- .:/workspaces/nestjs-interview
7+
ports:
8+
- "3000:3000"
9+
environment:
10+
- DATABASE_HOST=postgres
11+
- DATABASE_PORT=5432
12+
- DATABASE_USER=postgres
13+
- DATABASE_PASSWORD=postgres
14+
- DATABASE_NAME=nestjs_db
15+
depends_on:
16+
- postgres
17+
networks:
18+
- nestjs-network
19+
20+
postgres:
21+
image: postgres:latest
22+
environment:
23+
- POSTGRES_USER=postgres
24+
- POSTGRES_PASSWORD=postgres
25+
- POSTGRES_DB=nestjs_db
26+
ports:
27+
- "5432:5432"
28+
volumes:
29+
- postgres_data:/var/lib/postgresql/data
30+
networks:
31+
- nestjs-network
32+
33+
networks:
34+
nestjs-network:
35+
driver: bridge
36+
37+
volumes:
38+
postgres_data:

0 commit comments

Comments
 (0)