diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..d987a2b05474c50c2f0c048e2216d158c8b686f8 --- /dev/null +++ b/Dockerfile @@ -0,0 +1,14 @@ +# base image +FROM node:14.18.0-alpine + +RUN apk --update add git + +WORKDIR /app +# add `/app/node_modules/.bin` to $PATH +ENV PATH /app/node_modules/.bin:$PATH +# install and cache app dependencies +COPY . /app/ +RUN npm install -g serve +EXPOSE 5000 +# To start app +ENTRYPOINT ["serve", "-s", "build"] diff --git a/Jenkinsfile b/Jenkinsfile new file mode 100644 index 0000000000000000000000000000000000000000..527f988483b90a1cfa10e5b997899205a09e4198 --- /dev/null +++ b/Jenkinsfile @@ -0,0 +1,57 @@ +pipeline { + agent{ + label 'nodejs' + } + environment { + DOCKER_TAG = "v${env.BUILD_NUMBER}" + } + options{ + // Stop the build early in case of compile or test failures + skipStagesAfterUnstable() + } + stages { + + stage("Testing"){ + steps{ + echo "no script" + + sh label: '', script: 'chmod +x changeTag.sh' + sh label: '', script: './changeTag.sh ${DOCKER_TAG}' + + } + } + stage("Build Project"){ + steps{ + sh label: '', script: '''npm install --production +npm install react-scripts -g --silent +CI=false npm run build''' + } + } + stage("Building Frontend Image"){ + steps{ + + sh label: '', script: '''docker build -t novisync-web-react-front-prod:v1 . +docker tag novisync-web-react-front-prod:v1 docker-registry-server:5000/novisync-web-react-front-prod:${DOCKER_TAG}''' + + + } + } + stage("Docker push Frontend Image"){ + steps{ + sh label: '', script: 'docker push docker-registry-server:5000/novisync-web-react-front-prod:${DOCKER_TAG}' + } + } + stage("Deploy Frontend to k8s"){ + steps{ + + sh label: '', script: 'sshpass -f "/root/suresh/k8s-pro" scp -o StrictHostKeyChecking=no novisync-web-react-frontend.yml root@192.168.6.110:/root/suresh/' + sh label: '', script: 'sshpass -f "/root/suresh/k8s-pro" ssh -o StrictHostKeyChecking=no root@192.168.6.110 \'kubectl apply -f /root/suresh/novisync-web-react-frontend.yml\'' + } + } + + } +} +def getDockerTag(){ + def tag = sh script: ' git rev-parse HEAD', returnStdout: true + return tag +} diff --git a/changeTag.sh b/changeTag.sh new file mode 100644 index 0000000000000000000000000000000000000000..c066717f21302fdb05b1d237f7b24dcb9e5432e3 --- /dev/null +++ b/changeTag.sh @@ -0,0 +1,4 @@ +#! /bin/bash + +tag="$1" +sed -i "s/tagVersion/$tag/g" novisync-web-react-frontend.yml \ No newline at end of file diff --git a/novisync-web-react-frontend.yml b/novisync-web-react-frontend.yml new file mode 100644 index 0000000000000000000000000000000000000000..787eb9506824e9ae3626cec5db386214ad20b384 --- /dev/null +++ b/novisync-web-react-frontend.yml @@ -0,0 +1,57 @@ +apiVersion: apps/v1 +kind: Deployment +metadata: + name: novisync-web-react-front-prod + namespace: nodejsprod +spec: + replicas: 1 + selector: + matchLabels: + app: novisync-web-react-front-prod-app + template: + metadata: + labels: + app: novisync-web-react-front-prod-app + spec: + + containers: + - image: docker-registry-server:5000/novisync-web-react-front-prod:tagVersion + name: novisync-web-react-front-prod-cont + resources: + requests: + memory: "1Mi" + cpu: "0.1" + limits: + memory: "1000Mi" + cpu: "0.7" + + +--- +apiVersion: v1 +kind: Service +metadata: + name: novisync-web-react-front-prod-svc + namespace: nodejsprod +spec: + selector: + app: novisync-web-react-front-prod-app + type: NodePort + ports: + - nodePort: 31194 + port: 5000 + targetPort: 5000 + +--- +apiVersion: autoscaling/v1 +kind: HorizontalPodAutoscaler +metadata: + name: novisync-web-react-front-prod-autoscale + namespace: nodejsprod +spec: + scaleTargetRef: + apiVersion: apps/v1 + kind: Deployment + name: novisync-web-react-front-prod + minReplicas: 1 + maxReplicas: 5 + targetCPUUtilizationPercentage: 75