Update message for Jenkins + Minikube pipeline test
This commit is contained in:
parent
6124329708
commit
933c2ee903
16
Dockerfile
Normal file
16
Dockerfile
Normal file
@ -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"]
|
||||||
38
Jenkinsfile
vendored
38
Jenkinsfile
vendored
@ -1,4 +1,5 @@
|
|||||||
pipeline {
|
pipeline {
|
||||||
|
<<<<<<< HEAD
|
||||||
agent any
|
agent any
|
||||||
|
|
||||||
environment {
|
environment {
|
||||||
@ -21,4 +22,41 @@ pipeline {
|
|||||||
echo "Pipeline finished: ${currentBuild.fullDisplayName}"
|
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)
|
||||||
}
|
}
|
||||||
|
|||||||
11
app/index.js
Normal file
11
app/index.js
Normal file
@ -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}`);
|
||||||
|
});
|
||||||
8
app/package.json
Normal file
8
app/package.json
Normal file
@ -0,0 +1,8 @@
|
|||||||
|
{
|
||||||
|
"name": "myapp",
|
||||||
|
"version": "1.0.0",
|
||||||
|
"main": "index.js",
|
||||||
|
"scripts": {
|
||||||
|
"start": "node index.js"
|
||||||
|
}
|
||||||
|
}
|
||||||
19
k8s/deployment-to-apply.yaml
Normal file
19
k8s/deployment-to-apply.yaml
Normal file
@ -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
|
||||||
19
k8s/deployment.yaml
Normal file
19
k8s/deployment.yaml
Normal file
@ -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
|
||||||
12
k8s/service.yaml
Normal file
12
k8s/service.yaml
Normal file
@ -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
|
||||||
Loading…
Reference in New Issue
Block a user