Create dev container environment

This commit is contained in:
Miika Holmlund
2025-11-03 18:26:54 +02:00
parent 4dc54839a0
commit 4397dc1f33
3 changed files with 32 additions and 44 deletions
+1
View File
@@ -8,3 +8,4 @@ gradesa/playwright-report/*
playwright-report playwright-report
screenshots screenshots
secrets.yaml secrets.yaml
.vscode
+2 -26
View File
@@ -4,15 +4,6 @@ GRADESA is a freely accessible website where language learners at language centr
## Install ## Install
This should be all that's needed:
- `node`
- `npm`
- https://github.com/peterldowns/pgmigrate
- MAC: Install the newest version with `brew install peterldowns/tap/pgmigrate`
- Linux: # Install pgmigrate
- `wget https://github.com/peterldowns/pgmigrate/releases/download/v0.0.6%2Bcommit.4f90829/pgmigrate-linux-amd64 -O /usr/local/bin/pgmigrate`
- `chmod +x /usr/local/bin/pgmigrate`
- Docker, either of these installation options work (if you're new to docker, I recommend Docker Desktop): - Docker, either of these installation options work (if you're new to docker, I recommend Docker Desktop):
- `brew install docker` + `brew install colima` (https://github.com/abiosoft/colima) - `brew install docker` + `brew install colima` (https://github.com/abiosoft/colima)
@@ -22,26 +13,11 @@ This should be all that's needed:
- Turn on the WSL 2 feature during installation - Turn on the WSL 2 feature during installation
- Ensure **Use the WSL 2 based engine** is enabled in General Settings - Ensure **Use the WSL 2 based engine** is enabled in General Settings
- psql: `brew install postgresql@15`
## Running locally ## Running locally
- Run PostgreSQL: - `docker-compose up -d` — This command starts the development enviroment which includes two databases (one for development, one for automatic tests) and a development container named node-dev-env. If using VSCode dev-containers extension can be used to attach VSCode to the running container (see dev-containers documentation). It is also possible to run the commands with `docker-exec -it node-dev-env bash`. The codebase is mounted at /host. The next actions should be run inside node-dev-env.
- Init .env files `./init-env.sh` — This will create the required .env files for environment variables. The local db credentials are
- DB_HOST=localhost
- DB_PORT=7742
- DB_USER=ohtu
- DB_PASSWORD=password
- DB_NAME=gradesa
Create session secret key with `openssl rand -base64 32` adding it to .env
- SESSION_SECRET=your_secret_key
- `docker compose up -d` — This command starts the services defined in the docker-compose.yml file in detached mode, meaning the services run in the background and the terminal is freed up for other tasks. For more information, checkout [Docker Compose docs](https://docs.docker.com/compose/)
- `npm install` in project root - `npm install` in project root
- `npm run db:migrate`
- `cd ./gradesa && npm install` - `cd ./gradesa && npm install`
- `npm run dev` — Starts the dev server. - `npm run dev` — Starts the dev server.
- You can now find the NextJS app on localhost:3000 - You can now find the NextJS app on localhost:3000
+25 -14
View File
@@ -1,28 +1,21 @@
version: "3.6" version: "3.6"
services: services:
db: db:
image: postgres:15 image: docker.io/library/postgres:15
container_name: gradesa-db container_name: gradesa-db
environment: environment:
POSTGRES_PASSWORD: password POSTGRES_PASSWORD: password
volumes: volumes:
- pg-data:/var/lib/postgresql/data/ - pg-data:/var/lib/postgresql/data/
- ./provision_db.sql:/docker-entrypoint-initdb.d/1_provision_db.sql
restart: unless-stopped restart: unless-stopped
ports:
- "7742:5432"
healthcheck: healthcheck:
test: ["CMD", "pg_isready", "-U", "postgres"] test: ["CMD", "pg_isready", "-U", "postgres"]
interval: 10s interval: 10s
retries: 20 retries: 20
command: > command: -p 7742
sh -c "apt update &&
apt install -y wget &&
wget https://github.com/peterldowns/pgmigrate/releases/download/v0.0.6%2Bcommit.4f90829/pgmigrate-linux-amd64 -O /usr/local/bin/pgmigrate &&
chmod +x /usr/local/bin/pgmigrate &&
/usr/local/bin/docker-entrypoint.sh postgres"
pgtestdb: pgtestdb:
image: postgres:15 image: docker.io/library/postgres:15
container_name: gradesa-pgtestdb container_name: gradesa-pgtestdb
environment: environment:
POSTGRES_PASSWORD: password POSTGRES_PASSWORD: password
@@ -35,12 +28,30 @@ services:
command: > command: >
sh -c "apt update && apt install -y postgresql-15-rum && sh -c "apt update && apt install -y postgresql-15-rum &&
echo 'trusted = true' >> /usr/share/postgresql/15/extension/rum.control && echo 'trusted = true' >> /usr/share/postgresql/15/extension/rum.control &&
/usr/local/bin/docker-entrypoint.sh -c fsync=off -c log_statement=all" /usr/local/bin/docker-entrypoint.sh -p 5432 -c fsync=off -c log_statement=all"
ports:
- "7741:5432"
healthcheck: healthcheck:
test: ["CMD", "pg_isready", "-U", "postgres"] test: ["CMD", "pg_isready", "-U", "postgres"]
interval: 10s interval: 10s
retries: 20 retries: 20
node-dev-env:
image: docker.io/library/node:20
container_name: node-dev-env
environment:
DB_HOST: gradesa-db
DB_PORT: 7742
DB_USER: postgres
DB_PASSWORD: password
DB_NAME: postgres
SESSION_SECRET: secret
volumes:
- .:/host:Z
ports:
- "3000:3000"
command: >
sh -c "apt install -y wget &&
wget https://github.com/peterldowns/pgmigrate/releases/download/v0.0.6%2Bcommit.4f90829/pgmigrate-linux-amd64 -O /usr/local/bin/pgmigrate &&
chmod +x /usr/local/bin/pgmigrate &&
/usr/local/bin/docker-entrypoint.sh sleep inf"
volumes: volumes:
pg-data: pg-data: