image: node:lts-alpine

services:
  - postgres:latest

variables:
  DB_NAME: $POSTGRES_DB
  DB_USER: $POSTGRES_USER
  DB_HOST: postgres
  DB_DRIVER: postgres
  DB_PASSWORD: $POSTGRES_PASSWORD
  TEST_DB_NAME: test
  POSTGRES_DB: $POSTGRES_DB
  POSTGRES_USER: $POSTGRES_USER
  POSTGRES_PASSWORD: $POSTGRES_PASSWORD
  POSTGRES_HOST_AUTH_METHOD: trust
  SKIP_PREFLIGHT_CHECK: "true"
  INITIAL_COORDINATOR_EMAIL: "initial@fahrtenbuch.example"
  INITIAL_COORDINATOR_PASSWORD: "password"
  JWT_SECRET: "RANDOM_SECRET_HARD_TO_GUESS"


# These folders and files are cached between builds
cache:
  paths:
    - client/node_modules/
    - server/node_modules/
    - server/.env
    - server/dist/

# Stages for better overview
stages:
  - prepare
  - build
  - test

mirror_dockerfile_server:
  stage: prepare
  script:
    - cd server && npm install

mirror_dockerfile_client:
  stage: prepare
  script:
    - cd client && npm install

build_server:
  stage: build
  script:
    - cd server && npm run build

test_server:
  stage: test
  # I only run the server, since server tests are (almost) always against the API
  before_script:
    - cd server && npm run start &
  script:
    - cd server && npm run test

test_client:
  stage: test
  # If specific content needs to be tested, both the server and client need to be up and running
  before_script:
    - cd client && npm start &
    - cd server && npm start &
  script:
    - cd client && npm run test
    