added k8s files and manifests files
Some checks failed
ecommerce frontend/pipeline/head Something is wrong with the build of this commit

This commit is contained in:
tusuii
2026-03-10 22:41:08 +05:30
parent c504876102
commit bb5dfe4e23
5 changed files with 175 additions and 6 deletions

View File

@@ -1,16 +1,16 @@
FROM node:20
WORKDIR /vaishnaviecommerce
FROM mirror.gcr.io/library/node:20-bullseye-slim
WORKDIR /app
COPY package*.json ./
RUN npm install
COPY . .
RUN npm run build
ARG VITE_API_BASE_URL
ENV VITE_API_BASE_URL=$VITE_API_BASE_URL
RUN npm run build
EXPOSE 5173

96
Jenkinsfile vendored Normal file
View 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"
}
}
}
}

40
k8s/deployment.yaml Normal file
View File

@@ -0,0 +1,40 @@
apiVersion: apps/v1
kind: Deployment
metadata:
name: website
namespace: ecommerce
spec:
replicas: 1
selector:
matchLabels:
app: website
template:
metadata:
labels:
app: website
spec:
containers:
- name: website
image: 192.168.49.2:30004/vaishnavi-ecommerce/website:latest
imagePullPolicy: Always
ports:
- containerPort: 5173
resources:
requests:
cpu: "100m"
memory: "128Mi"
limits:
cpu: "250m"
memory: "256Mi"
livenessProbe:
httpGet:
path: /
port: 5173
initialDelaySeconds: 15
periodSeconds: 15
readinessProbe:
httpGet:
path: /
port: 5173
initialDelaySeconds: 5
periodSeconds: 5

20
k8s/ingress.yaml Normal file
View File

@@ -0,0 +1,20 @@
apiVersion: networking.k8s.io/v1
kind: Ingress
metadata:
name: website-ingress
namespace: ecommerce
annotations:
nginx.ingress.kubernetes.io/proxy-body-size: "10m"
spec:
ingressClassName: nginx
rules:
- host: website.local
http:
paths:
- path: /
pathType: Prefix
backend:
service:
name: website
port:
number: 5173

13
k8s/service.yaml Normal file
View File

@@ -0,0 +1,13 @@
apiVersion: v1
kind: Service
metadata:
name: website
namespace: ecommerce
spec:
type: NodePort
selector:
app: website
ports:
- port: 5173
targetPort: 5173
nodePort: 30081