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

server:
  host: 38.38.251.113:34156
  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
    commands:
      - docker login git.oceanpay.cc -u $DOCKER_LOGIN -p $DOCKER_TOKEN
      - docker build -t git.oceanpay.cc/danial/kami_merchant_${DRONE_BRANCH}:${DRONE_BUILD_NUMBER} -f deploy/Dockerfile . --build-arg USE_PROXY=0
      - docker tag git.oceanpay.cc/danial/kami_merchant_${DRONE_BRANCH}:${DRONE_BUILD_NUMBER} git.oceanpay.cc/danial/kami_merchant_${DRONE_BRANCH}:latest
      - docker push git.oceanpay.cc/danial/kami_merchant_${DRONE_BRANCH}:${DRONE_BUILD_NUMBER}
      - docker push git.oceanpay.cc/danial/kami_merchant_${DRONE_BRANCH}:latest
      - docker logout git.oceanpay.cc
  - name: deploy to docker compose
    environment:
      DOCKER_LOGIN:
        from_secret: docker_login
      DOCKER_TOKEN:
        from_secret: docker_token
    commands:
      - docker login git.oceanpay.cc -u $DOCKER_LOGIN -p $DOCKER_TOKEN
      - BRANCH=${DRONE_BRANCH} VERSION=${DRONE_BUILD_NUMBER} docker compose -f /data/kami/docker-compose.yaml --profile merchant up -d
      - docker logout git.oceanpay.cc

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

