kind: pipeline
type: docker
name: default

steps:

  - name: install-node
    image: node:16.10.0
    commands:
      - npm config set registry https://registry.npmmirror.com
      - yarn config set registry https://registry.npmmirror.com
      - yarn config list
      - yarn config set proxy http://192.168.1.5:10809 -g
      - yarn config set https-proxy http://192.168.1.5:10809 -g
      - yarn install
      - yarn build:test

  - name: zip-dist
    image: alpine:3.12
    commands:
      - sed -i 's#https\?://dl-cdn.alpinelinux.org/alpine#https://mirrors.tuna.tsinghua.edu.cn/alpine#g' /etc/apk/repositories
      - apk update
      - apk add zip
      - zip -r dist.zip dist

  - name: push
    image: appleboy/drone-scp
    settings:
      host:
        from_secret: TestServerIP
      port:
        from_secret: Port
      username: root
      password: 
        from_secret: TestServerPwd
      command_timeout: 3m
      target: /opt/docker/other/nginx/html/
      source:
        - dist.zip
      status:
        - success

  - name: deploy
    image: appleboy/drone-ssh
    settings:
      host:
        from_secret: TestServerIP
      username: root
      password: 
        from_secret: TestServerPwd
      port:
        from_secret: Port
      script:
        - 'cd /opt/docker/other/nginx/html'
        - 'unzip dist.zip'
        - 'rm -rf dist.zip'
        - 'rm -rf admin'
        - 'mv dist admin'
        - 'docker exec nginx nginx -s reload'
      status:
        - success
trigger:
  branch:
    - 2.0
  event:
    - push
