From ce4844c06c712d7fee7653a6044145ab64ca839e Mon Sep 17 00:00:00 2001 From: Daya Adianto <dayaadianto@cs.ui.ac.id> Date: Sat, 7 Sep 2019 09:01:44 +0700 Subject: [PATCH 1/5] Write pseudocode (#7) As I am currently working offline, I only write the pseudocode first. --- .devcontainer/Dockerfile | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/.devcontainer/Dockerfile b/.devcontainer/Dockerfile index 8fcb253..89a0d62 100644 --- a/.devcontainer/Dockerfile +++ b/.devcontainer/Dockerfile @@ -42,8 +42,14 @@ RUN wget -O /usr/local/bin/hadolint https://github.com/hadolint/hadolint/release # Configure shellcheck ARG SHELLCHECK_VERSION=latest + +## TODO Download shellcheck archive file to a directory RUN wget -O /usr/local/bin/shellcheck https://shellcheck.storage.googleapis.com/shellcheck-${SHELLCHECK_VERSION}.linux.x86_64.tar.xz \ && chmod +x /usr/local/bin/shellcheck +## TODO Extract the archive file +## TODO Change working directory into the bin directory +## TODO Move the binary executable into /usr/local/bin +## TODO Change shellcheck executable flag to active (chmod +x) # Switch back to dialog for any ad-hoc use of apt-get ENV DEBIAN_FRONTEND='' -- GitLab From d813cf9438c3bda6ff72fbaefa4bbefcd21eab3f Mon Sep 17 00:00:00 2001 From: Daya Adianto <dayaadianto@cs.ui.ac.id> Date: Sat, 7 Sep 2019 09:06:15 +0700 Subject: [PATCH 2/5] Draft README (#4) I add some notes regarding the README and also draft how to use the container image. --- README.md | 32 ++++++++++++++++++++++++++++++++ 1 file changed, 32 insertions(+) diff --git a/README.md b/README.md index 44549a2..3e08d6f 100644 --- a/README.md +++ b/README.md @@ -2,11 +2,43 @@ > Sonar Scanner CLI bundled in a container image. +## Usage + +To run the container image locally using Docker: + +```bash +docker run --rm addianto/sonar-scanner-cli:latest +``` + +To use the container image as a base image for a CI job on GitLab CI/CD: + +```yaml +SonarScanner Analysis: + image: addianto/sonar-scanner-cli:latest + # Ideally you want to run SonarScanner after the test suite has generated + # test & coverage report. The following is only an example to run + # SonarScanner concurrently with CI job(s) in `test` stage. + stage: test + script: + # Obtain the host and token from GitLab CI environment variables + - sonar-scanner + -Dsonar.host.url=$SONARQUBE_HOST + -Dsonar.login=$SONARQUBE_TOKEN + only: + # Perform SonarScanner analysis only on `master` branch + - master +``` + ## Maintainers - [Daya Adianto](https://gitlab.com/addianto) ## License +> TODO State that SonarScanner is a product made by SonarQube. I, or we, +> do not have the copyright. +> TODO State that the containerisation project is a open-source project +> that licensed under LGPL v3. + Copyright (c) 2019 Faculty of Computer Science Universitas Indonesia. Licensed under the [GNU Lesser General Public, Version 3.0](LICENSE). -- GitLab From 86328b7f10d4adee797c66a65a0822b9cc7615f4 Mon Sep 17 00:00:00 2001 From: Daya Adianto <dayaadianto@cs.ui.ac.id> Date: Fri, 13 Sep 2019 15:20:47 +0700 Subject: [PATCH 3/5] Fix shellcheck installation (#7) --- .devcontainer/Dockerfile | 16 +++++++--------- .hadolint.yaml | 1 + Dockerfile | 12 ++++++++---- 3 files changed, 16 insertions(+), 13 deletions(-) diff --git a/.devcontainer/Dockerfile b/.devcontainer/Dockerfile index 89a0d62..0ddb308 100644 --- a/.devcontainer/Dockerfile +++ b/.devcontainer/Dockerfile @@ -20,7 +20,7 @@ RUN apt-get update \ && apt-get -y install --no-install-recommends git procps lsb-release \ # # Install project-specific tools - && apt-get -y install --no-install-recommends ca-certificates wget \ + && apt-get -y install --no-install-recommends ca-certificates wget xz-utils \ # # Create a non-root user to use if preferred - see https://aka.ms/vscode-remote/containers/non-root-user. && groupadd --gid $USER_GID $USERNAME \ @@ -42,14 +42,12 @@ RUN wget -O /usr/local/bin/hadolint https://github.com/hadolint/hadolint/release # Configure shellcheck ARG SHELLCHECK_VERSION=latest - -## TODO Download shellcheck archive file to a directory -RUN wget -O /usr/local/bin/shellcheck https://shellcheck.storage.googleapis.com/shellcheck-${SHELLCHECK_VERSION}.linux.x86_64.tar.xz \ - && chmod +x /usr/local/bin/shellcheck -## TODO Extract the archive file -## TODO Change working directory into the bin directory -## TODO Move the binary executable into /usr/local/bin -## TODO Change shellcheck executable flag to active (chmod +x) +RUN wget -O /opt/shellcheck-${SHELLCHECK_VERSION}.tar.xz https://shellcheck.storage.googleapis.com/shellcheck-${SHELLCHECK_VERSION}.linux.x86_64.tar.xz \ + && cd /opt \ + && tar -xf shellcheck-${SHELLCHECK_VERSION}.tar.xz \ + && rm shellcheck-${SHELLCHECK_VERSION}.tar.xz \ + && chmod +x /opt/shellcheck-${SHELLCHECK_VERSION}/shellcheck \ + && ln -s /opt/shellcheck-${SHELLCHECK_VERSION}/shellcheck /usr/local/bin/shellcheck # Switch back to dialog for any ad-hoc use of apt-get ENV DEBIAN_FRONTEND='' diff --git a/.hadolint.yaml b/.hadolint.yaml index b138ee2..08c8a50 100644 --- a/.hadolint.yaml +++ b/.hadolint.yaml @@ -1,3 +1,4 @@ --- ignored: + - DL3003 - DL3008 \ No newline at end of file diff --git a/Dockerfile b/Dockerfile index d27c2d0..d51014e 100644 --- a/Dockerfile +++ b/Dockerfile @@ -10,7 +10,7 @@ ARG USER_GID=$USER_UID # Install packages RUN apt-get update \ - && apt-get -y install --no-install-recommends ca-certificates git nodejs unzip wget \ + && apt-get -y install --no-install-recommends ca-certificates git nodejs unzip wget xz-utils \ # Create a non-root user to use if preferred - see https://aka.ms/vscode-remote/containers/non-root-user. && groupadd --gid $USER_GID $USERNAME \ && useradd -s /bin/bash --uid $USER_UID --gid $USER_GID -m $USERNAME \ @@ -29,8 +29,12 @@ RUN wget -O sonar-scanner-cli.zip https://binaries.sonarsource.com/Distribution/ # Configure shellcheck ARG SHELLCHECK_VERSION=latest -RUN wget -O /usr/local/bin/shellcheck https://shellcheck.storage.googleapis.com/shellcheck-${SHELLCHECK_VERSION}.linux.x86_64.tar.xz \ - && chmod +x /usr/local/bin/shellcheck +RUN wget -O /opt/shellcheck-${SHELLCHECK_VERSION}.tar.xz https://shellcheck.storage.googleapis.com/shellcheck-${SHELLCHECK_VERSION}.linux.x86_64.tar.xz \ + && cd /opt \ + && tar -xf shellcheck-${SHELLCHECK_VERSION}.tar.xz \ + && rm shellcheck-${SHELLCHECK_VERSION}.tar.xz \ + && chmod +x /opt/shellcheck-${SHELLCHECK_VERSION}/shellcheck \ + && ln -s /opt/shellcheck-${SHELLCHECK_VERSION}/shellcheck /usr/local/bin/shellcheck # Switch back to dialog for any ad-hoc use of apt-get ENV DEBIAN_FRONTEND='' @@ -40,7 +44,7 @@ ENV DEBIAN_FRONTEND='' USER sonar WORKDIR /home/sonar -CMD ["/bin/bash"] +ENTRYPOINT ["sonar-scanner"] # Container image metadata ## Note to editors: metadata values for `created`, `version`, and `revision` -- GitLab From b759c58b6f5fac716fa037a361afd80f5069b940 Mon Sep 17 00:00:00 2001 From: Daya Adianto <dayaadianto@cs.ui.ac.id> Date: Fri, 13 Sep 2019 15:29:39 +0700 Subject: [PATCH 4/5] Update hadolint version in the dev container (#7) --- .devcontainer/Dockerfile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.devcontainer/Dockerfile b/.devcontainer/Dockerfile index 0ddb308..7177afc 100644 --- a/.devcontainer/Dockerfile +++ b/.devcontainer/Dockerfile @@ -36,7 +36,7 @@ RUN apt-get update \ && rm -rf /var/lib/apt/lists/* # Configure hadolint -ARG HADOLINT_VERSION=v1.17.1 +ARG HADOLINT_VERSION=v1.17.2 RUN wget -O /usr/local/bin/hadolint https://github.com/hadolint/hadolint/releases/download/${HADOLINT_VERSION}/hadolint-Linux-x86_64 \ && chmod +x /usr/local/bin/hadolint -- GitLab From 85fce594863b30f7530f9e3d7de8a8dcaf0a84fd Mon Sep 17 00:00:00 2001 From: Daya Adianto <dayaadianto@cs.ui.ac.id> Date: Fri, 13 Sep 2019 16:25:06 +0700 Subject: [PATCH 5/5] Complete README (#4) --- Dockerfile | 2 +- README.md | 28 +++++++++++++++++++++------- 2 files changed, 22 insertions(+), 8 deletions(-) diff --git a/Dockerfile b/Dockerfile index d51014e..98c25ea 100644 --- a/Dockerfile +++ b/Dockerfile @@ -42,7 +42,7 @@ ENV DEBIAN_FRONTEND='' ## Note to editors: Make sure name of USER and its WORKDIR path matches with ## the value of USERNAME above USER sonar -WORKDIR /home/sonar +WORKDIR /home/sonar/workspace ENTRYPOINT ["sonar-scanner"] diff --git a/README.md b/README.md index 3e08d6f..371a791 100644 --- a/README.md +++ b/README.md @@ -4,12 +4,27 @@ ## Usage +First, you need to have a SonarScanner properties file (e.g. [`sonar-project.properties`](sonar-project.properties)) +in current working directory. Make sure to avoid putting sensitive information +or values that might change over time in the properties file such as SonarQube's +authentication token. Those kind of values and configuration can be passed +into SonarScanner via CLI prompt. + To run the container image locally using Docker: ```bash -docker run --rm addianto/sonar-scanner-cli:latest +docker run -v $(pwd):/home/sonar/workspace addianto/sonar-scanner-cli:latest [sonar-scanner options] +``` + +Example: + +```bash +docker run -v $(pwd):/home/sonar/workspace addianto/sonar-scanner-cli:latest -Dsonar.host.url=https://pmpl.cs.ui.ac.id/sonarqube -Dsonar.login=[REDACTED] ``` +> Note: It is also possible to pass all possible SonarScanner's properties +> via CLI options. YMMV. + To use the container image as a base image for a CI job on GitLab CI/CD: ```yaml @@ -35,10 +50,9 @@ SonarScanner Analysis: ## License -> TODO State that SonarScanner is a product made by SonarQube. I, or we, -> do not have the copyright. -> TODO State that the containerisation project is a open-source project -> that licensed under LGPL v3. +[SonarScanner CLI](https://github.com/Sonarsource/sonar-scanner-cli) is a +product of [SonarSource](https://www.sonarsource.com) and licensed under the +[GNU Lesser General Public License, Version 3.0](http://www.gnu.org/licenses/lgpl.txt). -Copyright (c) 2019 Faculty of Computer Science Universitas Indonesia. Licensed -under the [GNU Lesser General Public, Version 3.0](LICENSE). +The Dockerfiles and associated scripts found in this project are licensed under +the [GNU Lesser General Public License, Version 3.0](LICENSE). -- GitLab