# Official framework image. Look for the different tagged releases at:
# https://hub.docker.com/r/library/node/tags/
image: node:10-stretch

# Only needed when using a docker container to run your tests in.
# Check out: http://docs.gitlab.com/ce/ci/docker/using_docker_images.html#what-is-a-service
services:
  - postgres

variables:
  POSTGRES_DB: sigma_staging
  POSTGRES_USER: sigma
  POSTGRES_PASSWORD: "sigmapw"

# This folder is cached between builds
cache:
  paths:
  - node_modules/

stages:
  - build
  - tests

### Jobs ###

# Install dependencies, compile the bundle.js,
build:transpile:
  stage: build
  script:
    - npm ci 
    - npm run build
  artifacts:
    paths:
      - build/

tests:mocha:
  stage: tests
  script:
    - npm ci && npm i -g knex
    # set up to use ldap, not ldaps
    - export LDAP_URI=ldap://ldapdev.eleves.polytechnique.fr:389
    - export LDAP_DN=uid=sigma,ou=services,dc=frankiz,dc=net
    - export TARGET_ENV=staging
    # in Kubernetes executor, hostname postgres is broken
    - export DB_HOST=127.0.0.1
    - cd db
    - knex migrate:latest --env staging
    - knex seed:run --env staging
    - cd ..
    - npm run test