kind: pipeline
type: docker
name: 构建静态站点

trigger:
  event:
    - push
  branch:
    - master

steps:
  - name: 构建 Docker 镜像
    image: plugins/docker:latest
    privileged: true
    settings:
      username: kagami-ci
      password:
        from_secret: KAGAMI-CI-PASSWORD
      repo: gitea.service.jazzwhom.top/mttu-developers/docs
      registry: gitea.service.jazzwhom.top
      tags:
        - latest
        - latest-${DRONE_COMMIT_SHA}
      dockerfile: Dockerfile
    volumes:
      - name: docker-socket
        path: /var/run/docker.sock
  - name: 创建 Ansible Inventory 文件
    image: alpine/helm:3.2.1
    environment:
      CI_DEPLOY_SERVER:
        from_secret: CI-DEPLOY-SERVER
      CI_DEPLOY_PORT:
        from_secret: CI-DEPLOY-PORT
      CI_DEPLOY_USER:
        from_secret: CI-DEPLOY-USER
      CI_DEPLOY_KEY:
        from_secret: CI-DEPLOY-KEY
    commands:
      - mkdir -p deploy
      - echo "[jazzwhom_server]" > deploy/inventory.ini
      - echo "prod_doc_server ansible_host=$${CI_DEPLOY_SERVER} ansible_port=$${CI_DEPLOY_PORT} ansible_user=$${CI_DEPLOY_USER}" >> deploy/inventory.ini
      - echo "$${CI_DEPLOY_KEY}" > deploy/deploy_key
      - chmod 600 deploy/deploy_key
  - name: 部署到服务器
    image: alpine/ansible:latest
    commands:
      - ansible-playbook --inventory deploy/inventory.ini --private-key deploy/deploy_key --ssh-common-args='-o StrictHostKeyChecking=no' deploy/deploy.ansible.yml

  - name: 发送构建结果到 ntfy
    image: parrazam/drone-ntfy
    when:
      status: [success, failure]
    settings:
      url: https://ntfy.service.jazzwhom.top
      topic: drone_ci
      tags:
        - drone-ci
      token:
        from_secret: NTFY_TOKEN

volumes:
  - name: docker-socket
    host:
      path: /var/run/docker.sock
