pipeline:
  generate_docker_tag:
    image: golang
    commands:
      - echo -n "${CI_COMMIT_BRANCH//\//-}-${CI_COMMIT_SHA:0:8}, latest" > .tags
    when:
      path: [ "frontend/**", "telegram_bot/**", "api/**" ]
      event: push


  # -------------------------------------- API --------------------------------------
  build_api:
    image: woodpeckerci/plugin-docker-buildx
    settings:
      repo:
        from_secret: repo_api
      username:
        from_secret: username
      password:
        from_secret: password
      registry:
        from_secret: registry
      dockerfile: api/Dockerfile
      platforms: linux/amd64
    when:
      path: "api/**"
      event: push


  # -------------------------------------- Bot --------------------------------------
  build_bot:
    image: woodpeckerci/plugin-docker-buildx
    settings:
      repo:
        from_secret: repo_bot
      username:
        from_secret: username
      password:
        from_secret: password
      registry:
        from_secret: registry
      dockerfile: telegram_bot/Dockerfile
      platforms: linux/amd64
    when:
      path: "telegram_bot/**"
      event: push


  # -------------------------------------- Frontend --------------------------------------
  build_frontend:
    image: woodpeckerci/plugin-docker-buildx
    settings:
      repo:
        from_secret: repo_frontend
      username:
        from_secret: username
      password:
        from_secret: password
      registry:
        from_secret: registry
      dockerfile: frontend/Dockerfile
      platforms: linux/amd64
    when:
      path: "frontend/**"
      event: push


  # -------------------------------------- Deploy --------------------------------------
  deploy:
    image: appleboy/drone-ssh
    network_mode: host
    settings:
      host:
        from_secret: ssh_host
      username:
        from_secret: ssh_user
      password:
        from_secret: ssh_password
      script:
        - cd /root/docker/aktienbot
        - docker-compose pull
        - docker-compose -p "aktienbot" up -d
    when:
      path: [ "frontend/**", "telegram_bot/**", "api/**" ]
      event: push

branches: main
