Skip to content
Snippets Groups Projects
Commit 0638fea0 authored by Vinod Bangera's avatar Vinod Bangera
Browse files

Initial commit by containerization

parent 4db9a52c
No related branches found
No related tags found
No related merge requests found
FROM node:14-alpine
WORKDIR /app
COPY package*.json ./
RUN npm install
COPY . .
RUN npm run build
EXPOSE 3000
CMD npm start
pipeline {
agent any
tools {
nodejs 'NodeJS'
}
environment {
PROJECT_ID = "tech-rnd-project"
CLUSTER_NAME = "react-cluster"
LOCATION = "us-central1-b"
CREDENTIALS_ID = "335fefa0-0089-4fe2-994c-fd3bd9e2ab2b"
}
stages {
stage('Scm Checkout') {
steps {
checkout scm
}
}
stage('Build') {
steps {
echo 'building the software'
// sh 'npm install --force'
}
}
stage('Test') {
steps {
//add steps here
echo 'testing'
}
}
stage('Build Docker Image') {
steps {
script {
sh 'whoami'
sh 'sudo chmod 777 /var/run/docker.sock'
sh "docker build -t react-app ."
}
}
}
// stage('Image Scan') {
// steps {
// //add steps here
// echo 'image scanning'
// sh 'trivy image --no-progress --exit-code 1 --severity CRITICAL react-app'
// }
// }
stage('Push Docker Image') {
steps {
script {
echo 'Push Docker Image'
sh "docker tag react-app asia-south1-docker.pkg.dev/tech-rnd-project/container-react/reactjs"
sh 'gcloud auth configure-docker asia-south1-docker.pkg.dev'
sh 'docker push asia-south1-docker.pkg.dev/tech-rnd-project/container-react/reactjs'
// sh 'curl -LO https://storage.googleapis.com/kubernetes-release/release/$(curl -s https://storage.googleapis.com/kubernetes-release/release/stable.txt)/bin/linux/amd64/kubectl'
// sh 'chmod +x kubectl'
// sh "sudo mv kubectl \$(which kubectl)"
}
}
}
stage('Deploy to K8s') {
steps {
echo 'Deployment started ...'
sh 'ls -ltr'
sh 'pwd'
echo 'Start deployment of deployment.yaml'
step([$class: 'KubernetesEngineBuilder', projectId: env.PROJECT_ID, clusterName: env.CLUSTER_NAME, location: env.LOCATION, manifestPattern: 'k8', credentialsId: env.CREDENTIALS_ID, verifyDeployments: true])
echo 'Deployment Finished ...'
sh '''
'''
}
}
}
post {
always {
emailext to: 'vinod.bangera@niveussolutions.com',
subject: "jenkins build:${currentBuild.currentResult}: ${env.JOB_NAME}",
body: "${currentBuild.currentResult}: Job ${env.JOB_NAME}\nMore Info can be found in the attached log",
attachLog: true
}
}
}
web: npm start
apiVersion: apps/v1
kind: Deployment
metadata:
name: react-app
spec:
replicas: 1
selector:
matchLabels:
app: react-app
template:
metadata:
labels:
app: react-app
spec:
containers:
- name: react-app
image: asia-south1-docker.pkg.dev/tech-rnd-project/container-react/reactjs
ports:
- containerPort: 3000
apiVersion: v1
kind: Service
metadata:
name: node-app
name: react-app
spec:
ports:
- port: 3000
targetPort: 3000
type: LoadBalancer
selector:
app: react-app
...@@ -3,6 +3,7 @@ ...@@ -3,6 +3,7 @@
"version": "0.1.0", "version": "0.1.0",
"private": true, "private": true,
"dependencies": { "dependencies": {
"sonarqube-scanner": "^3.0.1",
"@testing-library/jest-dom": "^5.17.0", "@testing-library/jest-dom": "^5.17.0",
"@testing-library/react": "^13.4.0", "@testing-library/react": "^13.4.0",
"@testing-library/user-event": "^13.5.0", "@testing-library/user-event": "^13.5.0",
...@@ -13,6 +14,7 @@ ...@@ -13,6 +14,7 @@
"web-vitals": "^2.1.4" "web-vitals": "^2.1.4"
}, },
"scripts": { "scripts": {
"sonar": "node sonar-project.js",
"start": "react-scripts start", "start": "react-scripts start",
"build": "react-scripts build", "build": "react-scripts build",
"test": "react-scripts test", "test": "react-scripts test",
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment