From e97bafdf142ddcc8671c3d3183ea47b27d3dc744 Mon Sep 17 00:00:00 2001 From: Daya Adianto <dayaadianto@cs.ui.ac.id> Date: Thu, 29 Aug 2019 20:36:17 +0700 Subject: [PATCH 1/6] Edit Dockerfile to get some metadata values from args (#2) --- Dockerfile | 17 +++++++++-------- 1 file changed, 9 insertions(+), 8 deletions(-) diff --git a/Dockerfile b/Dockerfile index 106cebe..0f2b339 100644 --- a/Dockerfile +++ b/Dockerfile @@ -38,16 +38,17 @@ WORKDIR /home/sonar ENTRYPOINT ["/bin/bash"] # Container image metadata -## Note to editors: metadata values for `created`, `version`, `revision`, and -## `ref.name` keys must be provided during build process, i.e. `docker build` -## invocation -LABEL org.opencontainers.image.created="" +## Note to editors: metadata values for `created`, `version`, and `revision` +## keys must be provided during build process, i.e. `docker build` invocation +ARG IMAGE_CREATED="" +ARG IMAGE_VERSION="" +ARG IMAGE_REVISION="" +LABEL org.opencontainers.image.created=${IMAGE_CREATED} LABEL org.opencontainers.image.authors="Daya Adianto <dayaadianto@cs.ui.ac.id>" LABEL org.opencontainers.image.source="https://gitlab.cs.ui.ac.id/pmpl/sonar-scanner-cli-image" -LABEL org.opencontainers.image.version="" -LABEL org.opencontainers.image.revision="" +LABEL org.opencontainers.image.version=${IMAGE_VERSION} +LABEL org.opencontainers.image.revision=${IMAGE_REVISION} LABEL org.opencontainers.image.vendor="Faculty of Computer Science Universitas Indonesia" LABEL org.opencontainers.image.licenses="LGPL-3.0" -LABEL org.opencontainers.image.ref.name="" LABEL org.opencontainers.image.title="Sonar Scanner CLI Image" -LABEL org.opencontainers.image.description="Sonar Scanner CLI bundled in a container image" +LABEL org.opencontainers.image.description="Sonar Scanner CLI bundled in a container image." -- GitLab From 100642d9313a63a4b280f28a3db59754ce9dd083 Mon Sep 17 00:00:00 2001 From: Daya Adianto <dayaadianto@cs.ui.ac.id> Date: Thu, 29 Aug 2019 20:37:12 +0700 Subject: [PATCH 2/6] Fix lint issue in Dockerfile used for VS Code dev. container (#2) --- .devcontainer/Dockerfile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.devcontainer/Dockerfile b/.devcontainer/Dockerfile index 8d87309..425c153 100644 --- a/.devcontainer/Dockerfile +++ b/.devcontainer/Dockerfile @@ -41,4 +41,4 @@ RUN wget -O /usr/local/bin/hadolint https://github.com/hadolint/hadolint/release && chmod +x /usr/local/bin/hadolint # Switch back to dialog for any ad-hoc use of apt-get -ENV DEBIAN_FRONTEND= +ENV DEBIAN_FRONTEND='' -- GitLab From fd01ff02280be3ebfda1850e0a225ff6e9fea497 Mon Sep 17 00:00:00 2001 From: Daya Adianto <dayaadianto@cs.ui.ac.id> Date: Thu, 29 Aug 2019 20:37:53 +0700 Subject: [PATCH 3/6] Add build script (#2) --- build.sh | 42 ++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 42 insertions(+) create mode 100644 build.sh diff --git a/build.sh b/build.sh new file mode 100644 index 0000000..3e1f7bd --- /dev/null +++ b/build.sh @@ -0,0 +1,42 @@ +#!/usr/bin/env bash + +# Exit immediately on any failure +set -e +set -o pipefail + +if ! [ -x "$(command -v docker)" ]; then + echo 'Error: docker is not installed.' >&2 + exit 1 +fi + +if ! [ -x "$(command -v git)" ]; then + echo 'Error: git is not installed.' >&2 + exit 1 +fi + +if ! [ -x "$(command -v awk)" ]; then + echo 'Error: awk is not installed.' >&2 + exit 1 +fi + +if ! [ -n "$1" ]; then + echo "Error: missing 1st argument of $0, i.e. namespace of the container image." >&2 + 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 | awk '{print $1}')" \ + --tag="${IMAGE_NAMESPACE}/sonar-scanner-cli:${IMAGE_VERSION}" \ + . + +exit 0 -- GitLab From 8a215729e9c535decffa89413ca44ec8b21cefb0 Mon Sep 17 00:00:00 2001 From: Daya Adianto <dayaadianto@cs.ui.ac.id> Date: Thu, 29 Aug 2019 20:50:02 +0700 Subject: [PATCH 4/6] Fix invalid commit SHA parsing (#2) --- build.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/build.sh b/build.sh index 3e1f7bd..ecb16b5 100644 --- a/build.sh +++ b/build.sh @@ -35,7 +35,7 @@ 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 | awk '{print $1}')" \ + --build-arg=IMAGE_REVISION="$(git show --pretty=oneline | tac | tail -n 1 | awk '{print $1}')" \ --tag="${IMAGE_NAMESPACE}/sonar-scanner-cli:${IMAGE_VERSION}" \ . -- GitLab From 574e20a6ed31183239d0fcb92d59c27854c0e218 Mon Sep 17 00:00:00 2001 From: Daya Adianto <dayaadianto@cs.ui.ac.id> Date: Thu, 29 Aug 2019 20:51:40 +0700 Subject: [PATCH 5/6] Ensure backward compatibility with Label Schema standard (#2) --- Dockerfile | 22 ++++++++++++++++++---- 1 file changed, 18 insertions(+), 4 deletions(-) diff --git a/Dockerfile b/Dockerfile index 0f2b339..74001bc 100644 --- a/Dockerfile +++ b/Dockerfile @@ -39,16 +39,30 @@ ENTRYPOINT ["/bin/bash"] # Container image metadata ## Note to editors: metadata values for `created`, `version`, and `revision` -## keys must be provided during build process, i.e. `docker build` invocation +## keys must be provided during build process, i.e. `docker build` invocation. +## 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_REVISION="" +ARG IMAGE_VENDOR="Faculty of Computer Science Universitas Indonesia" +ARG IMAGE_TITLE="Sonar Scanner CLI Image" +ARG IMAGE_DESCRIPTION="Sonar Scanner CLI bundled in a container image." LABEL org.opencontainers.image.created=${IMAGE_CREATED} LABEL org.opencontainers.image.authors="Daya Adianto <dayaadianto@cs.ui.ac.id>" -LABEL org.opencontainers.image.source="https://gitlab.cs.ui.ac.id/pmpl/sonar-scanner-cli-image" +LABEL org.opencontainers.image.source=${IMAGE_SOURCE} LABEL org.opencontainers.image.version=${IMAGE_VERSION} LABEL org.opencontainers.image.revision=${IMAGE_REVISION} -LABEL org.opencontainers.image.vendor="Faculty of Computer Science Universitas Indonesia" +LABEL org.opencontainers.image.vendor=${IMAGE_VENDOR} LABEL org.opencontainers.image.licenses="LGPL-3.0" -LABEL org.opencontainers.image.title="Sonar Scanner CLI Image" +LABEL org.opencontainers.image.title=${IMAGE_TITLE} LABEL org.opencontainers.image.description="Sonar Scanner CLI bundled in a container image." + +## Note to editors: The following label assignments are to ensure backward +## compatibility with Label Schema standard +LABEL org.label-schema.build-date=${IMAGE_CREATED} \ + org.label-schema.vcs-url=${IMAGE_SOURCE} \ + org.label-schema.version=${IMAGE_VERSION} \ + org.label-schema.vendor=${IMAGE_VENDOR} \ + org.label-schema.title=${IMAGE_TITLE} \ + org.label-schema.description=${IMAGE_DESCRIPTION} -- GitLab From cad1e78c05c1c97d9468e5322eab991fc4217f84 Mon Sep 17 00:00:00 2001 From: Daya Adianto <dayaadianto@cs.ui.ac.id> Date: Thu, 29 Aug 2019 20:54:53 +0700 Subject: [PATCH 6/6] Make label assignments to only use single layer (#2) --- Dockerfile | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/Dockerfile b/Dockerfile index 74001bc..0d3b1fe 100644 --- a/Dockerfile +++ b/Dockerfile @@ -48,15 +48,15 @@ ARG IMAGE_REVISION="" ARG IMAGE_VENDOR="Faculty of Computer Science Universitas Indonesia" ARG IMAGE_TITLE="Sonar Scanner CLI Image" ARG IMAGE_DESCRIPTION="Sonar Scanner CLI bundled in a container image." -LABEL org.opencontainers.image.created=${IMAGE_CREATED} -LABEL org.opencontainers.image.authors="Daya Adianto <dayaadianto@cs.ui.ac.id>" -LABEL org.opencontainers.image.source=${IMAGE_SOURCE} -LABEL org.opencontainers.image.version=${IMAGE_VERSION} -LABEL org.opencontainers.image.revision=${IMAGE_REVISION} -LABEL org.opencontainers.image.vendor=${IMAGE_VENDOR} -LABEL org.opencontainers.image.licenses="LGPL-3.0" -LABEL org.opencontainers.image.title=${IMAGE_TITLE} -LABEL org.opencontainers.image.description="Sonar Scanner CLI bundled in a container image." +LABEL org.opencontainers.image.created=${IMAGE_CREATED} \ + org.opencontainers.image.authors="Daya Adianto <dayaadianto@cs.ui.ac.id>" \ + org.opencontainers.image.source=${IMAGE_SOURCE} \ + org.opencontainers.image.version=${IMAGE_VERSION} \ + org.opencontainers.image.revision=${IMAGE_REVISION} \ + org.opencontainers.image.vendor=${IMAGE_VENDOR} \ + org.opencontainers.image.licenses="LGPL-3.0" \ + org.opencontainers.image.title=${IMAGE_TITLE} \ + org.opencontainers.image.description=${IMAGE_DESCRIPTION} ## Note to editors: The following label assignments are to ensure backward ## compatibility with Label Schema standard -- GitLab