From fe05ac9770eaf81cba9217ac8a82117ee6154186 Mon Sep 17 00:00:00 2001 From: Diamantis Tziotzios Date: Thu, 24 Sep 2020 17:20:33 +0300 Subject: [PATCH] jenkins files --- Jenkinsfile | 66 ++++++++++++++++++++++++++++++++++++++ dmp-backend/Dockerfile.CI | 16 +++++++++ dmp-frontend/Dockerfile.CI | 31 ++++++++++++++++++ dmp-frontend/nginx.conf.CI | 28 ++++++++++++++++ 4 files changed, 141 insertions(+) create mode 100644 Jenkinsfile create mode 100644 dmp-backend/Dockerfile.CI create mode 100644 dmp-frontend/Dockerfile.CI create mode 100644 dmp-frontend/nginx.conf.CI diff --git a/Jenkinsfile b/Jenkinsfile new file mode 100644 index 000000000..fdaa2a542 --- /dev/null +++ b/Jenkinsfile @@ -0,0 +1,66 @@ +def pipelineContext = [:] + +pipeline { + agent any + + options { + skipDefaultCheckout(true) + } + + stages { + stage('Checkout') { + steps { + checkout scm + } + } + stage('Build API') { + steps { + script { + pipelineContext.apiImage = docker.build("open-dmp-api:${env.BUILD_ID}", "-f dmp-backend/Dockerfile.CI dmp-backend/") + } + } + } + stage('Build WebApp') { + steps { + script { + pipelineContext.webappImage = docker.build("open-dmp-webapp:${env.BUILD_ID}", "-f dmp-frontend/Dockerfile.CI dmp-frontend/") + } + } + } + stage('SonarQube analysis') { + steps { + script { + def scannerHome = tool 'SonarQube Scanner 4.3'; + withSonarQubeEnv('SonarQube') { // If you have configured more than one global server connection, you can specify its name + sh "${scannerHome}/bin/sonar-scanner" + } + } + } + } + // waiting for sonar results based into the configured web hook in Sonar server which push the status back to jenkins + stage('SonarQube scan result check') { + steps { + timeout(time: 2, unit: 'MINUTES') { + retry(3) { + script { + def qg = waitForQualityGate() + if (qg.status != 'OK') { + error "Pipeline aborted due to quality gate failure: ${qg.status}" + } + } + } + } + } + } + stage('Pushing to Docker Registry') { + steps { + script { + docker.withRegistry('https://registry.home-server', '1e8e4c8e-c709-4475-ab14-8d079a36914a') { + pipelineContext.apiImage.push() + pipelineContext.webappImage.push() + } + } + } + } + } +} \ No newline at end of file diff --git a/dmp-backend/Dockerfile.CI b/dmp-backend/Dockerfile.CI new file mode 100644 index 000000000..323e2ba36 --- /dev/null +++ b/dmp-backend/Dockerfile.CI @@ -0,0 +1,16 @@ +FROM maven:3-jdk-8-alpine AS MAVEN_BUILD + +COPY pom.xml /build/ +COPY data /build/data/ +COPY elastic /build/elastic/ +COPY logging /build/logging/ +COPY queryable /build/queryable/ +COPY web /build/web/ + +WORKDIR /build/ +RUN mvn package + +FROM openjdk:8-jre-alpine +WORKDIR /app +COPY --from=MAVEN_BUILD /build/web/target/web-1.0-SNAPSHOT.jar /app/app.jar +ENTRYPOINT ["java","-Djava.security.egd=file:/dev/./urandom" ,"-Dspring.profiles.active=${PROF}","-jar","/app.jar"] \ No newline at end of file diff --git a/dmp-frontend/Dockerfile.CI b/dmp-frontend/Dockerfile.CI new file mode 100644 index 000000000..b9d0860ec --- /dev/null +++ b/dmp-frontend/Dockerfile.CI @@ -0,0 +1,31 @@ +# stage1 as builder +FROM node:12-alpine as builder + +# copy the package.json to install dependencies +COPY package.json ./ + +# Install the dependencies and make the folder +RUN npm install && mkdir /src && mv ./node_modules ./src + +WORKDIR /src + +COPY . . + +# Build the project and copy the files +RUN npm run ng build -- --deploy-url=/ --prod + +FROM nginx:alpine + +#!/bin/sh + +COPY nginx.conf.CI /etc/nginx/nginx.conf + +## Remove default nginx index page +RUN rm -rf /usr/share/nginx/html/* + +# Copy from the stahg 1 +COPY --from=builder /src/dist /usr/share/nginx/html + +EXPOSE 8080 + +ENTRYPOINT ["nginx", "-g", "daemon off;"] \ No newline at end of file diff --git a/dmp-frontend/nginx.conf.CI b/dmp-frontend/nginx.conf.CI new file mode 100644 index 000000000..63cee1859 --- /dev/null +++ b/dmp-frontend/nginx.conf.CI @@ -0,0 +1,28 @@ +server { + + listen 8080; + + sendfile on; + + default_type application/octet-stream; + + + gzip on; + gzip_http_version 1.1; + gzip_disable "MSIE [1-6]\."; + gzip_min_length 1100; + gzip_vary on; + gzip_proxied expired no-cache no-store private auth; + gzip_types text/plain text/css application/json application/javascript application/x-javascript text/xml application/xml application/xml+rss text/javascript; + gzip_comp_level 9; + + + root /usr/share/nginx/html; + + + location / { + try_files $uri $uri/ /index.html =404; + add_header Cache-Control "no-store, no-cache, must-revalidate"; + } + +} \ No newline at end of file