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:
32
Jenkinsfile
vendored
32
Jenkinsfile
vendored
@@ -7,7 +7,6 @@ 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"
|
||||||
// Pointing nerdctl to the socket we found in your ls output
|
|
||||||
CONTAINERD_ADDR = "/run/containerd-pod/containerd.sock"
|
CONTAINERD_ADDR = "/run/containerd-pod/containerd.sock"
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -21,9 +20,28 @@ pipeline {
|
|||||||
stage('Build Image') {
|
stage('Build Image') {
|
||||||
steps {
|
steps {
|
||||||
script {
|
script {
|
||||||
// Use nerdctl directly with the explicit socket address
|
// Force nerdctl to use the socket by creating the directory it expects
|
||||||
// we add --insecure-registry because harbor is on port 80
|
sh """
|
||||||
sh "nerdctl --address ${CONTAINERD_ADDR} build --insecure-registry -t ${IMAGE_TAG} ."
|
sudo mkdir -p /run/buildkit-default
|
||||||
|
sudo mkdir -p /run/buildkit
|
||||||
|
|
||||||
|
# Search for the buildkit socket in the entire /run directory
|
||||||
|
# and symlink it to the default location nerdctl wants
|
||||||
|
BK_SOCKET=\$(find /run -name "buildkitd.sock" | head -n 1)
|
||||||
|
|
||||||
|
if [ -n "\$BK_SOCKET" ]; then
|
||||||
|
echo "Found BuildKit socket at \$BK_SOCKET. Linking..."
|
||||||
|
sudo ln -sf \$BK_SOCKET /run/buildkit/buildkitd.sock
|
||||||
|
sudo ln -sf \$BK_SOCKET /run/buildkit-default/buildkitd.sock
|
||||||
|
else
|
||||||
|
echo "BuildKit socket not found. Attempting to start it locally..."
|
||||||
|
sudo nohup buildkitd --addr unix:///run/buildkit/buildkitd.sock > /tmp/buildkitd.log 2>&1 &
|
||||||
|
sleep 10
|
||||||
|
fi
|
||||||
|
|
||||||
|
# Run the build
|
||||||
|
nerdctl --address ${CONTAINERD_ADDR} build --insecure-registry -t ${IMAGE_TAG} .
|
||||||
|
"""
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -43,11 +61,11 @@ pipeline {
|
|||||||
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,
|
// Using 'Never' because nerdctl builds directly into the containerd store
|
||||||
// the image is already 'imported' effectively.
|
// shared by the node.
|
||||||
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": "IfNotPresent"}]}}}}'
|
'{"spec": {"template": {"spec": {"containers": [{"name": "${APP_NAME}", "image": "${IMAGE_TAG}", "imagePullPolicy": "Never"}]}}}}'
|
||||||
"""
|
"""
|
||||||
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