kind: pipeline
type: ssh
name: qudoco-be-build-deploy

server:
  host:
    from_secret: ssh_host
  user:
    from_secret: ssh_user
  ssh_key:
    from_secret: ssh_key

steps:
  - name: prepare repo
    when:
      branch:
        - main
    commands:
      - rm -rf /opt/build/qudoco-be
      - mkdir -p /opt/build/qudoco-be
      - cd /opt/build/qudoco-be
      - git clone http://38.47.180.165:3000/qudo-project/qudoco-be.git

  - name: build image
    when:
      branch:
        - main
    commands:
      - docker login 38.47.180.165:3000 -u administrator -p HarborDockerImageRep0
      - cd /opt/build/qudoco-be/qudoco-be
      - docker build -t 38.47.180.165:3000/qudo-project/qudoco-be:main .
      - docker push 38.47.180.165:3000/qudo-project/qudoco-be:main

  - name: deploy
    when:
      branch:
        - main
    commands:
      - docker login 38.47.180.165:3000 -u administrator -p HarborDockerImageRep0
      - docker pull 38.47.180.165:3000/qudo-project/qudoco-be:main
      - docker stop qudoco-be || true
      - docker rm qudoco-be || true
      - docker run -dt -p 8812:8800 --name qudoco-be 38.47.180.165:3000/qudo-project/qudoco-be:main
