---
kind: pipeline
type: docker
name: deploy

environment:
  PACKAGE: TubeArchivist
  URL: tubearchivist.alexlebens.net

steps:
  - name: Tests
    image: ps03fd.alexlebens.net:5000/droneimage:latest
    commands:
      - /scripts/tests.sh

  - name: Nofification > Discord | Tests - Failure
    image: appleboy/drone-discord
    settings:
      webhook_id:
        from_secret: discord_webhook_id
      webhook_token:
        from_secret: discord_webhook_token
      username: DroneCI - ps03fd
      message: Docker compose validation for TubeArchivist failed.
    when:
      status:
        - failure

  - name: Configuration
    image: ps03fd.alexlebens.net:5000/droneimage:latest
    commands:
      - mkdir ~/.ssh/
      - echo "$SSH_KEY" > ~/.ssh/id_rsa
      - chmod 600 ~/.ssh/id_rsa
      - ssh-keyscan -H $HOST_IP >> ~/.ssh/known_hosts
      - /scripts/configuration.sh
    environment:
      SSH_KEY:
        from_secret: ssh_key_ps03fd_drone
      DOCKER_HOST:
        from_secret: docker_host_ps03fd
      HOST_IP:
        from_secret: host_ip_ps03fd
      UPTIMEKUMA_NAME:
        from_secret: uptimekuma_name
      UPTIMEKUMA_PASSWORD:
        from_secret: uptimekuma_password
      UPTIMEKUMA_URL:
        from_secret: uptimekuma_url
    when:
      branch:
        - main

  - name: Nofification > Discord | Configuration - Failure
    image: appleboy/drone-discord
    settings:
      webhook_id:
        from_secret: discord_webhook_id
      webhook_token:
        from_secret: discord_webhook_token
      username: DroneCI - ps03fd
      message: Configuration for TubeArchivist failed.
    when:
      status:
        - failure

  - name: Deploy
    image: ps03fd.alexlebens.net:5000/droneimage:latest
    commands:
      - mkdir ~/.ssh/
      - echo "$SSH_KEY" > ~/.ssh/id_rsa
      - chmod 600 ~/.ssh/id_rsa
      - ssh-keyscan -H $HOST_IP >> ~/.ssh/known_hosts
      - /scripts/deploy.sh
    environment:
      SSH_KEY:
        from_secret: ssh_key_ps03fd_drone
      DOCKER_HOST:
        from_secret: docker_host_ps03fd
      HOST_IP:
        from_secret: host_ip_ps03fd
    when:
      branch:
        - main

  - name: Nofification > Discord | Deploy - Success
    image: appleboy/drone-discord
    settings:
      webhook_id:
        from_secret: discord_webhook_id
      webhook_token:
        from_secret: discord_webhook_token
      username: DroneCI - ps03fd
      message: Docker compose deployment for TubeArchivist succeeded
    when:
      status:
        - sucess

  - name: Nofification > Discord | Deploy - Failure
    image: appleboy/drone-discord
    settings:
      webhook_id:
        from_secret: discord_webhook_id
      webhook_token:
        from_secret: discord_webhook_token
      username: DroneCI - ps03fd
      message: Docker compose deployment for TubeArchivist failed.
    when:
      status:
        - failure
