diff --git a/Jenkinsfile b/Jenkinsfile index 23cd33c..3b59972 100644 --- a/Jenkinsfile +++ b/Jenkinsfile @@ -7,6 +7,8 @@ pipeline { IMAGE_NAME = "ecommerce-backend" IMAGE_TAG = "${REGISTRY}/library/${IMAGE_NAME}:${env.BRANCH_NAME}-${env.BUILD_NUMBER}" NAMESPACE = "ecommerce" + // Explicitly tell the docker wrapper where to find the daemon you just started + BUILDKIT_HOST = "unix:///run/buildkit/buildkitd.sock" } stages { @@ -19,12 +21,20 @@ pipeline { stage('Build Image') { steps { script { - // We call nerdctl directly, bypassing the 'docker' wrapper script. - // This uses the containerd socket that your deployment YAML confirmed is at /run/containerd-pod/containerd.sock - sh "nerdctl --address /run/containerd-pod/containerd.sock build -t ${IMAGE_TAG} ." + // Check if the socket you just created is actually visible to the Jenkins agent + sh """ + if [ -S /run/buildkit/buildkitd.sock ]; then + echo "BuildKit socket found! Proceeding with build..." + else + echo "BuildKit socket NOT found at /run/buildkit/buildkitd.sock" + echo "Listing /run to find correct path:" + ls -R /run + exit 1 + fi + """ - // Tag it as latest for the local cache as well - sh "nerdctl --address /run/containerd-pod/containerd.sock tag ${IMAGE_TAG} ${IMAGE_NAME}:latest" + // Build using the socket + sh "docker build -t ${IMAGE_TAG} ." } } } @@ -43,7 +53,7 @@ pipeline { stage('Inject to K8s Cache') { steps { script { - // Force the image into the local containerd store + // This is crucial: inject into the k8s namespace sh "docker save ${IMAGE_TAG} | sudo ctr -n k8s.io images import -" } } @@ -63,11 +73,4 @@ pipeline { } } } - - post { - always { - // Cleanup to save space on the agent - sh "docker rmi ${IMAGE_TAG} || true" - } - } } \ No newline at end of file