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:
27
Jenkinsfile
vendored
27
Jenkinsfile
vendored
@@ -3,7 +3,7 @@ pipeline {
|
|||||||
|
|
||||||
environment {
|
environment {
|
||||||
REGISTRY = "myharbor.local:80"
|
REGISTRY = "myharbor.local:80"
|
||||||
HARBOR_IP = "192.168.108.101" // Your Master Node IP
|
HARBOR_IP = "192.168.108.101"
|
||||||
APP_NAME = "ecommerce-app"
|
APP_NAME = "ecommerce-app"
|
||||||
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}"
|
||||||
@@ -14,18 +14,25 @@ pipeline {
|
|||||||
stages {
|
stages {
|
||||||
stage('Network Setup') {
|
stage('Network Setup') {
|
||||||
steps {
|
steps {
|
||||||
// Manually inject the host entry for this build session
|
// No sudo needed, agent is running as root
|
||||||
sh "echo '${HARBOR_IP} myharbor.local' | sudo tee -a /etc/hosts"
|
sh "echo '${HARBOR_IP} myharbor.local' >> /etc/hosts"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
stage('Build Image') {
|
stage('Build Image') {
|
||||||
steps {
|
steps {
|
||||||
script {
|
script {
|
||||||
// Start buildkitd if it died during pod rotation
|
// Ensure directories exist for BuildKit
|
||||||
sh "mkdir -p /run/buildkit && sudo chmod 777 /run/buildkit"
|
sh "mkdir -p /run/buildkit && chmod 777 /run/buildkit"
|
||||||
sh "nohup buildkitd --addr unix:///run/buildkit/buildkitd.sock > /tmp/buildkitd.log 2>&1 &"
|
|
||||||
sleep 10
|
// Start buildkitd in background if not running
|
||||||
|
sh """
|
||||||
|
if ! pgrep buildkitd > /dev/null; then
|
||||||
|
echo "Starting buildkitd..."
|
||||||
|
nohup buildkitd --addr unix:///run/buildkit/buildkitd.sock > /tmp/buildkitd.log 2>&1 &
|
||||||
|
sleep 10
|
||||||
|
fi
|
||||||
|
"""
|
||||||
|
|
||||||
sh "nerdctl --address ${CONTAINERD_ADDR} build --insecure-registry -t ${IMAGE_TAG} ."
|
sh "nerdctl --address ${CONTAINERD_ADDR} build --insecure-registry -t ${IMAGE_TAG} ."
|
||||||
}
|
}
|
||||||
@@ -36,7 +43,6 @@ pipeline {
|
|||||||
steps {
|
steps {
|
||||||
script {
|
script {
|
||||||
withCredentials([usernamePassword(credentialsId: 'harbor-creds', passwordVariable: 'PASS', usernameVariable: 'USER')]) {
|
withCredentials([usernamePassword(credentialsId: 'harbor-creds', passwordVariable: 'PASS', usernameVariable: 'USER')]) {
|
||||||
// Using --password-stdin to remove the "insecure" warning
|
|
||||||
sh "echo '${PASS}' | nerdctl --address ${CONTAINERD_ADDR} login ${REGISTRY} -u ${USER} --password-stdin --insecure-registry"
|
sh "echo '${PASS}' | nerdctl --address ${CONTAINERD_ADDR} login ${REGISTRY} -u ${USER} --password-stdin --insecure-registry"
|
||||||
sh "nerdctl --address ${CONTAINERD_ADDR} push ${IMAGE_TAG} --insecure-registry"
|
sh "nerdctl --address ${CONTAINERD_ADDR} push ${IMAGE_TAG} --insecure-registry"
|
||||||
}
|
}
|
||||||
@@ -48,7 +54,10 @@ pipeline {
|
|||||||
steps {
|
steps {
|
||||||
script {
|
script {
|
||||||
withCredentials([file(credentialsId: 'k8s-config', variable: 'KUBECONFIG')]) {
|
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"}]}}}}'
|
||||||
|
"""
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user