diff --git a/Jenkinsfile b/Jenkinsfile index 7c7a857..04cebd2 100644 --- a/Jenkinsfile +++ b/Jenkinsfile @@ -1,35 +1,73 @@ -pipeline { - agent any - environment { - DOCKERHUB_CREDENTIALS = credentials('valaxy-dockerhub') - } - stages { - stage('SCM Checkout') { - steps{ - git 'https://github.com/ravdy/nodejs-demo.git' - } +podTemplate(yaml: ''' + apiVersion: v1 + kind: Pod + spec: + containers: + - name: nodejs + image: node:6-alpine + command: + - sleep + args: + - 999999 + - name: kubectl + image: bitnami/kubectl + command: + - sleep + args: + - 9999999 + - name: kaniko + image: gcr.io/kaniko-project/executor:debug + command: + - sleep + args: + - 9999999 + volumeMounts: + - name: kaniko-secret + mountPath: /kaniko/.docker + restartPolicy: Never + volumes: + - name: kaniko-secret + secret: + secretName: dockercred + items: + - key: .dockerconfigjson + path: config.json +''') { + + node(POD_LABEL) { + stage('Get a nodejs project') { + git url: 'https://github.com/PottaAkhil/nodejs-OBT.git', branch: 'master' + container('nodejs') { + stage('Build a nodejs project') { + sh ''' + echo pwd + ''' } + } + } + stage('SonarQube analysis') { + def scannerHome = tool 'sonarqube'; + withSonarQubeEnv('sonarqube') { + sh "${scannerHome}/bin/sonar-scanner \ + -D sonar.login=admin \ + -D sonar.password=admin \ + -D sonar.projectKey= nodejs \ + -D sonar.exclusions=vendor/**,resources/**,**/*.js \ + -D sonar.host.url=http://54.169.237.40:9000/" + } + } - stage('Build docker image') { - steps { - sh 'docker build -t valaxy/nodeapp:$BUILD_NUMBER .' - } - } - stage('login to dockerhub') { - steps{ - sh 'echo $DOCKERHUB_CREDENTIALS_PSW | docker login -u $DOCKERHUB_CREDENTIALS_USR --password-stdin' - } - } - stage('push image') { - steps{ - sh 'docker push valaxy/nodeapp:$BUILD_NUMBER' - } - } -} -post { - always { - sh 'docker logout' + stage('Build nodejs Image') { + container('kaniko') { + stage('Build a Go project') { + sh ''' + /kaniko/executor --context `pwd` --destination 957288871734.dkr.ecr.ap-southeast-1.amazonaws.com/images:$BUILD_NUMBER && \ + /kaniko/executor --context `pwd` --destination 957288871734.dkr.ecr.ap-southeast-1.amazonaws.com/images:latest + ''' } + } } + + +} } - diff --git a/deploymentservice.yaml b/deploymentservice.yaml new file mode 100644 index 0000000..2e27c7e --- /dev/null +++ b/deploymentservice.yaml @@ -0,0 +1,41 @@ +apiVersion: apps/v1 +kind: Deployment +metadata: + name: nodejs-k8s-Deployment + labels: + app: nodejs-k8s + annotations: + fluxcd.io/automated: "true" +spec: + selector: + matchLabels: + app: nodejs-k8s + replicas: 3 + strategy: + type: RollingUpdate + template: + metadata: + labels: + app: nodejs-k8s + spec: + containers: + - name: nodejs-k8s + image: 957288871734.dkr.ecr.ap-southeast-1.amazonaws.com/images + ports: + - containerPort: 80 + protocol: TCP + imagePullPolicy: Always + +apiVersion: v1 +kind: Service +metadata: + name: nodejs-k8ssvc +spec: + selector: + app: nodejst-k8s + type: LoadBalancer + ports: + - protocol: "TCP" + port: 8080 + targetPort: 8080 + type: NodePort diff --git a/download NLB & jenkins b/download NLB & jenkins new file mode 100644 index 0000000..2f61d40 --- /dev/null +++ b/download NLB & jenkins @@ -0,0 +1,2 @@ +https://kubernetes.github.io/ingress-nginx/deploy/#digital-ocean ==== to download the Ngnix Load Balancer and attach it to the node +https://devopscube.com/jenkins-build-agents-kubernetes/ -setup jekins agent on diff --git a/flux.yaml b/flux.yaml new file mode 100644 index 0000000..2daede2 --- /dev/null +++ b/flux.yaml @@ -0,0 +1,37 @@ +apiVersion: apps/v1 +kind: Deployment +metadata: + name: awsome-app-flux + labels: + app: awsome-app-flux + annotations: + fluxcd.io/automated: "true" +spec: + replicas: 1 + selector: + matchLabels: + app: awsome-app-flux + template: + metadata: + labels: + app: awsome-app-flux + spec: + containers: + - name: awsome-app-flux + image: 957288871734.dkr.ecr.ap-southeast-1.amazonaws.com/images:latest + ports: + - containerPort: 8080 + +--- + +apiVersion: v1 +kind: Service +metadata: + name: awsome-app-flux-svc +spec: + selector: + app: awsome-app-flux + ports: + - protocol: "TCP" + port: 80 + targetPort: 3000 diff --git a/ingress.yaml b/ingress.yaml new file mode 100644 index 0000000..ca42587 --- /dev/null +++ b/ingress.yaml @@ -0,0 +1,20 @@ +apiVersion: networking.k8s.io/v1 +kind: Ingress +metadata: + name: simple-ingress + annotations: + kubernetes.io/ingress.class: nginx + alb.ingress.kubernetes.io/scheme: internet-facing + alb.ingress.kubernetes.io/target-type: ip +spec: + rules: + - host: + http: + paths: + - path: / + pathType: Prefix + backend: + service: + name: awsome-app-flux-svc + port: + number: 80 diff --git a/nodeapp/index.js b/nodeapp/index.js index 8b51bcb..cb8df4b 100644 --- a/nodeapp/index.js +++ b/nodeapp/index.js @@ -2,7 +2,7 @@ var express = require('express'); var app = express(); app.get('/', function (req, res) { - res.send('{ "response": "Hello, Welcome to Valaxy" }'); + res.send('{ "response": "Hello, Welcome to Minfy" }'); }); app.get('/will', function (req, res) {