image: docker:git

services:
  - docker:dind

variables:
  DOCKER_DRIVER: overlay2
  DOCKER_TLS_CERTDIR: ''

stages:
  - build
  - quality

build-test:
  stage: build
  image: node:14.15.4-alpine
  before_script:
    - apk add git
    - apk add bash
  script:
    - yarn
    - yarn build
  only:
    - dev
    - merge_requests

build:
  image: docker:18.09
  services:
    - docker:18.09-dind
  stage: build
  only:
    - master
    - dev
  script:
    - docker login -u $CI_REGISTRY_USER -p $CI_REGISTRY_PASSWORD $CI_REGISTRY
    - docker build --pull -t "$CI_REGISTRY_IMAGE:$CI_COMMIT_REF_SLUG" --build-arg conf=prod .
    - docker push "$CI_REGISTRY_IMAGE:$CI_COMMIT_REF_SLUG"

sonarqube:
  stage: quality
  only:
    - dev
    - merge_requests
  image: registry.forge.grandlyon.com/apoyen2/sonnar-scanner-gl:master
  before_script:
    - export NODE_PATH=$NODE_PATH:`npm root -g`
    - npm install -g typescript
  script:
    - >
      sonar-scanner
      -Dsonar.projectName="ecolyo-backoffice-front"
      -Dsonar.projectVersion=1.0
      -Dsonar.sourceEncoding=UTF-8
      -Dsonar.projectBaseDir=.
      -Dsonar.host.url=${SONAR_URL}
      -Dsonar.projectKey=${CI_PROJECT_PATH_SLUG}
      -Dsonar.login=${SONAR_TOKEN}
      -Dsonar.cpd.exclusions=tests/**,src/**/*.spec.ts*
      -Dsonar.qualitygate.wait=true

