pipeline {
  agent {
    docker {
      image 'ubuntu-latest'
    }

  }
  stages {
    stage('Checkout') {
      steps {
        git(branch: 'main', url: 'https://git.acayip.dev/log101/log101-dot-dev.git')
      }
    }

    stage('Build Docker Image') {
      steps {
        script {
          docker.build("${REGISTRY}/${DOCKER_IMAGE}:${DOCKER_TAG}")
        }

      }
    }

    stage('Push to microk8s Registry') {
      steps {
        script {
          docker.withRegistry("http://${REGISTRY}") {
            docker.image("${REGISTRY}/${DOCKER_IMAGE}:${DOCKER_TAG}").push()
          }
        }

      }
    }

    stage('Cleanup') {
      steps {
        script {
          sh "docker rmi ${REGISTRY}/${DOCKER_IMAGE}:${DOCKER_TAG} || true"
        }

      }
    }

  }
  environment {
    DOCKER_IMAGE = 'log101-dot-dev'
    DOCKER_TAG = 'latest'
    REGISTRY = '192.168.88.252:5000'
  }
}