Some checks failed
eCommerce-backend/pipeline/head There was a failure building this commit
73 lines
2.5 KiB
Groovy
73 lines
2.5 KiB
Groovy
pipeline {
|
|
agent any
|
|
|
|
environment {
|
|
REGISTRY = "myharbor.local:80"
|
|
APP_NAME = "ecommerce-app"
|
|
IMAGE_NAME = "ecommerce-backend"
|
|
IMAGE_TAG = "${REGISTRY}/library/${IMAGE_NAME}:${env.BRANCH_NAME}-${env.BUILD_NUMBER}"
|
|
NAMESPACE = "ecommerce"
|
|
}
|
|
|
|
stages {
|
|
stage('Checkout') {
|
|
steps {
|
|
checkout scm
|
|
}
|
|
}
|
|
|
|
stage('Build Image') {
|
|
steps {
|
|
script {
|
|
// We call nerdctl directly, bypassing the 'docker' wrapper script.
|
|
// This uses the containerd socket that your deployment YAML confirmed is at /run/containerd-pod/containerd.sock
|
|
sh "nerdctl --address /run/containerd-pod/containerd.sock build -t ${IMAGE_TAG} ."
|
|
|
|
// Tag it as latest for the local cache as well
|
|
sh "nerdctl --address /run/containerd-pod/containerd.sock tag ${IMAGE_TAG} ${IMAGE_NAME}:latest"
|
|
}
|
|
}
|
|
}
|
|
|
|
stage('Push to Harbor') {
|
|
steps {
|
|
script {
|
|
withCredentials([usernamePassword(credentialsId: 'harbor-creds', passwordVariable: 'PASS', usernameVariable: 'USER')]) {
|
|
sh "docker login ${REGISTRY} -u ${USER} -p ${PASS}"
|
|
sh "docker push ${IMAGE_TAG}"
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
stage('Inject to K8s Cache') {
|
|
steps {
|
|
script {
|
|
// Force the image into the local containerd store
|
|
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')]) {
|
|
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"
|
|
}
|
|
}
|
|
} |