kind: pipeline
type: docker
name: vendor-report-cicd

trigger:
  branch:
    - main
    - deployment-ready
  event:
    - push

steps:
  - name: build-image
    image: docker:24-cli
    volumes:
    - name: dockersock
      path: /var/run/docker.sock
    environment:
      DOCKER_HOST: unix:///var/run/docker.sock
      DOCKER_BUILDKIT: 1
    commands:
    - echo "Building vendor-report Docker image..."
    - docker build -t registry.lci.ge/taskboard/vendor-report-api:${DRONE_COMMIT_SHA:0:8} .
    - echo "Tagging image as latest..."
    - docker tag registry.lci.ge/taskboard/vendor-report-api:${DRONE_COMMIT_SHA:0:8} registry.lci.ge/taskboard/vendor-report-api:latest
    - echo "Vendor-report Docker image built and tagged successfully"
    when:
      event:
      - push

  - name: push-image
    image: docker:24-cli
    volumes:
    - name: dockersock
      path: /var/run/docker.sock
    environment:
      DOCKER_HOST: unix:///var/run/docker.sock
    commands:
    - echo "Pushing vendor-report image to registry..."
    - docker push registry.lci.ge/taskboard/vendor-report-api:${DRONE_COMMIT_SHA:0:8}
    - docker push registry.lci.ge/taskboard/vendor-report-api:latest
    - echo "Vendor-report image pushed to registry"
    - echo "Cleaning up local images to save space..."
    - docker rmi registry.lci.ge/taskboard/vendor-report-api:${DRONE_COMMIT_SHA:0:8} || true
    - docker rmi registry.lci.ge/taskboard/vendor-report-api:latest || true
    when:
      event:
      - push

volumes:
- name: dockersock
  host:
    path: /var/run/docker.sock

