From 4924fe823cc4ada24f883f59becf88975a46f529 Mon Sep 17 00:00:00 2001 From: subodh Date: Fri, 20 Feb 2026 15:31:19 +0000 Subject: [PATCH] Update Jenkinsfile --- Jenkinsfile | 32 ++++++++++++++++++++++++++------ 1 file changed, 26 insertions(+), 6 deletions(-) diff --git a/Jenkinsfile b/Jenkinsfile index d840821..4b3bbb7 100644 --- a/Jenkinsfile +++ b/Jenkinsfile @@ -7,8 +7,6 @@ pipeline { IMAGE_NAME = "ecommerce-backend" IMAGE_TAG = "${REGISTRY}/library/${IMAGE_NAME}:${env.BRANCH_NAME}-${env.BUILD_NUMBER}" NAMESPACE = "ecommerce" - // Pointing to the internal nerdctl/buildkit socket - BUILDKIT_HOST = "unix:///run/buildkit/buildkitd.sock" } stages { @@ -21,7 +19,20 @@ pipeline { stage('Build Image') { steps { script { - // nerdctl needs to know which containerd socket to use + // Ensure the buildkit socket directory exists and is writable + sh "sudo mkdir -p /run/buildkit && sudo chmod 777 /run/buildkit" + + // Start buildkitd if it is not already running + sh """ + if ! pgrep buildkitd > /dev/null; then + echo "Starting buildkitd daemon..." + # Start as root via sudo since it needs to manage network/mounts + sudo nohup buildkitd --addr unix:///run/buildkit/buildkitd.sock > /tmp/buildkitd.log 2>&1 & + sleep 10 + fi + """ + + // Run the build using the aliased docker (nerdctl) command sh "docker build -t ${IMAGE_TAG} ." } } @@ -41,8 +52,7 @@ pipeline { stage('Inject to K8s Cache') { steps { script { - // Since your agent is already using the containerd socket, - // the image might already be in the cache, but this ensures it. + // Force the image into the local containerd store sh "docker save ${IMAGE_TAG} | sudo ctr -n k8s.io images import -" } } @@ -52,11 +62,21 @@ pipeline { steps { script { withCredentials([file(credentialsId: 'k8s-config', variable: 'KUBECONFIG')]) { - sh "kubectl --kubeconfig=${KUBECONFIG} patch deployment ${APP_NAME} -n ${NAMESPACE} --patch '{\"spec\": {\"template\": {\"spec\": {\"containers\": [{\"name\": \"${APP_NAME}\", \"image\": \"${IMAGE_TAG}\", \"imagePullPolicy\": \"Never\"}]}}}}'" + sh """ + kubectl --kubeconfig=${KUBECONFIG} patch deployment ${APP_NAME} -n ${NAMESPACE} --patch \ + '{"spec": {"template": {"spec": {"containers": [{"name": "${APP_NAME}", "image": "${IMAGE_TAG}", "imagePullPolicy": "Never"}]}}}}' + """ sh "kubectl --kubeconfig=${KUBECONFIG} rollout status deployment/${APP_NAME} -n ${NAMESPACE}" } } } } } + + post { + always { + // Cleanup to save space on the agent + sh "docker rmi ${IMAGE_TAG} || true" + } + } } \ No newline at end of file