From 052e530ef9a095e62ca5c774a44b94a1ca710511 Mon Sep 17 00:00:00 2001 From: kytay Date: Sat, 29 Oct 2022 14:10:47 +0000 Subject: [PATCH] feat: sonar-node-plugin - sonar-scanner based on node:lts-alpine --- sonar-node-plugin/Dockerfile | 18 ++++++++++++++++ sonar-node-plugin/docker-entrypoint.sh | 29 ++++++++++++++++++++++++++ 2 files changed, 47 insertions(+) create mode 100644 sonar-node-plugin/Dockerfile create mode 100644 sonar-node-plugin/docker-entrypoint.sh diff --git a/sonar-node-plugin/Dockerfile b/sonar-node-plugin/Dockerfile new file mode 100644 index 0000000..542c686 --- /dev/null +++ b/sonar-node-plugin/Dockerfile @@ -0,0 +1,18 @@ +FROM node:lts-alpine + +ENV SONAR_VERSION=4.7.0.2747 +ENV SONAR_SCANNER_CLI=sonar-scanner-cli-${SONAR_VERSION} +ENV SONAR_SCANNER=sonar-scanner-${SONAR_VERSION} + +RUN apk add bash curl openjdk11-jre-headless + +RUN curl https://binaries.sonarsource.com/Distribution/sonar-scanner-cli/${SONAR_SCANNER_CLI}.zip -so /opt/${SONAR_SCANNER_CLI}.zip && \ +unzip -d /opt /opt/${SONAR_SCANNER_CLI}.zip && \ +rm /opt/${SONAR_SCANNER_CLI}.zip + +COPY docker-entrypoint.sh /usr/bin/docker-entrypoint.sh +RUN chmod +x /usr/bin/docker-entrypoint.sh + +ENV PATH=$PATH:/opt/${SONAR_SCANNER}/bin + +ENTRYPOINT ["/usr/bin/docker-entrypoint.sh"] \ No newline at end of file diff --git a/sonar-node-plugin/docker-entrypoint.sh b/sonar-node-plugin/docker-entrypoint.sh new file mode 100644 index 0000000..d567ba1 --- /dev/null +++ b/sonar-node-plugin/docker-entrypoint.sh @@ -0,0 +1,29 @@ +#!/bin/bash + +JAVA_OPTS="" + +if [[ -n "PLUGIN_SONAR_HOST" ]]; then + JAVA_OPTS+=" -Dsonar.host.url=${PLUGIN_SONAR_HOST}" +fi + +if [[ -n "PLUGIN_SONAR_TOKEN" ]]; then + JAVA_OPTS+=" -Dsonar.login=${PLUGIN_SONAR_TOKEN}" + +elif [[ -n "PLUGIN_SONAR_LOGIN" && -n "PLUGIN_SONAR_PASSWORD" ]]; then + JAVA_OPTS+=" -Dsonar.login=${PLUGIN_SONAR_LOGIN} -Dsonar.password=${PLUGIN_SONAR_PASSWORD}" + echo "Using authentication token is encouraged for security reasons. Refer to https://docs.sonarqube.org/latest/user-guide/user-token/" +fi + +if [[ -n "PLUGIN_SONAR_LOGLEVEL" ]]; then + JAVA_OPTS+=" -Dsonar.log.level=${PLUGIN_SONAR_LOGLEVEL}" +fi + +if [[ -n "PLUGIN_SONAR_PROJECT_SETTINGS" ]]; then + JAVA_OPTS+=" -Dproject.settings=${PLUGIN_SONAR_PROJECT_SETTINGS}" +fi + +if [[ -n "PLUGIN_SONAR_DEBUG" && ${PLUGIN_SONAR_DEBUG} == "true" ]]; then + JAVA_OPTS+=" -X" +fi + +sonar-scanner ${JAVA_OPTS} \ No newline at end of file