From 9dd76a739de23be334d35851a32b6257ab61e2af Mon Sep 17 00:00:00 2001 From: George Kalampokis Date: Thu, 24 Sep 2020 12:37:03 +0300 Subject: [PATCH 1/4] If RDA Export fail show properly an error message --- .../src/main/java/eu/eudat/controllers/DMPs.java | 6 +++++- .../ui/dmp/overview/dmp-overview.component.ts | 16 ++++++++++++---- 2 files changed, 17 insertions(+), 5 deletions(-) diff --git a/dmp-backend/web/src/main/java/eu/eudat/controllers/DMPs.java b/dmp-backend/web/src/main/java/eu/eudat/controllers/DMPs.java index f8d8c2445..6bfbf7c08 100644 --- a/dmp-backend/web/src/main/java/eu/eudat/controllers/DMPs.java +++ b/dmp-backend/web/src/main/java/eu/eudat/controllers/DMPs.java @@ -173,8 +173,12 @@ public class DMPs extends BaseController { @RequestMapping(method = RequestMethod.GET, value = {"rda/{id}"}) public @ResponseBody - ResponseEntity getRDAJsonDocument(@PathVariable String id, @ClaimedAuthorities(claims = {Authorities.ADMIN, Authorities.MANAGER, Authorities.USER, Authorities.ANONYMOUS}) Principal principal) throws IOException { + ResponseEntity getRDAJsonDocument(@PathVariable String id, @ClaimedAuthorities(claims = {Authorities.ADMIN, Authorities.MANAGER, Authorities.USER, Authorities.ANONYMOUS}) Principal principal) { + try { return this.dataManagementPlanManager.getRDAJsonDocument(id, datasetManager, principal); + } catch (Exception e) { + return ResponseEntity.status(HttpStatus.EXPECTATION_FAILED).body(new ResponseItem<>().message(e.getMessage()).status(ApiMessageCode.ERROR_MESSAGE)); + } } @RequestMapping(method = RequestMethod.GET, value = {"/getPDF/{id}"}) diff --git a/dmp-frontend/src/app/ui/dmp/overview/dmp-overview.component.ts b/dmp-frontend/src/app/ui/dmp/overview/dmp-overview.component.ts index d480a4e44..8405fcd98 100644 --- a/dmp-frontend/src/app/ui/dmp/overview/dmp-overview.component.ts +++ b/dmp-frontend/src/app/ui/dmp/overview/dmp-overview.component.ts @@ -352,11 +352,19 @@ export class DmpOverviewComponent extends BaseComponent implements OnInit { downloadJson(id: string) { this.dmpService.downloadJson(id) .pipe(takeUntil(this._destroyed)) - .subscribe(response => { - const blob = new Blob([response.body], { type: 'application/json' }); - const filename = this.getFilenameFromContentDispositionHeader(response.headers.get('Content-Disposition')); + .subscribe(complete => { + const blob = new Blob([complete.body], { type: 'application/json' }); + const filename = this.getFilenameFromContentDispositionHeader(complete.headers.get('Content-Disposition')); FileSaver.saveAs(blob, filename); - }) + }, async error => { + this.onExportCallbackError(error); + }); + } + + async onExportCallbackError(error: any) { + const errorJsonText = await error.error.text(); + const errorObj = JSON.parse(errorJsonText); + this.uiNotificationService.snackBarNotification(errorObj.message, SnackBarNotificationLevel.Error); } getFilenameFromContentDispositionHeader(header: string): string { From fe05ac9770eaf81cba9217ac8a82117ee6154186 Mon Sep 17 00:00:00 2001 From: Diamantis Tziotzios Date: Thu, 24 Sep 2020 17:20:33 +0300 Subject: [PATCH 2/4] 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 From 28feacc7effd8ef9fedfc264d8fdee0c95c24704 Mon Sep 17 00:00:00 2001 From: Diamantis Tziotzios Date: Thu, 24 Sep 2020 17:25:08 +0300 Subject: [PATCH 3/4] CI Update --- dmp-backend/Dockerfile.CI | 1 - 1 file changed, 1 deletion(-) diff --git a/dmp-backend/Dockerfile.CI b/dmp-backend/Dockerfile.CI index 323e2ba36..944713adf 100644 --- a/dmp-backend/Dockerfile.CI +++ b/dmp-backend/Dockerfile.CI @@ -3,7 +3,6 @@ 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/ From 38f550542a0646acc548f812c330d071c98b22b0 Mon Sep 17 00:00:00 2001 From: Diamantis Tziotzios Date: Thu, 24 Sep 2020 17:37:32 +0300 Subject: [PATCH 4/4] CI update --- Jenkinsfile | 52 +++++++++++++++++++------------------- dmp-frontend/tsconfig.json | 1 + 2 files changed, 27 insertions(+), 26 deletions(-) diff --git a/Jenkinsfile b/Jenkinsfile index fdaa2a542..40de9c9ea 100644 --- a/Jenkinsfile +++ b/Jenkinsfile @@ -27,35 +27,35 @@ pipeline { } } } - 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('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') { + docker.withRegistry('http://drepo.local.cite.gr', 'b2c651c1-9a3b-4a98-a6da-e1dd7a20f512') { pipelineContext.apiImage.push() pipelineContext.webappImage.push() } diff --git a/dmp-frontend/tsconfig.json b/dmp-frontend/tsconfig.json index 5d5ba689a..4d05665e4 100644 --- a/dmp-frontend/tsconfig.json +++ b/dmp-frontend/tsconfig.json @@ -10,6 +10,7 @@ "emitDecoratorMetadata": true, "experimentalDecorators": true, "importHelpers": true, + "skipLibCheck": true, "target": "es2015", "typeRoots": [ "node_modules/@types"