kind: pipeline
name: linear-dream-hd-pipeline

platform:
  os: linux
  arch: amd64

workspace:
  path: /drone/src

trigger:
  branch:
    - master
  event:
    - push

image_pull_secrets:
  - docker_auth_config
steps:

  - name: build(release
    image: node:14.18.1
    commands:
      - CI=false
      - echo 'build 打包部署'
      - npm config set registry https://registry.npm.taobao.org
      - npm config set disturl https://npm.taobao.org/dist
      - npm config set electron_mirror https://npm.taobao.org/mirrors/electron/
      - npm config set sass_binary_site https://npm.taobao.org/mirrors/node-sass/
      - npm config set phantomjs_cdnurl https://npm.taobao.org/mirrors/phantomjs/
      - npm install cnpm -g
      - npm install -g create-react-app
      - npm install --save-dev react-dev-utils
      - npm install --save-dev patch-package
      - npm install --save-dev jsondiffpatch-for-react
      - npm install --save-dev dotenv-cli
      - npm install
      - npm run build:test
    when:
      branch:
        - release/*
      status: [ success ]

  - name: push(release
    image: plugins/docker
    settings:
      username: lunar@starlinear
      password:
        from_secret: CI_PWD
      insecure: true
      repo: linear-repo-registry.cn-shanghai.cr.aliyuncs.com/platform/dream-hd
      dockerfile: Dockerfile
      registry: linear-repo-registry.cn-shanghai.cr.aliyuncs.com
      tags:
        - 'release'
    when:
      branch:
        - release/*
      status: [ success ]

  - name: deploy(release
    image: appleboy/drone-ssh
    settings:
      host: 106.15.72.97
      username: root
      ssh_key:
        from_secret: SSH_KEY
      port: 22
      insecure: false
      command_timeout: 3m
      script:
        - docker pull linear-repo-registry-vpc.cn-shanghai.cr.aliyuncs.com/platform/dream-hd:release
        - cd /wwwroot/dream-hd/
        - docker-compose down
        - docker-compose -f docker-compose.yml up -d
    when:
      branch:
        - release/*
      status: [ success ]

