cache:
  paths:
  - node_modules/
  
stages:
    - sonar
    - build
    - deploy
    
variables:    
  CONTAINER_NAME: web_common_company_site
  
  LAN_REPO: registry-vpc.cn-beijing.aliyuncs.com/qianjia2018
  WAN_REPO: registry.cn-beijing.aliyuncs.com/qianjia2018

  DEV_REPO:  $WAN_REPO/qianjia_dev
  PRED_REPO: $WAN_REPO/qianjia_pred
  PROD_REPO: $LAN_REPO/qianjia_prod

sonar check:
    image: registry.cn-beijing.aliyuncs.com/qianjia2018/qianjia_dev:sonar1
    stage: sonar
    script:
      - /opt/sonar-runner-2.4/bin/sonar-runner -Dsonar.projectName=$CONTAINER_NAME  -Dsonar.projectKey=$CONTAINER_NAME -Dsonar.projectVersion=1.0 -Dsonar.sources=. -Dsonar.language=js -Dsonar.java.binaries=./*
    tags: 
      - sonarqube-200
    only:
      - dev


build_push_image_dev:
    stage: build
    before_script:
      - docker login --username=wangnannan@1520818330092673 --password="qj123123" registry-vpc.cn-beijing.aliyuncs.com

    script:
        - docker build -t $LAN_REPO/qianjia_dev:$CONTAINER_NAME .
        - docker push $LAN_REPO/qianjia_dev:$CONTAINER_NAME
    tags:
        - docker-run
    only:
        - dev
        
build_push_image_pred:
    stage: build
    before_script:
      - docker login --username=wangnannan@1520818330092673 --password="qj123123" registry-vpc.cn-beijing.aliyuncs.com

    script:
        - docker build -t $LAN_REPO/qianjia_pred:$CONTAINER_NAME .
        - docker push $LAN_REPO/qianjia_pred:$CONTAINER_NAME
    tags:
        - docker-run
    only:
        - release      

        
remote_run_image_dev:
    stage: deploy
    script:
      - bash ~/.local/bin/f200.sh   $CONTAINER_NAME    7084 80   $DEV_REPO:$CONTAINER_NAME  guojia   192.168.10.200
    tags:
      - shell-200
    only:
      - dev 
    when: on_success

remote_run_image_pred:
    stage: deploy
  
    script:
      - bash ~/.local/bin/fdeploy.sh $CONTAINER_NAME  7084 80  $PRED_REPO:$CONTAINER_NAME zp  39.106.144.161
    tags:
        - shell-prod 
    only:
        - release
    when: on_success