From 5258de6cc6eff3966d072d7ab52b7754bcefe188 Mon Sep 17 00:00:00 2001
From: Emmanuel Bruno <emmanuel.bruno@univ-tln.fr>
Date: Wed, 15 Dec 2021 18:52:06 +0100
Subject: [PATCH] initial sonar.

---
 .github/workflows/docker-image.yml            | 18 +++++++----------
 docker-compose.yml                            |  5 +++++
 docker/Dockerfile                             | 20 ++++++++++++++++---
 .../settings-docker.xml                       |  2 +-
 4 files changed, 30 insertions(+), 15 deletions(-)
 rename .github/ci-settings.xml => docker/settings-docker.xml (93%)

diff --git a/.github/workflows/docker-image.yml b/.github/workflows/docker-image.yml
index 07af7d2..fb2e064 100644
--- a/.github/workflows/docker-image.yml
+++ b/.github/workflows/docker-image.yml
@@ -18,14 +18,10 @@ jobs:
     steps:
     - uses: actions/checkout@v2
     - name: Build the Docker image for branch ${GITHUB_REF##*/}
-      run: DOCKER_BUILDKIT=1 docker build . --file ./docker/Dockerfile --tag brunoe/samplejee91::${GITHUB_REF##*/}
-
-
-  maven-sonar:
-    runs-on: [ self-hosted, Linux ]
-    needs: maven-build
-    # Develop branch only
-    # if: github.ref == 'refs/heads/develop'
-    steps:
-      - name: Launch a sonar analysis
-        run: ./mvn.sh -D sonar.branch.name=${GITHUB_REF#refs/heads/} --activate-profiles sonar sonar:sonar && mvn --activate-profiles sonar -pl . sonar-quality-gate:check
+      run: DOCKER_BUILDKIT=1 docker build . \
+            --env GITHUBLOGIN="$GITHUBLOGIN" \
+            --env GITHUBPASSWORD="$GITHUBPASSWORD" \
+            --env SONAR_HOST="$SONAR_HOST" \
+            --env SONAR_TOKEN="$SONAR_TOKEN" \
+            --file ./docker/Dockerfile \
+            --tag brunoe/samplejee91:${GITHUB_REF##*/}
diff --git a/docker-compose.yml b/docker-compose.yml
index efa6f90..87c0dee 100644
--- a/docker-compose.yml
+++ b/docker-compose.yml
@@ -2,6 +2,11 @@ version: '3'
 services:
   jakartaEE:
     build:
+      args:
+        - GITHUBLOGIN
+        - GITHUBPASSWORD
+        - SONAR_HOST
+        - SONAR_TOKEN
       context: .
       dockerfile: docker/Dockerfile
     image: brunoe/samplejee91
diff --git a/docker/Dockerfile b/docker/Dockerfile
index fb51ae3..8cf64ea 100644
--- a/docker/Dockerfile
+++ b/docker/Dockerfile
@@ -1,13 +1,27 @@
-# syntax=docker/dockerfile:1.3
-
 ### First we build the application in docker in a controlled env
 FROM maven:3.8.4-eclipse-temurin-11 as build
 WORKDIR /app
+
+#see https://www.jrebel.com/blog/how-to-speed-up-your-maven-build
+# see https://www.baeldung.com/jvm-tiered-compilation
+ENV MAVEN_OPTS="-XX:+TieredCompilation -XX:TieredStopAtLevel=1"
+#ENV MAVEN_CLI_OPTS="-T 1C --settings /usr/share/maven/ref/settings-docker.xml -B"
+ENV MAVEN_CLI_OPTS="--settings /usr/share/maven/ref/settings-docker.xml -B"
+
+COPY docker/settings-docker.xml /usr/share/maven/ref/
+
 # COPY pom.xml /app/pom.xml
 COPY . /app/
 
 RUN --mount=type=cache,id=mvncache,target=/root/.m2/repository,rw \
-	mvn -B verify
+	mvn $MAVEN_CLI_OPTS -Dmaven.test.skip=true verify
+
+RUN --mount=type=cache,id=mvncache,target=/root/.m2/repository,rw \
+    if [ "$SONAR_TOKEN" ] ; then \
+      mvn $MAVEN_CLI_OPTS -D sonar.branch.name=${GITHUB_REF#refs/heads/} \
+        --activate-profiles sonar sonar:sonar && \
+      mvn $MAVEN_CLI_OPTS --activate-profiles sonar -pl . sonar-quality-gate:check ; \
+    fi
 
 ### Then we add the builded war to a JEE server.
 #FROM payara/server-full:5.2021.9-jdk11 as server
diff --git a/.github/ci-settings.xml b/docker/settings-docker.xml
similarity index 93%
rename from .github/ci-settings.xml
rename to docker/settings-docker.xml
index c2019e0..fc533f8 100644
--- a/.github/ci-settings.xml
+++ b/docker/settings-docker.xml
@@ -28,7 +28,7 @@
         <profile>
             <id>sonar</id>
             <properties>
-                <sonar.host.url>http://compute-lsis-2:9000</sonar.host.url>
+                <sonar.host.url>${env.SONAR_HOST}</sonar.host.url>
                 <sonar.login>${env.SONAR_TOKEN}</sonar.login>
             </properties>
         </profile>
-- 
GitLab