diff --git a/.gitignore b/.gitignore index dc16015..0dc5d42 100644 --- a/.gitignore +++ b/.gitignore @@ -8,3 +8,4 @@ gradesa/playwright-report/* playwright-report screenshots secrets.yaml +.vscode diff --git a/README.md b/README.md index ae3f441..a21d218 100644 --- a/README.md +++ b/README.md @@ -4,15 +4,6 @@ GRADESA is a freely accessible website where language learners at language centr ## 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): - `brew install docker` + `brew install colima` (https://github.com/abiosoft/colima) @@ -22,29 +13,14 @@ This should be all that's needed: - Turn on the WSL 2 feature during installation - Ensure **Use the WSL 2 based engine** is enabled in General Settings -- psql: `brew install postgresql@15` - ## Running locally -- Run PostgreSQL: - - - 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 - - `cd ./gradesa && npm install` - - `npm run dev` — Starts the dev server. - - You can now find the NextJS app on localhost:3000 +- `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. +- `npm install` in project root +- `npm run db:migrate` +- `cd ./gradesa && npm install` +- `npm run dev` — Starts the dev server. +- You can now find the NextJS app on localhost:3000 ## OpenShift diff --git a/docker-compose.yml b/docker-compose.yml index 7aad07c..0d1e4f6 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -1,28 +1,21 @@ version: "3.6" services: db: - image: postgres:15 + image: docker.io/library/postgres:15 container_name: gradesa-db environment: POSTGRES_PASSWORD: password volumes: - pg-data:/var/lib/postgresql/data/ - - ./provision_db.sql:/docker-entrypoint-initdb.d/1_provision_db.sql restart: unless-stopped - ports: - - "7742:5432" healthcheck: test: ["CMD", "pg_isready", "-U", "postgres"] interval: 10s retries: 20 - command: > - 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" + command: -p 7742 + pgtestdb: - image: postgres:15 + image: docker.io/library/postgres:15 container_name: gradesa-pgtestdb environment: POSTGRES_PASSWORD: password @@ -35,12 +28,30 @@ services: command: > sh -c "apt update && apt install -y postgresql-15-rum && echo 'trusted = true' >> /usr/share/postgresql/15/extension/rum.control && - /usr/local/bin/docker-entrypoint.sh -c fsync=off -c log_statement=all" - ports: - - "7741:5432" + /usr/local/bin/docker-entrypoint.sh -p 5432 -c fsync=off -c log_statement=all" healthcheck: test: ["CMD", "pg_isready", "-U", "postgres"] interval: 10s 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: pg-data: