Skip to content

Commit 16fa6a4

Browse files
authored
Merge pull request #43 from GBSL-Informatik/dev-container
Dev container
2 parents 0b6f52d + 0342dbb commit 16fa6a4

File tree

4 files changed

+153
-0
lines changed

4 files changed

+153
-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: 72 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,72 @@
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+
"ghcr.io/georglauterbach/dev-container-features/cache-vscode-extensions:0": {}
16+
},
17+
// Use 'forwardPorts' to make a list of ports inside the container available locally.
18+
// This can be used to network with other containers or with the host.
19+
"forwardPorts": [3002, 5432],
20+
// Use 'postCreateCommand' to run commands after the container is created.
21+
"postCreateCommand": "yarn install",
22+
// Configure tool-specific properties.
23+
"customizations": {
24+
"vscode": {
25+
"extensions": [
26+
"Prisma.prisma",
27+
"mhutchie.git-graph",
28+
"dbaeumer.vscode-eslint",
29+
"motivesoft.vscode-uuid-generator",
30+
"dbaeumer.vscode-eslint",
31+
"esbenp.prettier-vscode",
32+
"ms-ossdata.vscode-pgsql",
33+
"GitHub.copilot",
34+
"GitHub.vscode-pull-request-github"
35+
],
36+
"settings": {
37+
"pgsql.serverGroups": [
38+
{
39+
"name": "Servers",
40+
"id": "9B1DBC9B-951B-4E3D-AC65-7D4CDE1773A0",
41+
"isDefault": true
42+
}
43+
],
44+
"pgsql.connections": [
45+
{
46+
"id": "30A5E0E0-9901-4311-913B-98F78549DD64",
47+
"groupId": "9B1DBC9B-951B-4E3D-AC65-7D4CDE1773A0",
48+
"authenticationType": "SqlLogin",
49+
"connectTimeout": 15,
50+
"applicationName": "vscode-pgsql",
51+
"clientEncoding": "utf8",
52+
"sslmode": "disable",
53+
"server": "db",
54+
"user": "postgres",
55+
"port": "5432",
56+
"database": "teaching_api",
57+
"password": "postgres",
58+
"savePassword": true,
59+
"profileName": "TeachingAPI",
60+
"copilotAccessMode": "ro",
61+
"expiresOn": 0
62+
}
63+
]
64+
}
65+
}
66+
},
67+
"remoteEnv": {
68+
"DATABASE_URL": "postgresql://postgres:postgres@db:5432/teaching_api?schema=public"
69+
}
70+
// Uncomment to connect as root instead. More info: https://aka.ms/dev-containers-non-root.
71+
// "remoteUser": "root"
72+
}

.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:

README.md

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,29 @@
11
# Teaching Website Backend
22
The backend for our teaching website.
33

4+
## Run the Project with VS Code
5+
6+
The Project is ready to be used with dev containers. You only need a recent version of [Docker](https://www.docker.com/). Then you can reopen the project in a devcontainer (`Ctrl+Shift+P` > `Dev Containers: Reopen in Container`).
7+
8+
Setup your local env - inside the devcontainer **you should not set** `DATABASE_URL` yourself.
9+
10+
```bash
11+
USER_ID="<your uuid>"
12+
USER_EMAIL="<your mail>"
13+
USER_ROLE="ADMIN"
14+
NO_AUTH="true"
15+
```
16+
17+
The `USER_ID` and `USER_EMAIL` are used only for seeding the database and are not strictly needed.
18+
The `USER_ID` is the `ID` attribute from the response of [Graph-Explorer/v1.0/me](https://developer.microsoft.com/en-us/graph/graph-explorer) - you need to log in first...
19+
20+
21+
The Project builds and you can run
22+
1. `yarn run db:migrate && yarn run db:seed` (needed only on the initial startup)
23+
2. `yarn run dev`
24+
25+
And done...
26+
427
## Dev Dependencies
528

629
In order to use `.env` files, the [dotenv-cli](https://www.npmjs.com/package/dotenv-cli) must be installed globally:

0 commit comments

Comments
 (0)