From 3ed5bcbcea64b8fd17ff2b64a3e558fb68f59250 Mon Sep 17 00:00:00 2001
From: Daya Adianto <dayaadianto@cs.ui.ac.id>
Date: Fri, 6 Sep 2019 09:54:19 +0700
Subject: [PATCH] Add shellcheck into the container image (#15)

Closes #15.
---
 .devcontainer/Dockerfile        | 7 ++++++-
 .devcontainer/devcontainer.json | 4 ++--
 Dockerfile                      | 9 +++++++--
 build.sh                        | 9 +--------
 4 files changed, 16 insertions(+), 13 deletions(-)

diff --git a/.devcontainer/Dockerfile b/.devcontainer/Dockerfile
index 425c153..8fcb253 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 shellcheck wget \
+    && apt-get -y install --no-install-recommends ca-certificates wget \
     #
     # Create a non-root user to use if preferred - see https://aka.ms/vscode-remote/containers/non-root-user.
     && groupadd --gid $USER_GID $USERNAME \
@@ -40,5 +40,10 @@ ARG HADOLINT_VERSION=v1.17.1
 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
 
+# 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
+
 # Switch back to dialog for any ad-hoc use of apt-get
 ENV DEBIAN_FRONTEND=''
diff --git a/.devcontainer/devcontainer.json b/.devcontainer/devcontainer.json
index 98f075b..365a86c 100644
--- a/.devcontainer/devcontainer.json
+++ b/.devcontainer/devcontainer.json
@@ -28,6 +28,6 @@
 	"extensions": [
 		"exiasr.hadolint",
 		"ms-azuretools.vscode-docker",
-		"timonwong.shellcheck",
-	],
+		"timonwong.shellcheck"
+	]
 }
\ No newline at end of file
diff --git a/Dockerfile b/Dockerfile
index e37924e..d27c2d0 100644
--- a/Dockerfile
+++ b/Dockerfile
@@ -19,7 +19,7 @@ RUN apt-get update \
     && apt-get clean -y \
     && rm -rf /var/lib/apt/lists/*
 
-# Install Sonar Scanner CLI
+# Configure Sonar Scanner CLI
 ARG SONAR_SCANNER_CLI_VERSION=4.0.0.1744
 RUN wget -O sonar-scanner-cli.zip https://binaries.sonarsource.com/Distribution/sonar-scanner-cli/sonar-scanner-cli-$SONAR_SCANNER_CLI_VERSION-linux.zip \
     && unzip sonar-scanner-cli.zip -d /opt \
@@ -27,6 +27,11 @@ RUN wget -O sonar-scanner-cli.zip https://binaries.sonarsource.com/Distribution/
     && chmod +x /opt/sonar-scanner-$SONAR_SCANNER_CLI_VERSION-linux/bin/sonar-scanner \
     && ln -s /opt/sonar-scanner-$SONAR_SCANNER_CLI_VERSION-linux/bin/sonar-scanner /usr/local/bin/sonar-scanner
 
+# 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
+
 # Switch back to dialog for any ad-hoc use of apt-get
 ENV DEBIAN_FRONTEND=''
 
@@ -43,7 +48,7 @@ CMD ["/bin/bash"]
 ## It is also possible to pass other metadata values via build arguments.
 ARG IMAGE_CREATED=""
 ARG IMAGE_SOURCE="https://gitlab.cs.ui.ac.id/pmpl/sonar-scanner-cli-image"
-ARG IMAGE_VERSION=""
+ARG IMAGE_VERSION=${SONAR_SCANNER_CLI_VERSION}
 ARG IMAGE_REVISION=""
 ARG IMAGE_VENDOR="Faculty of Computer Science Universitas Indonesia"
 ARG IMAGE_TITLE="Sonar Scanner CLI Image"
diff --git a/build.sh b/build.sh
index ecb16b5..a0898c6 100644
--- a/build.sh
+++ b/build.sh
@@ -24,19 +24,12 @@ if ! [ -n "$1" ]; then
     exit 1
 fi
 
-if ! [ -n "$2" ]; then
-    echo "Error: missing 2nd argument of $0, i.e. version of the container image." >&2
-    exit 1
-fi
-
 IMAGE_NAMESPACE="$1"
-IMAGE_VERSION="$2"
 
 docker build \
     --build-arg=IMAGE_CREATED="$(date --utc --rfc-3339=seconds)" \
-    --build-arg=IMAGE_VERSION="${IMAGE_VERSION}" \
     --build-arg=IMAGE_REVISION="$(git show --pretty=oneline | tac | tail -n 1 | awk '{print $1}')" \
-    --tag="${IMAGE_NAMESPACE}/sonar-scanner-cli:${IMAGE_VERSION}" \
+    --tag="${IMAGE_NAMESPACE}/sonar-scanner-cli:latest" \
     .
 
 exit 0
-- 
GitLab