From 933c2ee903f2cffa2f8009c6dbea8c8cb6bfd132 Mon Sep 17 00:00:00 2001 From: VIPIN Date: Thu, 11 Sep 2025 09:54:16 +0530 Subject: [PATCH] Update message for Jenkins + Minikube pipeline test --- Dockerfile | 16 +++++++++++++++ Jenkinsfile | 38 ++++++++++++++++++++++++++++++++++++ app/index.js | 11 +++++++++++ app/package.json | 8 ++++++++ k8s/deployment-to-apply.yaml | 19 ++++++++++++++++++ k8s/deployment.yaml | 19 ++++++++++++++++++ k8s/service.yaml | 12 ++++++++++++ 7 files changed, 123 insertions(+) create mode 100644 Dockerfile create mode 100644 app/index.js create mode 100644 app/package.json create mode 100644 k8s/deployment-to-apply.yaml create mode 100644 k8s/deployment.yaml create mode 100644 k8s/service.yaml diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 0000000..342ac8a --- /dev/null +++ b/Dockerfile @@ -0,0 +1,16 @@ +# Use official Node.js image +FROM node:18-alpine + +WORKDIR /app + +# Copy and install dependencies +COPY app/package*.json ./ +RUN npm install --production + +# Copy app files +COPY app ./ + +EXPOSE 3000 + +# Run the app +CMD ["node", "index.js"] diff --git a/Jenkinsfile b/Jenkinsfile index b91574b..aee0683 100644 --- a/Jenkinsfile +++ b/Jenkinsfile @@ -1,4 +1,5 @@ pipeline { +<<<<<<< HEAD agent any environment { @@ -21,4 +22,41 @@ pipeline { echo "Pipeline finished: ${currentBuild.fullDisplayName}" } } +======= + agent any + environment { + DOCKERHUB_REPO = "vipin2025devops/myapp" + IMAGE_TAG = "${env.BUILD_NUMBER}" + } + stages { + stage('Checkout') { + steps { checkout scm } + } + stage('Build & Push Image') { + steps { + script { + docker.withRegistry('https://index.docker.io/v1/', 'dockerhub-creds') { + def img = docker.build("${DOCKERHUB_REPO}:${IMAGE_TAG}") + img.push() + bat "docker image rm ${DOCKERHUB_REPO}:${IMAGE_TAG} || exit 0" + } + } + } + } + stage('Deploy to Kubernetes') { + steps { + withCredentials([file(credentialsId: 'kubeconfig', variable: 'KUBECONFIG')]) { + script { + bat """ + powershell -Command "(Get-Content k8s/deployment.yaml) -replace 'IMAGE_PLACEHOLDER', '${DOCKERHUB_REPO}:${IMAGE_TAG}' | Set-Content k8s/deployment-to-apply.yaml" + kubectl --kubeconfig=%KUBECONFIG% apply -f k8s/deployment-to-apply.yaml + kubectl --kubeconfig=%KUBECONFIG% apply -f k8s/service.yaml + """ + } + } + } + } + } + post { always { echo "Pipeline finished: ${currentBuild.fullDisplayName}" } } +>>>>>>> 19a245e (Update message for Jenkins + Minikube pipeline test) } diff --git a/app/index.js b/app/index.js new file mode 100644 index 0000000..66bb42f --- /dev/null +++ b/app/index.js @@ -0,0 +1,11 @@ +const http = require('http'); + +const server = http.createServer((req, res) => { + res.writeHead(200, { 'Content-Type': 'text/plain' }); + res.end('🚀 New Deployment: Hello vipin.This is Jenkins + Minikube pipeline!\n'); +}); + +const PORT = 3000; +server.listen(PORT, () => { + console.log(`✅ Server running on port ${PORT}`); +}); diff --git a/app/package.json b/app/package.json new file mode 100644 index 0000000..aa92e02 --- /dev/null +++ b/app/package.json @@ -0,0 +1,8 @@ +{ + "name": "myapp", + "version": "1.0.0", + "main": "index.js", + "scripts": { + "start": "node index.js" + } +} diff --git a/k8s/deployment-to-apply.yaml b/k8s/deployment-to-apply.yaml new file mode 100644 index 0000000..c787901 --- /dev/null +++ b/k8s/deployment-to-apply.yaml @@ -0,0 +1,19 @@ +apiVersion: apps/v1 +kind: Deployment +metadata: + name: myapp-deployment +spec: + replicas: 1 + selector: + matchLabels: + app: myapp + template: + metadata: + labels: + app: myapp + spec: + containers: + - name: myapp + image: myapp:1 # Jenkins will replace this + ports: + - containerPort: 3000 diff --git a/k8s/deployment.yaml b/k8s/deployment.yaml new file mode 100644 index 0000000..5c83df7 --- /dev/null +++ b/k8s/deployment.yaml @@ -0,0 +1,19 @@ +apiVersion: apps/v1 +kind: Deployment +metadata: + name: myapp-deployment +spec: + replicas: 1 + selector: + matchLabels: + app: myapp + template: + metadata: + labels: + app: myapp + spec: + containers: + - name: myapp + image: IMAGE_PLACEHOLDER # Jenkins will replace this + ports: + - containerPort: 3000 diff --git a/k8s/service.yaml b/k8s/service.yaml new file mode 100644 index 0000000..1fe3b2d --- /dev/null +++ b/k8s/service.yaml @@ -0,0 +1,12 @@ +apiVersion: v1 +kind: Service +metadata: + name: myapp-service +spec: + selector: + app: myapp + type: NodePort + ports: + - port: 3000 + targetPort: 3000 + nodePort: 30080