diff --git a/Jenkinsfile b/Jenkinsfile index 3b59972..472ca1e 100644 --- a/Jenkinsfile +++ b/Jenkinsfile @@ -7,8 +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" + // Pointing nerdctl to the socket we found in your ls output + CONTAINERD_ADDR = "/run/containerd-pod/containerd.sock" } stages { @@ -21,20 +21,9 @@ pipeline { stage('Build Image') { steps { script { - // 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 - """ - - // Build using the socket - sh "docker build -t ${IMAGE_TAG} ." + // Use nerdctl directly with the explicit socket address + // we add --insecure-registry because harbor is on port 80 + sh "nerdctl --address ${CONTAINERD_ADDR} build --insecure-registry -t ${IMAGE_TAG} ." } } } @@ -43,29 +32,22 @@ pipeline { steps { script { withCredentials([usernamePassword(credentialsId: 'harbor-creds', passwordVariable: 'PASS', usernameVariable: 'USER')]) { - sh "docker login ${REGISTRY} -u ${USER} -p ${PASS}" - sh "docker push ${IMAGE_TAG}" + sh "nerdctl --address ${CONTAINERD_ADDR} login ${REGISTRY} -u ${USER} -p ${PASS} --insecure-registry" + sh "nerdctl --address ${CONTAINERD_ADDR} push ${IMAGE_TAG} --insecure-registry" } } } } - stage('Inject to K8s Cache') { - steps { - script { - // This is crucial: inject into the k8s namespace - sh "docker save ${IMAGE_TAG} | sudo ctr -n k8s.io images import -" - } - } - } - stage('Deploy to K8s') { steps { script { withCredentials([file(credentialsId: 'k8s-config', variable: 'KUBECONFIG')]) { + // Patch the deployment. Since nerdctl shares the containerd store, + // the image is already 'imported' effectively. sh """ kubectl --kubeconfig=${KUBECONFIG} patch deployment ${APP_NAME} -n ${NAMESPACE} --patch \ - '{"spec": {"template": {"spec": {"containers": [{"name": "${APP_NAME}", "image": "${IMAGE_TAG}", "imagePullPolicy": "Never"}]}}}}' + '{"spec": {"template": {"spec": {"containers": [{"name": "${APP_NAME}", "image": "${IMAGE_TAG}", "imagePullPolicy": "IfNotPresent"}]}}}}' """ sh "kubectl --kubeconfig=${KUBECONFIG} rollout status deployment/${APP_NAME} -n ${NAMESPACE}" }