diff --git a/.gitignore b/.gitignore index 0a16fa7..e095c17 100644 --- a/.gitignore +++ b/.gitignore @@ -72,3 +72,4 @@ fabric.properties # Android studio 3.1+ serialized cache file .idea/caches/build_file_checksums.ser +/.idea/sonarlint/ diff --git a/.idea/gitlab-ci-templates.iml b/.idea/gitlab-ci-templates.iml index d6ebd48..2576ae6 100644 --- a/.idea/gitlab-ci-templates.iml +++ b/.idea/gitlab-ci-templates.iml @@ -2,7 +2,9 @@ - + + + diff --git a/.idea/sonarlint/issuestore/2/e/2eef21b10116aab77b6b014cb5adf007d2d2e128 b/.idea/sonarlint/issuestore/2/e/2eef21b10116aab77b6b014cb5adf007d2d2e128 deleted file mode 100644 index e69de29..0000000 diff --git a/.idea/sonarlint/issuestore/index.pb b/.idea/sonarlint/issuestore/index.pb deleted file mode 100644 index 201e7fb..0000000 --- a/.idea/sonarlint/issuestore/index.pb +++ /dev/null @@ -1,3 +0,0 @@ - -A -publish-image.yml,2/e/2eef21b10116aab77b6b014cb5adf007d2d2e128 \ No newline at end of file diff --git a/publish-image.yml b/container-publish.yml similarity index 83% rename from publish-image.yml rename to container-publish.yml index cb09eb4..51d1b55 100644 --- a/publish-image.yml +++ b/container-publish.yml @@ -4,6 +4,9 @@ rules: - if: $CI_COMMIT_TAG variables: + DOCKER_REGISTRY: $CI_REGISTRY + DOCKER_REGISTRY_USER: $CI_REGISTRY_USER + DOCKER_REGISTRY_PASSWORD: $CI_REGISTRY_PASSWORD MVN_VERSION: "true" script: - export PARSED_VERSION=$(echo $CI_COMMIT_TAG | sed -r 's/\+/_/g') # Replace + sign since this is not valid in a docker tag @@ -14,8 +17,9 @@ fi - mvn $MAVEN_CLI_OPTS compile jib:build "-DskipTests" - "-Djib.to.auth.username=$CI_REGISTRY_USER" - "-Djib.to.auth.password=$CI_REGISTRY_PASSWORD" + "-Djib.to.image=$DOCKER_REGISTRY:$PARSED_VERSION" + "-Djib.to.auth.username=$DOCKER_REGISTRY_USER" + "-Djib.to.auth.password=$DOCKER_REGISTRY_PASSWORD" .publish-image-kaniko: image: diff --git a/container-scan.yml b/container-scan.yml new file mode 100644 index 0000000..df6734a --- /dev/null +++ b/container-scan.yml @@ -0,0 +1,34 @@ +.scan-container-jib: + image: $MAVEN_IMAGE + stage: test + variables: + TRIVY_VERSION: 0.18.3 + EXITCODE_ON_HIGH: 1 + EXITCODE_ON_CRITICAL: 1 + before_script: + - curl -L "https://github.com/aquasecurity/trivy/releases/download/v${TRIVY_VERSION}/trivy_${TRIVY_VERSION}_Linux-64bit.tar.gz" --output trivy_${TRIVY_VERSION}_Linux-64bit.tar.gz + - tar zxvf trivy_${TRIVY_VERSION}_Linux-64bit.tar.gz + script: + - mvn $MAVEN_CLI_OPTS compile jib:buildTar -DskipTests + - ./trivy --exit-code $EXITCODE_ON_HIGH --severity HIGH --no-progress --auto-refresh --input target/jib-image.tar + - ./trivy --exit-code $EXITCODE_ON_CRITICAL --severity CRITICAL --no-progress --auto-refresh --input target/jib-image.tar + +.scan-container-kaniko: + stage: test + image: + name: gcr.io/kaniko-project/executor:debug + entrypoint: [ "" ] + variables: + TRIVY_VERSION: 0.18.3 + PROJECT_DIR: $CI_PROJECT_DIR + DOCKERFILE_LOCATION: $CI_PROJECT_DIR/Dockerfile + CONTEXT_LOCATION: $CI_PROJECT_DIR + EXITCODE_ON_HIGH: 1 + EXITCODE_ON_CRITICAL: 1 + before_script: + - wget "https://github.com/aquasecurity/trivy/releases/download/v${TRIVY_VERSION}/trivy_${TRIVY_VERSION}_Linux-64bit.tar.gz" + - tar zxvf trivy_${TRIVY_VERSION}_Linux-64bit.tar.gz + script: + - /kaniko/executor --context $CONTEXT_LOCATION --dockerfile $DOCKERFILE_LOCATION --cache-dir cache/image --tarPath image.tar --no-push --destination image + - ./trivy --exit-code $EXITCODE_ON_HIGH --severity HIGH --no-progress --auto-refresh --input image.tar + - ./trivy --exit-code $EXITCODE_ON_CRITICAL --severity CRITICAL --no-progress --auto-refresh --input image.tar diff --git a/documentation/chapters/generalInformation.adoc b/documentation/chapters/generalInformation.adoc index 2b47efc..24fb4c7 100644 --- a/documentation/chapters/generalInformation.adoc +++ b/documentation/chapters/generalInformation.adoc @@ -23,7 +23,8 @@ include: - 'npm-dependencies-template.yml' - 'npm-lint-template.yml' - 'npm-test-template.yml' - - 'publish-image.yml' + - 'container-publish.yml' + - 'container-scan.yml' - 'set-version-template.yml' - 'sonar-template.yml' diff --git a/documentation/chapters/templates/container-publish.adoc b/documentation/chapters/templates/container-publish.adoc new file mode 100644 index 0000000..c90abce --- /dev/null +++ b/documentation/chapters/templates/container-publish.adoc @@ -0,0 +1,18 @@ +:sourcedir: ../../../ + += Container-Publish + +Baut mithilfe von jib oder kaniko ein Docker Image und läd das Image in der Docker Registry des Projekts hoch. +Dieser Schritt wird nur ausgeführt, wenn ein Tag gesetzt wird. + +.Variables +|=== +|Name |Description | Default Value +|MVN_VERSION | Bestimmt, ob die version von MAVEN gesetzt werden soll. +Falls das Projekt aus mehreren Poms besteht, kann `before_script:` benutzt werden. | "true" +|=== + +.sonar-template +---- +include::{sourcedir}/container-publish.yml[] +---- \ No newline at end of file diff --git a/documentation/chapters/templates/container-scan.adoc b/documentation/chapters/templates/container-scan.adoc new file mode 100644 index 0000000..2dc3a1d --- /dev/null +++ b/documentation/chapters/templates/container-scan.adoc @@ -0,0 +1,22 @@ +:sourcedir: ../../../ + += Container-Scan + +Baut ein Image mithilfe von jib oder Kaniko welches im Anschluss gescanned wird. Dieser Schritt wird ausgeführt, wenn ein Tag gesetzt wird. Die Ergebnisse des Scans können genutzt werden den Build failen zu lassen, falls gewünscht (vgl. `EXITCODE_ON_HIGH` und `EXITCODE_ON_CRITICAL`). + +.Variables +|=== +|Name |Description | Default Value +|TRIVY_VERSION | Version von Trivy die benutzt werden soll. +|EXITCODE_ON_HIGH | Bestimmt den Exit code der ausgegeben werden soll, wenn ein CVE der als HIGH markiert wurde, gefunden werden konnte. +Wenn 0 benutzt wird, läuft die CI weiter. +Benutzte `allow_failure: true` damit die CI weiter läuft aber ein Failure angezeigt wird. +|EXITCODE_ON_CRITICAL | Bestimmt den Exit code der ausgegeben werden soll, wenn ein CVE der als CRITICAL markiert wurde, gefunden werden konnte. +Wenn 0 benutzt wird, läuft die CI weiter. +Benutzte `allow_failure: true` damit die CI weiter läuft aber ein Failure angezeigt wird. +|=== + +.sonar-template +---- +include::{sourcedir}/container-scan.yml[] +---- \ No newline at end of file diff --git a/documentation/chapters/templates/publish-image.adoc b/documentation/chapters/templates/publish-image.adoc deleted file mode 100644 index 2c2fa41..0000000 --- a/documentation/chapters/templates/publish-image.adoc +++ /dev/null @@ -1,18 +0,0 @@ -:sourcedir: ../../../ - -= Publish-Image-jib - -Baut mithilfe von jib ein Docker Image und läd es in der Docker Registry des Projekt hoch. -Dieser Schritt wird nur ausgeführt, wenn ein Tag gesetzt wird. - -.Variables -|=== -|Name |Description | Default Value -|MVN_VERSION | Bestimmt, ob die version von MAVEN gesetzt werden soll. -Falls das Projekt aus mehreren Poms besteht, kann `bevor_script:` benutzt werden. | "true" -|=== - -.sonar-template ----- -include::{sourcedir}/publish-image.yml[] ----- \ No newline at end of file diff --git a/documentation/chapters/templates/sonar-template.adoc b/documentation/chapters/templates/sonar-template.adoc deleted file mode 100644 index dd5e6d7..0000000 --- a/documentation/chapters/templates/sonar-template.adoc +++ /dev/null @@ -1,17 +0,0 @@ -:sourcedir: ../../../ - -= sonar-template - -Ruft den Sonar Job für das Projekt auf. -Mehr Details zu finden hier: https://gitlab.exxcellent.de/gilden/ci/exxcellent-sonar-tool[Gilde CI/CD: exxcellent-sonar-tool]. - -.Variables -|=== -|Name |Description | Default Value -|SONAR_PROJECT_KEY | Der Sonar-Projekt-Key. | "" -|=== - -.sonar-template ----- -include::{sourcedir}/sonar-template.yml[] ----- \ No newline at end of file diff --git a/documentation/document.adoc b/documentation/document.adoc index 65a24ae..c783dfb 100644 --- a/documentation/document.adoc +++ b/documentation/document.adoc @@ -36,8 +36,8 @@ include::chapters/generalInformation.adoc[leveloffset=1] == Misc Templates -include::chapters/templates/sonar-template.adoc[leveloffset=1] -include::chapters/templates/publish-image.adoc[leveloffset=1] +include::chapters/templates/container-publish.adoc[leveloffset=1] +include::chapters/templates/container-scan.adoc[leveloffset=1] == NPM Templates @@ -50,4 +50,8 @@ include::chapters/templates/npm-test-template.adoc[leveloffset=1] include::chapters/templates/maven-dependencies-template.adoc[leveloffset=1] include::chapters/templates/maven-build-template.adoc[leveloffset=1] -include::chapters/templates/maven-verify-template.adoc[leveloffset=1] \ No newline at end of file +include::chapters/templates/maven-verify-template.adoc[leveloffset=1] + +== Tools + +Weitere Templates für die Tools der CI Gilde, sind in den jeweiligen Repos zu finden. \ No newline at end of file