Page History
Table of Contents |
---|
Introduction
- This article explains a simplified build process for Controller images that is extracted from the SOS build environment.
- Users can build their own Docker images for Controllers.
- This article explains options how to create the Controller image.
Build Environment
For the build environment the following directory hierarchy is assumed:
...
The build script build.sh
and Controller start script start-controller.sh
are described below.
Dockerfile
Download: Dockerfile
Docker images for JS7 Controllers provided by SOS make use of the following Dockerfile:
Code Block | ||||||||
---|---|---|---|---|---|---|---|---|
| ||||||||
# BUILD PRE-IMAGE FROM openjdk:8-jre-alpine LABEL maintainer="Software- und Organisations-Service GmbH" # BUILD SETTINGS # provide build arguments alpine:latest AS js7-pre-image # provide build arguments for release information ARG JS_RELEASE ARG JS_RELEASE_MAJOR # defaultadd/copy userinstallation id has to match later run-time user ARG JS_USER_ID=tarball ADD https://download.sos-berlin.com/JobScheduler.${JS_USER_ID:-1001} ARG JS_ID=RELEASE_MAJOR}/js7_controller_unix.${JS_ID:-jobscheduler} ARG JS_HTTP_INTERFACE=RELEASE}.tar.gz /usr/local/src/ # COPY js7_controller_unix.${JS_HTTP_INTERFACE:-""} ARG JS_HTTP_PORT=${JS_HTTP_PORT:-4444} ARG JS_HTTPS_INTERFACE=${JS_HTTPS_INTERFACE:-""} ARG JS_HTTPS_PORT=${JS_HTTPS_PORT:-""} ARG JS_JAVA_OPTIONS=${JS_JAVA_OPTIONS} # RUN-TIME SETTINGS # JS7 Controller ID, ports and Java options ENV RUN_JS_ID=${RUN_JS_ID:-$JS_ID} ENV RUN_JS_HTTP_INTERFACE=${RUN_JS_HTTP_INTERFACE:-$JS_HTTP_INTERFACE} ENV RUN_JS_HTTP_PORT=${RUN_JS_HTTP_PORT:-$JS_HTTP_PORT} ENV RUN_JS_HTTPS_INTERFACE=${RUN_JS_HTTPS_INTERFACE:-$JS_HTTPS_INTERFACE} ENV RUN_JS_HTTPS_PORT=${RUN_JS_HTTPS_PORT} ENV RUN_JS_JAVA_OPTIONS=${RUN_JS_JAVA_OPTIONS:-$JS_JAVA_OPTIONS} # PREPARATION # install process tools, net tools, bash RUN apk update && apk add --no-cache \ procps \ net-tools \ bash # setup working directory RUN mkdir -p /var/sos-berlin.com/js7 WORKDIR /var/sos-berlin.com/js7 # add/copy installation tarball ADD https://download.sos-berlin.com/JobScheduler.${JS_RELEASE_MAJOR}/js7_controller_unix.${JS_RELEASE}.tar.gz /usr/local/src/ # COPY js7_controller_unix.${JS_RELEASE}.tar.gz /usr/local/src/ # add start script COPY start-controller.sh /usr/local/bin/ # INSTALLATION RELEASE}.tar.gz /usr/local/src/ RUN mkdir -p /var/sos-berlin.com/js7 && \ test -e /usr/local/src/js7_controller_unix.${JS_RELEASE}.tar.gz && \ tar xfvz /usr/local/src/js7_controller_unix.${JS_RELEASE}.tar.gz -C /var/sos-berlin.com/js7/ # add start script COPY start-controller.sh /var/sos-berlin.com/js7/ # copy configuration COPY config/ /var/sos-berlin.com/js7/controller/var/config/ # BUILD IMAGE FROM alpine:latest AS js7-image LABEL maintainer="Software- und Organisations-Service GmbH" # provide build arguments for release information ARG JS_RELEASE ARG JS_RELEASE_MAJOR # default user id has to match later run-time user ARG JS_USER_ID=${JS_USER_ID:-1001} ARG JS_ID=${JS_ID:-jobscheduler} ARG JS_HTTP_INTERFACE=${JS_HTTP_INTERFACE:-""} ARG JS_HTTP_PORT=${JS_HTTP_PORT:-4444} ARG JS_HTTPS_INTERFACE=${JS_HTTPS_INTERFACE:-""} ARG JS_HTTPS_PORT=${JS_HTTPS_PORT:-""} ARG JS_JAVA_OPTIONS=${JS_JAVA_OPTIONS} # JS7 Controller ID, ports and Java options ENV RUN_JS_ID=${RUN_JS_ID:-$JS_ID} ENV RUN_JS_HTTP_INTERFACE=${RUN_JS_HTTP_INTERFACE:-$JS_HTTP_INTERFACE} ENV RUN_JS_HTTP_PORT=${RUN_JS_HTTP_PORT:-$JS_HTTP_PORT} ENV RUN_JS_HTTPS_INTERFACE=${RUN_JS_HTTPS_INTERFACE:-$JS_HTTPS_INTERFACE} ENV RUN_JS_HTTPS_PORT=${RUN_JS_HTTPS_PORT} ENV RUN_JS_JAVA_OPTIONS=${RUN_JS_JAVA_OPTIONS:-$JS_JAVA_OPTIONS} COPY --from=js7-pre-image ["/var/sos-berlin.com/js7", "/var/sos-berlin.com/js7"] # INSTALLATION # install process tools, net tools, bash, openjdk # extract installation tarball # for JDK < 12, /dev/random does not provide sufficient entropy, see https://kb.sos-berlin.com/x/lIM3 # add jobscheduler user account and make it the owner of directories RUN adduser -u ${JS_USER_ID:-1001}apk update && apk add --disabled-password --home /home/jobscheduler --no-create-home --shell /bin/bash jobscheduler jobschedulerno-cache \ --repository=http://dl-cdn.alpinelinux.org/alpine/edge/community \ procps \ net-tools \ bash \ openjdk8 && \ testadduser -e /usr/local/src/js7_controller_unix.${JS_RELEASE}.tar.gzu ${JS_USER_ID:-1001} --disabled-password --home /home/jobscheduler --no-create-home --shell /bin/bash jobscheduler jobscheduler && \ tarchown xfvz /usr/local/src/js7_controller_unix.${JS_RELEASE}.tar.gz -C -R jobscheduler:jobscheduler /var/sos-berlin.com/js7/ && \ rmmv /var/sos-berlin.com/js7/start-controller.sh /usr/local/src/js7_controller_unix.${JS_RELEASE}.tar.gzbin/ && \ chown -R jobscheduler:jobscheduler /var/sos-berlin.com && \ chmod +x /usr/local/bin/start-controller.sh && \ sed -i 's/securerandom.source=file:\/dev\/random/securerandom.source=file:\/dev\/urandom/g' /usr/lib/jvm/java-1.8-openjdk/jre/lib/security/java.security # CONFIGURATIONCODA # copy configuration # COPY --chown=jobscheduler:jobscheduler config/ /var/sos-berlin.com/js7/controller/var/config/ # CODA # run-time user, can be overwritten when running the container USER jobscheduler run-time user, can be overwritten when running the container USER jobscheduler CMD ["sh","-c","/usr/local/bin/start-controller.sh --id=\"$RUN_JS_ID\" --http-port=$RUN_JS_HTTP_INTERFACE:$RUN_JS_HTTP_PORT --https-port=$RUN_JS_HTTPS_INTERFACE:$RUN_JS_HTTPS_PORT --java-options=\"$RUN_JS_JAVA_OPTIONS\""] |
Explanation:
- The build script implements two stages to exclude installer files from the resulting image.
- Line 3Line 1: The base image is OpenJDK Java 1.8 (Alpine based). You can run Controllers with newer Java releases, however, stick to Oracle, OpenJDK or AdoptOpenJDK as the source for your Java base image. Alternatively you can use your own base image and install Java 1.8 on top of this.the current Alpine image at build-time.
- Line 6 - 7Line 8 - 9: The release identification is injected by build arguments. This information is used to determine the tarball to be downloaded or copied.
- Line 12 10 - 18: Defaults for the Controller ID and user id running the Controller inside the container as well as HTTP and HTTPS ports are provided. These values can be overwritten by providing the respective build arguments.
- Line 23 - 28: Environment variables are provided at run-time, not at build-time. They can be used to specify ports and Java options when running the container.
- Line 33 - 36: The image OS is updated and additional packages are installed (ps, netstat, bash, vi).
- Line 43 - 44: You can either download the Controller tarball directly from the SOS web site or you store the tarball with the build directory and copy from this location.
- 11: You can either download the Controller tarball directly from the SOS web site or you store the tarball with the build directory and copy from this location.
Line 13 - 15: The tarball is extracted. For Unix Controllers no installer is used.
Line 18: The
start-controller.sh
script is copied from the build directory to the image. Users can Line 47: Thestart-controller.sh
script is copied from the build directory to the image. Users can apply their own version of the start script. The start script used by SOS looks like this:Code Block language bash title Controller Start Script linenumbers true collapse true #!/bin/sh js_id="" js_http_port="" js_https_port="" js_java_options="" for option in "$@" do case "$option" in --id=*) js_id=`echo "$option" | sed 's/--id=//'` ;; --http-port=*) js_http_port=`echo "$option" | sed 's/--http-port=//'` ;; --https-port=*) js_https_port=`echo "$option" | sed 's/--https-port=//'` ;; --java-options=*) js_java_options=`echo "$option" | sed 's/--java-options=//'` ;; *) echo "unknown argument: $option" exit 1 ;; esac done js_args="" if [ ! "$js_http_port" = "" ] && [ ! "$js_http_port" = ":" ] then js_args="$js_args --http-port=$js_http_port" fi if [ ! "$js_https_port" = "" ] && [ ! "$js_https_port" = ":" ] then js_args="$js_args --https-port=$js_https_port" fi if [ ! "$js_java_options" = "" ] then js_args="$js_args --java-options=$js_java_options" fi echo "starting Controller: /var/sos-berlin.com/js7/controller/bin/controller.sh start --id=$js_id $js_args" /var/sos-berlin.com/js7/controller/bin/controller.sh start --id=$js_id $js_args && tail -f /dev/null /dev/null
- Line 21: Optionally a
config
folder is available in the build directory and is copied to theconfig
sub-folder in the image. This can be useful to create an image with individual default settings in configuration files, see JS7 - Controller Configuration Items. - Line 34 - 40: Defaults for the Controller ID and user id running the Controller inside the container as well as HTTP and HTTPS ports are provided. These values can be overwritten by providing the respective build arguments.
- Line 33 - 48: Environment variables are provided at run-time, not at build-time. They can be used to specify ports and Java options when running the container.
- Line 58 - 62: The image OS is updated and additional packages are installed (ps, netstat, bash,).
- Line 63: The most recent Java 1.8 package available with Alpine is applied. Agents can be operated with newer Java releases, however, stick to Oracle, OpenJDK or AdoptOpenJDK as the source for your Java LTS release. Alternatively you can use your own base image and install Java 1.8 or later on top of this.
- Line 64 - 67Line 54 - 59: The user account
jobscheduler
is created and is assigned the user id and group id handed over by the respective build arguments. This translates to the fact that the account running the Controller inside the container and the account that starts the container are assigned the same user id and group id. This allows the account running the container to access any files created by the Controller in mounted volumes with identical permissions. - Line 6068: Java releases < Java 12 make use of
/dev/random
for random number generation. This is a bottleneck as random number generation with this file is blocking. Instead/dev/urandom
should be used that implements non-blocking behavior. The change of the random file is applied to the Java security file. - Line 65: if a
config
folder is available in the build directory then its contents is copied to the respectiveconfig
folder in the image. This can be useful to create an image with individual settings in configuration files, see JS7 - Controller Configuration Items.Line 7275: The start script is executed and is dynamically parameterized from environment variables that are forwarded when starting the container.
...