image: docker:19.03.7

services:
  - docker:19.03.7-dind
  
stages:
  - install
  - build_docker_image
  - build_docker_clear
cache:
  paths:
    - node_modules/

before_script:
  - node -v
  - npm install

install_dependencies:
  image: node:14.19.3
  stage: install
  only:
    - main
  tags:
    - test
  script:
    - echo "=====node install start====="
    - pwd
    - npm ci
    - npm run build
    - echo "=====node install end ====="
  artifacts:
    paths:
      - node_modules/

docker-build-main:
  variables:
    # do not clone again
    GIT_STRATEGY: none
  stage: build_docker_image
  only:
    - main
  tags:
    - test
  script:
    # make docker image and push to local docker 
    - echo "=====node build_docker_image start====="
    - sudo docker login -u $CI_REGISTRY_USER -p $CI_REGISTRY_PASSWORD $CI_REGISTRY
    - sudo docker build -t $CI_REGISTRY/root/registry/skfems/ui .
    - sudo docker push $CI_REGISTRY/root/registry/skfems/ui
    - sudo docker rmi $CI_REGISTRY/root/registry/skfems/ui
    - echo "=====node build_docker_image end====="

clear-files:
  stage: build_docker_clear
  only:
    - main
  tags:
    - test
  script:
    # 빌드 완료후 빌드시 Root 계정으로 생성된 자료 클리어 처리(아래 부분을 수행 안하면, 다음번 파이브라인 처리시 권한 문제로 수행 안됨)
    - sudo rm -rf .nuxt
    - sudo rm -rf dist
    - sudo rm -rf node_modules
