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_NAME = "ecommerce-backend"
|
||||||
IMAGE_TAG = "${REGISTRY}/library/${IMAGE_NAME}:${env.BRANCH_NAME}-${env.BUILD_NUMBER}"
|
IMAGE_TAG = "${REGISTRY}/library/${IMAGE_NAME}:${env.BRANCH_NAME}-${env.BUILD_NUMBER}"
|
||||||
NAMESPACE = "ecommerce"
|
NAMESPACE = "ecommerce"
|
||||||
// Explicitly tell the docker wrapper where to find the daemon you just started
|
// Pointing nerdctl to the socket we found in your ls output
|
||||||
BUILDKIT_HOST = "unix:///run/buildkit/buildkitd.sock"
|
CONTAINERD_ADDR = "/run/containerd-pod/containerd.sock"
|
||||||
}
|
}
|
||||||
|
|
||||||
stages {
|
stages {
|
||||||
@@ -21,20 +21,9 @@ pipeline {
|
|||||||
stage('Build Image') {
|
stage('Build Image') {
|
||||||
steps {
|
steps {
|
||||||
script {
|
script {
|
||||||
// Check if the socket you just created is actually visible to the Jenkins agent
|
// Use nerdctl directly with the explicit socket address
|
||||||
sh """
|
// we add --insecure-registry because harbor is on port 80
|
||||||
if [ -S /run/buildkit/buildkitd.sock ]; then
|
sh "nerdctl --address ${CONTAINERD_ADDR} build --insecure-registry -t ${IMAGE_TAG} ."
|
||||||
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} ."
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -43,29 +32,22 @@ pipeline {
|
|||||||
steps {
|
steps {
|
||||||
script {
|
script {
|
||||||
withCredentials([usernamePassword(credentialsId: 'harbor-creds', passwordVariable: 'PASS', usernameVariable: 'USER')]) {
|
withCredentials([usernamePassword(credentialsId: 'harbor-creds', passwordVariable: 'PASS', usernameVariable: 'USER')]) {
|
||||||
sh "docker login ${REGISTRY} -u ${USER} -p ${PASS}"
|
sh "nerdctl --address ${CONTAINERD_ADDR} login ${REGISTRY} -u ${USER} -p ${PASS} --insecure-registry"
|
||||||
sh "docker push ${IMAGE_TAG}"
|
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') {
|
stage('Deploy to K8s') {
|
||||||
steps {
|
steps {
|
||||||
script {
|
script {
|
||||||
withCredentials([file(credentialsId: 'k8s-config', variable: 'KUBECONFIG')]) {
|
withCredentials([file(credentialsId: 'k8s-config', variable: 'KUBECONFIG')]) {
|
||||||
|
// Patch the deployment. Since nerdctl shares the containerd store,
|
||||||
|
// the image is already 'imported' effectively.
|
||||||
sh """
|
sh """
|
||||||
kubectl --kubeconfig=${KUBECONFIG} patch deployment ${APP_NAME} -n ${NAMESPACE} --patch \
|
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}"
|
sh "kubectl --kubeconfig=${KUBECONFIG} rollout status deployment/${APP_NAME} -n ${NAMESPACE}"
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user