image: node:lts

stages:
  - test
  - build

audit:
  stage: test
  script:
    - cd src/server
    - npm audit
  allow_failure: true
  only:
    - merge_requests
    - master

lint-server:
  stage: test
  script:
    - npm install eslint@7.32.0 eslint-plugin-prettier prettier babel-eslint eslint-plugin-requirejs
    - cd src/server
    - ../../node_modules/.bin/eslint . 
  only:
    - merge_requests
    - master

lint-client:
  stage: test
  script:
    - npm install eslint@7.32.0 eslint-plugin-prettier prettier babel-eslint eslint-plugin-requirejs
    - cd src/client
    - ../../node_modules/.bin/eslint .
  only:
    - merge_requests
    - master

build-image-latest:
  stage: build
  image: docker:stable
  services:
    - docker:dind
  before_script:
    # - docker login -u gitlab-ci-token -p $CI_JOB_TOKEN $CI_REGISTRY
    - docker login -u $DOCKERHUB_USERNAME -p $DOCKERHUB_TOKEN
  variables:
    #IMAGE_TAG_REF: $CI_REGISTRY_IMAGE:$CI_COMMIT_REF_SLUG
    #IMAGE_TAG_ALIAS: $CI_REGISTRY_IMAGE:latest
    IMAGE_TAG_REF: isleward/isleward:$CI_COMMIT_REF_SLUG
    IMAGE_TAG_ALIAS: isleward/isleward:latest
  script:
    - docker build -t $IMAGE_TAG_REF -t $IMAGE_TAG_ALIAS .
    - docker push $IMAGE_TAG_REF
    - docker push $IMAGE_TAG_ALIAS
  only:
    - master

build-image-stable:
  stage: build
  image: docker:stable
  services:
    - docker:dind
  before_script:
    # - docker login -u gitlab-ci-token -p $CI_JOB_TOKEN $CI_REGISTRY
    - docker login -u $DOCKERHUB_USERNAME -p $DOCKERHUB_TOKEN
  variables:
    #IMAGE_TAG_REF: $CI_REGISTRY_IMAGE:$CI_COMMIT_REF_SLUG
    #IMAGE_TAG_ALIAS: $CI_REGISTRY_IMAGE:stable
    IMAGE_TAG_REF: isleward/isleward:$CI_COMMIT_REF_SLUG
    IMAGE_TAG_ALIAS: isleward/isleward:stable
  script:
    - docker build -t $IMAGE_TAG_REF -t $IMAGE_TAG_ALIAS .
    - docker push $IMAGE_TAG_REF
    - docker push $IMAGE_TAG_ALIAS
  only:
    - tags
