Fakultas Ilmu Komputer UI

Skip to content
Snippets Groups Projects
Commit a65cd6fa authored by Daya Adianto's avatar Daya Adianto
Browse files

Merge branch 'feature/2-build-script' into 'master'

Create build script for building container image

This MR adds a build script for building container image.

Close #2.

See merge request pmpl/sonar-scanner-cli-image!2
parents b6265b54 23ae22e4
No related branches found
No related tags found
No related merge requests found
...@@ -41,4 +41,4 @@ RUN wget -O /usr/local/bin/hadolint https://github.com/hadolint/hadolint/release ...@@ -41,4 +41,4 @@ RUN wget -O /usr/local/bin/hadolint https://github.com/hadolint/hadolint/release
&& chmod +x /usr/local/bin/hadolint && chmod +x /usr/local/bin/hadolint
# Switch back to dialog for any ad-hoc use of apt-get # Switch back to dialog for any ad-hoc use of apt-get
ENV DEBIAN_FRONTEND= ENV DEBIAN_FRONTEND=''
...@@ -38,16 +38,31 @@ WORKDIR /home/sonar ...@@ -38,16 +38,31 @@ WORKDIR /home/sonar
ENTRYPOINT ["/bin/bash"] ENTRYPOINT ["/bin/bash"]
# Container image metadata # Container image metadata
## Note to editors: metadata values for `created`, `version`, `revision`, and ## Note to editors: metadata values for `created`, `version`, and `revision`
## `ref.name` keys must be provided during build process, i.e. `docker build` ## keys must be provided during build process, i.e. `docker build` invocation.
## invocation ## It is also possible to pass other metadata values via build arguments.
LABEL org.opencontainers.image.created="" ARG IMAGE_CREATED=""
LABEL org.opencontainers.image.authors="Daya Adianto <dayaadianto@cs.ui.ac.id>" ARG IMAGE_SOURCE="https://gitlab.cs.ui.ac.id/pmpl/sonar-scanner-cli-image"
LABEL org.opencontainers.image.source="https://gitlab.cs.ui.ac.id/pmpl/sonar-scanner-cli-image" ARG IMAGE_VERSION=""
LABEL org.opencontainers.image.version="" ARG IMAGE_REVISION=""
LABEL org.opencontainers.image.revision="" ARG IMAGE_VENDOR="Faculty of Computer Science Universitas Indonesia"
LABEL org.opencontainers.image.vendor="Faculty of Computer Science Universitas Indonesia" ARG IMAGE_TITLE="Sonar Scanner CLI Image"
LABEL org.opencontainers.image.licenses="LGPL-3.0" ARG IMAGE_DESCRIPTION="Sonar Scanner CLI bundled in a container image."
LABEL org.opencontainers.image.ref.name="" LABEL org.opencontainers.image.created=${IMAGE_CREATED} \
LABEL org.opencontainers.image.title="Sonar Scanner CLI Image" org.opencontainers.image.authors="Daya Adianto <dayaadianto@cs.ui.ac.id>" \
LABEL org.opencontainers.image.description="Sonar Scanner CLI bundled in a container image" 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}
build.sh 0 → 100644
#!/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
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment