---
kind: pipeline
type: ssh
name: master-machine

server:
  host: 121.37.253.228
  user: www
  password:
    from_secret: www_password

clone:
  depth: 1

steps:
  - name: build new image
    commands:
      - VERSION=${DRONE_BRANCH}${DRONE_BUILD_NUMBER} docker compose -f ./deploy/docker-compose.yml build --build-arg USE_PROXY=1 --no-cache
  - name: clean old container
    commands:
      - VERSION=${DRONE_BRANCH}${DRONE_BUILD_NUMBER} docker container inspect kami_frontend &> /dev/null && docker container rm -f kami_frontend
  - name: start new container
    commands:
      - echo start build
      - VERSION=${DRONE_BRANCH}${DRONE_BUILD_NUMBER} docker compose -f ./deploy/docker-compose.yml -p kami_frontend up -d
  # - name: clean old image and container
  #   commands:
  #     - docker images --filter "dangling=true" -q | xargs -r docker rmi -f
  #     - docker images --filter "label=none" -q | xargs -r docker rmi -f

trigger:
  branch:
    - develop
    - production
  when:
    event:
      - push

---
kind: pipeline
type: ssh
name: 绝技服务器

server:
  host: 43.133.200.219
  user: ubuntu
  password:
    from_secret: flower

clone:
  depth: 1

steps:
  - name: build new image
    commands:
      - VERSION=${DRONE_BRANCH}${DRONE_BUILD_NUMBER} docker compose -f ./deploy/docker-compose.yml build --no-cache
  - name: clean old continaer
    commands:
      - VERSION=${DRONE_BRANCH}${DRONE_BUILD_NUMBER} docker container inspect kami_frontend &> /dev/null && docker container rm -f kami_frontend
  - name: start new container
    commands:
      - echo start build
      - VERSION=${DRONE_BRANCH}${DRONE_BUILD_NUMBER} docker compose -f ./deploy/docker-compose.yml -p kami_frontend up -d
  # - name: clean old image and container
  #   commands:
  #     - docker images --filter "dangling=true" -q | xargs -r docker rmi -f
  #     - docker images --filter "label=none" -q | xargs -r docker rmi -f

trigger:
  status:
    - success
    - failure
  branch:
    - production
  when:
    event:
      - push

---
kind: pipeline
type: ssh
name: 小L的服务器

server:
  host: 43.130.238.110
  user: ubuntu
  password:
    from_secret: ubuntu_L

clone:
  depth: 1

steps:
  - name: build new image
    commands:
      - VERSION=${DRONE_BRANCH}${DRONE_BUILD_NUMBER} docker compose -f ./deploy/docker-compose.yml build --no-cache
  - name: clean old continaer
    commands:
      - VERSION=${DRONE_BRANCH}${DRONE_BUILD_NUMBER} docker container inspect kami_frontend &> /dev/null && docker container rm -f kami_frontend
  - name: start new container
    commands:
      - echo start build
      - VERSION=${DRONE_BRANCH}${DRONE_BUILD_NUMBER} docker compose -f ./deploy/docker-compose.yml -p kami_frontend up -d
  # - name: clean old image and container
  #   commands:
  #     - docker images --filter "dangling=true" -q | xargs -r docker rmi -f
  #     - docker images --filter "label=none" -q | xargs -r docker rmi -f

trigger:
  branch:
    - production
  status:
    - success
    - failure
  when:
    event:
      - push

---
kind: pipeline
type: ssh
name: 泼兔的服务器

server:
  host: 43.163.223.93
  user: ubuntu
  password:
    from_secret: ubuntu-crazy_rabbit

clone:
  depth: 1

steps:
  - name: build new image
    commands:
      - VERSION=${DRONE_BRANCH}${DRONE_BUILD_NUMBER} docker compose -f ./deploy/docker-compose.yml build --no-cache
  - name: clean old continaer
    commands:
      - VERSION=${DRONE_BRANCH}${DRONE_BUILD_NUMBER} docker container inspect kami_frontend &> /dev/null && docker container rm -f kami_frontend
  - name: start new container
    commands:
      - echo start build
      - VERSION=${DRONE_BRANCH}${DRONE_BUILD_NUMBER} docker compose -f ./deploy/docker-compose.yml -p kami_frontend up -d
  # - name: clean old image and container
  #   commands:
  #     - docker images --filter "dangling=true" -q | xargs -r docker rmi -f
  #     - docker images --filter "label=none" -q | xargs -r docker rmi -f

trigger:
  status:
    - success
    - failure
  branch:
    - production
  when:
    event:
      - push

---
kind: pipeline
type: docker
name: server酱微信通知

depends_on:
  - 泼兔的服务器
  - 小L的服务器
  - 绝技服务器
  - master-machine
steps:
  - name: send-wechat
    image: plugins/webhook
    pull: if-not-exists
    settings:
      urls: https://open.feishu.cn/open-apis/bot/v2/hook/1f4a9795-84a9-4cc5-b2c5-0bf05686336b
      content_type: application/json
      template: |
        {
          "msg_type":"text",
          "content":
            {
              "text": "项目名称： ${DRONE_REPO_NAME}\n分支：${DRONE_BRANCH}\n构建编号：${DRONE_BUILD_NUMBER}\n项目构建状态：{{ build.status }}"
            }
        }

trigger:
  branch:
    - develop
    - production
  status:
    - success
    - failure
  when:
    event:
      - push
