minikube working
This commit is contained in:
79
Jenkinsfile
vendored
79
Jenkinsfile
vendored
@@ -31,6 +31,20 @@ pipeline {
|
||||
}
|
||||
}
|
||||
|
||||
stage('Install Tools') {
|
||||
steps {
|
||||
sh '''
|
||||
# Ensure kustomize is available
|
||||
if ! command -v kustomize &>/dev/null; then
|
||||
echo "Installing kustomize..."
|
||||
curl -sL "https://github.com/kubernetes-sigs/kustomize/releases/download/kustomize%2Fv5.4.3/kustomize_v5.4.3_linux_amd64.tar.gz" \
|
||||
| tar xz -C /usr/local/bin/
|
||||
fi
|
||||
kustomize version
|
||||
'''
|
||||
}
|
||||
}
|
||||
|
||||
stage('Test') {
|
||||
steps {
|
||||
sh 'npm ci && npm test -- --reporter=verbose 2>&1 || true'
|
||||
@@ -42,10 +56,10 @@ pipeline {
|
||||
// steps {
|
||||
// withSonarQubeEnv('SonarQube') {
|
||||
// sh """
|
||||
// npx sonar-scanner \
|
||||
// -Dsonar.projectKey=${SONAR_PROJECT} \
|
||||
// -Dsonar.projectName='eCommerce Backend' \
|
||||
// -Dsonar.sources=src \
|
||||
// npx sonar-scanner \\
|
||||
// -Dsonar.projectKey=${SONAR_PROJECT} \\
|
||||
// -Dsonar.projectName='eCommerce Backend' \\
|
||||
// -Dsonar.sources=src \\
|
||||
// -Dsonar.host.url=${SONAR_HOST_URL}
|
||||
// """
|
||||
// }
|
||||
@@ -100,16 +114,63 @@ pipeline {
|
||||
}
|
||||
}
|
||||
|
||||
stage('Deploy to K8s') {
|
||||
stage('Validate Manifests') {
|
||||
steps {
|
||||
sh """
|
||||
echo "── Validating Kustomize build ──"
|
||||
kustomize build ${K8S_OVERLAY}
|
||||
echo "✅ Kustomize build succeeded"
|
||||
"""
|
||||
}
|
||||
}
|
||||
|
||||
stage('Deploy Infrastructure') {
|
||||
steps {
|
||||
withKubeConfig([credentialsId: "${K8S_CRED_ID}"]) {
|
||||
// Apply the full kustomize overlay (namespace, secrets, DBs, redis, app, job)
|
||||
sh "kubectl apply -k ${K8S_OVERLAY}"
|
||||
|
||||
// Wait for databases to be ready first
|
||||
sh "kubectl rollout status statefulset/postgres -n ${K8S_NAMESPACE} --timeout=300s"
|
||||
sh "kubectl rollout status statefulset/mongodb -n ${K8S_NAMESPACE} --timeout=300s"
|
||||
sh "kubectl rollout status deployment/redis -n ${K8S_NAMESPACE} --timeout=120s"
|
||||
|
||||
echo "✅ Infrastructure (Postgres, MongoDB, Redis) is ready."
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
stage('Run DB Migrations') {
|
||||
steps {
|
||||
withKubeConfig([credentialsId: "${K8S_CRED_ID}"]) {
|
||||
// Delete previous migration job if it exists (Jobs are immutable)
|
||||
sh "kubectl delete job prisma-migrate -n ${K8S_NAMESPACE} --ignore-not-found=true"
|
||||
|
||||
// Re-apply to create a fresh migration job
|
||||
sh "kubectl apply -k ${K8S_OVERLAY}"
|
||||
|
||||
// Wait for the migration job to complete
|
||||
sh """
|
||||
echo "Waiting for Prisma migration job to complete..."
|
||||
kubectl wait --for=condition=complete \
|
||||
job/prisma-migrate \
|
||||
-n ${K8S_NAMESPACE} \
|
||||
--timeout=120s \
|
||||
&& echo "✅ Prisma migration succeeded" \
|
||||
|| {
|
||||
echo "❌ Migration failed — showing logs:"
|
||||
kubectl logs job/prisma-migrate -n ${K8S_NAMESPACE} --tail=50
|
||||
exit 1
|
||||
}
|
||||
"""
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
stage('Deploy Application') {
|
||||
steps {
|
||||
withKubeConfig([credentialsId: "${K8S_CRED_ID}"]) {
|
||||
sh "kubectl rollout status deployment/ecommerce-app -n ${K8S_NAMESPACE} --timeout=300s"
|
||||
|
||||
echo "✅ Backend deployed successfully."
|
||||
}
|
||||
}
|
||||
@@ -126,8 +187,8 @@ pipeline {
|
||||
--attach \
|
||||
-n ${K8S_NAMESPACE} \
|
||||
-- curl -sf http://ecommerce-app:80/health \
|
||||
&& echo "Health check PASSED" \
|
||||
|| echo "Health check FAILED (non-blocking)"
|
||||
&& echo "✅ Health check PASSED" \
|
||||
|| echo "⚠️ Health check FAILED (non-blocking)"
|
||||
"""
|
||||
}
|
||||
}
|
||||
@@ -145,7 +206,7 @@ pipeline {
|
||||
|
||||
post {
|
||||
success {
|
||||
echo "✅ Build #${env.BUILD_NUMBER} — eCommerce Backend deployed → http://api.local"
|
||||
echo "✅ Build #${env.BUILD_NUMBER} — eCommerce Backend deployed → NodePort 30080"
|
||||
}
|
||||
failure {
|
||||
echo "❌ Pipeline failed. Check stage logs above."
|
||||
|
||||
Reference in New Issue
Block a user