# This file is a template, and might need editing before it works on your project.
# Official framework image. Look for the different tagged releases at:
# https://hub.docker.com/r/library/node/tags/
#services:
#  - docker:dind

variables:
  KUBECONFIG: /etc/deploy/config

##This folder is cached between builds
##http://docs.gitlab.com/ce/ci/yaml/README.html#cache
cache:
  untracked: true
  paths:
  - ./node_modules

stages:
  - build
  - push
  - deploy

build-node-dev:
  image: node:11.2.0
  stage: build
  before_script:
    - npm config set registry=http://registry.npm.taobao.org
    - npm config set puppeteer_download_host=https://storage.googleapis.com.cnpmjs.org
    - export APP_ENV_OS=dev
  script:
    - npm i
    - npm run build
  only:
    - dev
  tags:
    - node-build-mac
    #- svr251
  cache:
    paths:
      - ./dist

docker-push-dev:
  image: docker:stable
  stage: push
#  services:
#    - docker:dind
#  variables:
#    DOCKER_HOST: tcp://localhost:2375
#    DOCKER_DRIVER: overlay2
  script:
    - ls -al
    - find ./ -name dist
    - docker build -t registry.cn-shenzhen.aliyuncs.com/thinker-vc/communicaten-web:1.0.0 .
    - docker push registry.cn-shenzhen.aliyuncs.com/thinker-vc/communicate-web:1.0.0
  tags:
    - node-build-mac
    #- svr251
  only:
    - dev

build-node-pro:
  image: node:11.2.0
  stage: build
  before_script:
    - npm config set registry=http://registry.npm.taobao.org
    - npm config set puppeteer_download_host=https://storage.googleapis.com.cnpmjs.org
    - export APP_ENV_OS=production
  script:
    - npm i
    - npm run build
  only:
    - master
  tags:
    - node-build-mac
    #- svr251
  cache:
    paths:
      - ./dist


docker-push-pro:
  image: docker:stable
  stage: push
#  services:
#    - docker:dind
#  variables:
#    DOCKER_HOST: tcp://localhost:2375
#    DOCKER_DRIVER: overlay2
  script:
    - ls -al
    - find ./ -name dist
    - docker build -t registry.cn-shenzhen.aliyuncs.com/thinker-vc/communicate-web:release-1.0.0 .
    - docker push registry.cn-shenzhen.aliyuncs.com/thinker-vc/communicate-web:release-1.0.0
  tags:
    - node-build-mac
    #- svr251
  only:
    - master


deploy-prod:
  stage: deploy
  image: registry.cn-shenzhen.aliyuncs.com/thinker-open/helm-kubectl:v2.9.1-1.10.7
  before_script:
    - mkdir -p /etc/deploy
    - echo ${kube_config} | base64 -d > ${KUBECONFIG}
    - kubectl config use-context kubernetes-admin@kubernetes
    - helm init --client-only --stable-repo-url https://kubernetes.oss-cn-hangzhou.aliyuncs.com/charts
    - helm repo add thinker http://thinkervc:thinker@helm@helm.thinker.vc/
    - helm repo update
  script:
    - |
        helm upgrade communicate-web --install --reuse-values \
        --set updateVersion=`date +%s`  \
        --set image.repository="registry-vpc.cn-shenzhen.aliyuncs.com/thinker-vc/communicate-web" \
        --set image.tag="release-1.0.0" \
        --set ingress.host="communicate.thinker.vc" \
        --set ingress.tls="communicate-tls" \
        --namespace communicate \
        thinker/static
  environment:
    name: prod
    url: communicate.thinker.vc
  cache: {}
  only:
  - master
