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

server:
  host: 38.38.251.113:31245
  user: root
  password:
    from_secret: www_password

clone:
  depth: 1

steps:
  - name: build new image
    environment:
      DOCKER_LOGIN:
        from_secret: docker_login
      DOCKER_TOKEN:
        from_secret: docker_token
      DOCKER_PASSWORD:
        from_secret: docker_password
    commands:
      - echo "$DOCKER_PASSWORD" | docker login -u $DOCKER_LOGIN --password-stdin docker.kkknametrans.buzz
      - docker build -t docker.kkknametrans.buzz/kami/boss_${DRONE_BRANCH}:${DRONE_BUILD_NUMBER} -f deploy/Dockerfile . --build-arg USE_PROXY=0
      - docker tag docker.kkknametrans.buzz/kami/boss_${DRONE_BRANCH}:${DRONE_BUILD_NUMBER} docker.kkknametrans.buzz/kami/boss_${DRONE_BRANCH}:latest
      - docker push docker.kkknametrans.buzz/kami/boss_${DRONE_BRANCH}:${DRONE_BUILD_NUMBER}
      - docker push docker.kkknametrans.buzz/kami/boss_${DRONE_BRANCH}:latest
      - docker logout docker.kkknametrans.buzz
      - docker login git.kkknametrans.buzz -u $DOCKER_LOGIN -p $DOCKER_TOKEN
      - docker tag docker.kkknametrans.buzz/kami/boss_${DRONE_BRANCH}:${DRONE_BUILD_NUMBER} git.kkknametrans.buzz/danial/kami_boss_${DRONE_BRANCH}:${DRONE_BUILD_NUMBER}
      - docker tag docker.kkknametrans.buzz/kami/boss_${DRONE_BRANCH}:${DRONE_BUILD_NUMBER} git.kkknametrans.buzz/danial/kami_boss_${DRONE_BRANCH}:latest
      - docker push git.kkknametrans.buzz/danial/kami_boss_${DRONE_BRANCH}:${DRONE_BUILD_NUMBER}
      - docker push git.kkknametrans.buzz/danial/kami_boss_${DRONE_BRANCH}:latest
      - docker logout git.kkknametrans.buzz
  - name: deploy to docker compose
    environment:
      DOCKER_LOGIN:
        from_secret: docker_login
      DOCKER_TOKEN:
        from_secret: docker_token
      DOCKER_PASSWORD:
        from_secret: docker_password
    commands:
      - echo "$DOCKER_PASSWORD" | docker login -u $DOCKER_LOGIN --password-stdin docker.kkknametrans.buzz
      - BRANCH=${DRONE_BRANCH} VERSION=${DRONE_BUILD_NUMBER} docker compose -f /data/kami/docker-compose.yaml --profile boss up -d
      - docker logout docker.kkknametrans.buzz
trigger:
  branch:
    - develop
    - production
  when:
    event:
      - push
