kind: pipeline
type: docker
name: miniprogram-manager-prod

volumes: # 声明数据卷
  - name: targetDir
    host:
      path: /miniprogram-manager

clone:
  disable: false # 启用代码拉取

steps:
  - name: build-project
    image: mcr.microsoft.com/dotnet/core/sdk:3.0-alpine
    pull: if-not-exists
    depends_on: [clone] # 依赖的步骤
    volumes: # 挂载数据卷
      - name: targetDir
        path: /drone/src/dist/
    commands: # 执行命令
      - echo '' > ~/.nuget/NuGet/NuGet.Config
      - echo '<?xml version="1.0" encoding="utf-8"?><configuration><packageSources><add key="nuget.org" value="https://nuget.cdn.azure.cn/v3/index.json" protocolVersion="3" /></packageSources></configuration>' > ~/.nuget/NuGet/NuGet.Config
      - rm -rf /drone/src/dist/*
      - dotnet publish -c release -o ./publish
      - cp -r ./publish/* /drone/src/dist # 复制文件
    when:
      status:
        - success # 当前步骤成功时执行
  - name: scp-project
    image: appleboy/drone-scp
    pull: if-not-exists
    depends_on: [build-project] # 依赖的步骤
    volumes: # 挂载数据卷
      - name: targetDir # 数据卷名称
        path: /miniprogram-manager # 容器内目录 绝对路径
    settings:
      host:
        from_secret: miniprogram-manager-host-a
      username:
        from_secret: username
      password:
        from_secret: userpwd
      port: 22
      command_timeout: 2m
      target: /home/ABServer/deploy-ready/
      source:
        - echo ====开始拷贝=======
        - /miniprogram-manager/*
        - echo ====结束拷贝=======
      when:
        status:
          - success # 当前步骤成功时执行

  - name: deploy-project
    image: appleboy/drone-ssh
    pull: if-not-exists
    depends_on: [scp-project] # 依赖的步骤
    settings:
      host:
        from_secret: miniprogram-manager-host-a
      username:
        from_secret: username
      password:
        from_secret: userpwd
      port: 22
      command_timeout: 2m
      script:
        - echo ====开始部署=======
        - cd /home/ABServer/
        - cp -r /home/ABServer/deploy-ready/miniprogram-manager /home/ABServer/webroot/
        - docker restart miniprogram-manager
        # - docker restart nodeServer1
        - echo ====部署成功=======
  - name: scp-project-b
    image: appleboy/drone-scp
    pull: if-not-exists
    depends_on: [build-project] # 依赖的步骤
    volumes: # 挂载数据卷
      - name: targetDir # 数据卷名称
        path: /miniprogram-manager # 容器内目录 绝对路径
    settings:
      host:
        from_secret: miniprogram-manager-host-b
      username:
        from_secret: username
      password:
        from_secret: userpwd
      port: 22
      command_timeout: 2m
      target: /home/ABServer/deploy-ready/
      source:
        - echo ====开始拷贝=======
        - /miniprogram-manager/*
        - echo ====结束拷贝=======
      when:
        status:
          - success # 当前步骤成功时执行

  - name: deploy-project-b
    image: appleboy/drone-ssh
    pull: if-not-exists
    depends_on: [scp-project] # 依赖的步骤
    settings:
      host:
        from_secret: miniprogram-manager-host-b
      username:
        from_secret: username
      password:
        from_secret: userpwd
      port: 22
      command_timeout: 2m
      script:
        - echo ====开始部署=======
        - cd /home/ABServer/
        - cp -r /home/ABServer/deploy-ready/miniprogram-manager /home/ABServer/webroot/
        - docker restart miniprogram-manager
        # - docker restart nodeServer1
        - echo ====部署成功=======

trigger:
  branch:
    - release-miniprogram-manager
  event:
    - push
  #排除合并请求
  exclude:
    - ref: refs/pull/*