diff --git a/.devcontainer/Dockerfile b/.devcontainer/Dockerfile index 8d87309fc783e3b1195a7edacdf483635f6a023a..425c1539f7fb854154cc63095cd3f3d1ae5be261 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='' diff --git a/Dockerfile b/Dockerfile index 106cebe3902a9d7811b6a444f47b5a760f868102..0d3b1fe894ec5f9d14e4f4485b60a4c3d0d1b410 100644 --- a/Dockerfile +++ b/Dockerfile @@ -38,16 +38,31 @@ 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="" -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.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" +## Note to editors: metadata values for `created`, `version`, and `revision` +## 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} \ + 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 +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} diff --git a/build.sh b/build.sh new file mode 100644 index 0000000000000000000000000000000000000000..ecb16b512e40cab80e27bc13ac04f7a6aef6d3d3 --- /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 | tac | tail -n 1 | awk '{print $1}')" \ + --tag="${IMAGE_NAMESPACE}/sonar-scanner-cli:${IMAGE_VERSION}" \ + . + +exit 0