default:
  image: node:latest

variables:
  GIT_STRATEGY: clone  # Solve git fetch problem in gitlab-ci.yml
  NPM_CONFIG_REGISTRY: https://registry.npm.taobao.org

stages:
  - test
  - build
  - deploy

sast:
  stage: test
include:
- template: Security/SAST.gitlab-ci.yml

build:
  stage: build
  script:
    - npm install --registry ${NPM_CONFIG_REGISTRY}
    - npm run build
    - mv dist html
  artifacts:
    paths:
      - html

deploy_testing:
  stage: deploy
  tags:
    - qrcode-testing
  dependencies:
    - build
  script:
    - whoami
    - ls -la /usr/share/nginx/
    - rm -rf /usr/share/nginx/html/
    - mv -f html /usr/share/nginx/html
    - echo "Deploy to testing server"
    - ls -la /usr/share/nginx/
    - ls -la /usr/share/nginx/html/
  environment:
    name: testing
    url: http://43.156.10.57/
    deployment_tier: testing

deploy_production:
  stage: deploy
  tags:
    - qrcode-production
  dependencies:
    - build
  script:
    - rm -rf /usr/share/nginx/html/
    - mv -f html /usr/share/nginx/html
    - echo "Deploy to staging server"
    - ls -la /usr/share/nginx/
    - ls -la /usr/share/nginx/html/
  environment:
    name: production
    url: http://43.156.10.216/
    deployment_tier: production