jenkinsfile
Some checks failed
eCommerce-backend/pipeline/head There was a failure building this commit
Some checks failed
eCommerce-backend/pipeline/head There was a failure building this commit
This commit is contained in:
38
Jenkinsfile
vendored
38
Jenkinsfile
vendored
@@ -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}"
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user