Skip to content

Commit f0303a5

Browse files
committed
add devcontainer setup
1 parent 0b6f52d commit f0303a5

File tree

3 files changed

+97
-0
lines changed

3 files changed

+97
-0
lines changed

.devcontainer/Dockerfile

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
FROM mcr.microsoft.com/devcontainers/typescript-node:1-22-bookworm
2+
3+
# [Optional] Uncomment this section to install additional OS packages.
4+
# RUN apt-get update && export DEBIAN_FRONTEND=noninteractive \
5+
# && apt-get -y install --no-install-recommends <your-package-list-here>
6+
7+
# [Optional] Uncomment if you want to install an additional version of node using nvm
8+
# ARG EXTRA_NODE_VERSION=10
9+
# RUN su node -c "source /usr/local/share/nvm/nvm.sh && nvm install ${EXTRA_NODE_VERSION}"
10+
11+
# [Optional] Uncomment if you want to install more global node modules
12+
# RUN su node -c "npm install -g <your-package-list-here>"

.devcontainer/devcontainer.json

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
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/javascript-node-postgres
3+
{
4+
"name": "Teaching-API",
5+
"dockerComposeFile": "docker-compose.yml",
6+
"service": "app",
7+
"workspaceFolder": "/workspaces/${localWorkspaceFolderBasename}",
8+
// Features to add to the dev container. More info: https://containers.dev/features.
9+
"features": {
10+
"ghcr.io/devcontainers/features/github-cli:1": {},
11+
"ghcr.io/rails/devcontainer/features/postgres-client": {
12+
"version": "17"
13+
},
14+
"ghcr.io/code-fabrik/features/dokku-cli:latest": {}
15+
},
16+
// Use 'forwardPorts' to make a list of ports inside the container available locally.
17+
// This can be used to network with other containers or with the host.
18+
"forwardPorts": [3002, 5432],
19+
// Use 'postCreateCommand' to run commands after the container is created.
20+
"postCreateCommand": "yarn install",
21+
// Configure tool-specific properties.
22+
"customizations": {
23+
"vscode": {
24+
"extensions": [
25+
"Prisma.prisma",
26+
"mhutchie.git-graph",
27+
"dbaeumer.vscode-eslint",
28+
"motivesoft.vscode-uuid-generator",
29+
"dbaeumer.vscode-eslint",
30+
"esbenp.prettier-vscode"
31+
]
32+
}
33+
},
34+
"remoteEnv": {
35+
"DATABASE_URL": "postgresql://postgres:postgres@db:5432/teaching_api?schema=public"
36+
}
37+
// Uncomment to connect as root instead. More info: https://aka.ms/dev-containers-non-root.
38+
// "remoteUser": "root"
39+
}

.devcontainer/docker-compose.yml

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
version: '3.8'
2+
3+
services:
4+
app:
5+
build:
6+
context: ..
7+
dockerfile: .devcontainer/Dockerfile
8+
9+
volumes:
10+
- ../..:/workspaces:cached
11+
12+
# Overrides default command so things don't shut down after the process ends.
13+
command: sleep infinity
14+
15+
environment:
16+
- NODE_ENV=development
17+
- DATABASE_URL=postgresql://postgres:postgres@db:5432/teaching_api?schema=public
18+
- PORT=3002
19+
20+
# Runs app on the same network as the database container, allows "forwardPorts" in devcontainer.json function.
21+
network_mode: service:db
22+
23+
depends_on:
24+
- db
25+
26+
# Use "forwardPorts" in **devcontainer.json** to forward an app port locally.
27+
# (Adding the "ports" property to this file will not forward from a Codespace.)
28+
29+
db:
30+
image: postgres:17.2
31+
restart: unless-stopped
32+
volumes:
33+
- postgres-data:/var/lib/postgresql/data
34+
environment:
35+
POSTGRES_PASSWORD: postgres
36+
POSTGRES_USER: postgres
37+
POSTGRES_DB: teaching_api
38+
ports:
39+
- "3002:3002"
40+
- "5432:5432"
41+
42+
# Add "forwardPorts": ["5432"] to **devcontainer.json** to forward PostgreSQL locally.
43+
# (Adding the "ports" property to this file will not forward from a Codespace.)
44+
45+
volumes:
46+
postgres-data:

0 commit comments

Comments
 (0)