added k8s files and manifests files
Some checks failed
ecommerce frontend/pipeline/head Something is wrong with the build of this commit
Some checks failed
ecommerce frontend/pipeline/head Something is wrong with the build of this commit
This commit is contained in:
96
Jenkinsfile
vendored
Normal file
96
Jenkinsfile
vendored
Normal file
@@ -0,0 +1,96 @@
|
||||
pipeline {
|
||||
agent any
|
||||
|
||||
parameters {
|
||||
string(
|
||||
name: 'NODE_IP',
|
||||
defaultValue: '192.168.108.200',
|
||||
description: 'On-premise Kubernetes node IP'
|
||||
)
|
||||
}
|
||||
|
||||
environment {
|
||||
HARBOR = '192.168.108.200:80'
|
||||
IMAGE = '192.168.108.200:80/vaishnavi-ecommerce/website'
|
||||
OLD_IMAGE = '192.168.49.2:30004/vaishnavi-ecommerce/website:latest'
|
||||
TAG = "${env.BUILD_NUMBER}"
|
||||
NAMESPACE = 'ecommerce'
|
||||
}
|
||||
|
||||
stages {
|
||||
stage('Build Image') {
|
||||
steps {
|
||||
sh """
|
||||
docker build \
|
||||
--build-arg VITE_API_BASE_URL=http://${params.NODE_IP}:30080/api \
|
||||
-t ${IMAGE}:${TAG} \
|
||||
-t ${IMAGE}:latest \
|
||||
.
|
||||
"""
|
||||
}
|
||||
}
|
||||
|
||||
stage('Push to Harbor') {
|
||||
steps {
|
||||
withCredentials([usernamePassword(
|
||||
credentialsId: 'harbor-credentials',
|
||||
usernameVariable: 'HARBOR_USER',
|
||||
passwordVariable: 'HARBOR_PASS'
|
||||
)]) {
|
||||
sh """
|
||||
echo "\$HARBOR_PASS" | docker login ${HARBOR} -u "\$HARBOR_USER" --password-stdin
|
||||
docker push ${IMAGE}:${TAG}
|
||||
docker push ${IMAGE}:latest
|
||||
"""
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
stage('Deploy') {
|
||||
steps {
|
||||
withCredentials([file(credentialsId: 'kubeconfig', variable: 'KUBECONFIG')]) {
|
||||
sh """
|
||||
sed "s|${OLD_IMAGE}|${IMAGE}:${TAG}|g" \
|
||||
k8s/deployment.yaml | kubectl apply -f -
|
||||
kubectl apply -f k8s/service.yaml
|
||||
kubectl apply -f k8s/ingress.yaml
|
||||
"""
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
stage('Verify Rollout') {
|
||||
steps {
|
||||
withCredentials([file(credentialsId: 'kubeconfig', variable: 'KUBECONFIG')]) {
|
||||
sh "kubectl rollout status deployment/website -n ${NAMESPACE} --timeout=180s"
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
stage('Smoke Test') {
|
||||
steps {
|
||||
sh """
|
||||
STATUS=\$(curl -o /dev/null -sw "%{http_code}" http://${params.NODE_IP}:30081)
|
||||
echo "HTTP status: \$STATUS"
|
||||
[ "\$STATUS" = "200" ]
|
||||
"""
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
post {
|
||||
always {
|
||||
sh "docker rmi ${IMAGE}:${TAG} || true"
|
||||
sh "docker rmi ${IMAGE}:latest || true"
|
||||
}
|
||||
success {
|
||||
echo "Deploy successful. Website accessible at http://${params.NODE_IP}:30081"
|
||||
}
|
||||
failure {
|
||||
withCredentials([file(credentialsId: 'kubeconfig', variable: 'KUBECONFIG')]) {
|
||||
sh "kubectl get pods -n ${NAMESPACE} || true"
|
||||
sh "kubectl describe deployment/website -n ${NAMESPACE} || true"
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user