Page History
Table of Contents |
---|
Introduction
- This article explains describes a simplified build process for Agent images that which is extracted from the SOS build environment.
- Users can build their own Docker images for Agents.
...
- The build script implements two stages to exclude installer files from the resulting image.
- Line 3: The base image is the current Alpine image at build-time.
- Line 6 - 8: The release identification is injected by build arguments. This information is used to determine the tarball to be downloaded or copied.
- Line 11 - 12: You can either download the Agent tarball directly from the SOS web site or you store the tarball with the build directory and copy from this location.
Line 14 - 16: The tarball is extracted. For Unix Agents no installer is used.
Line 19: The
entrypoint.sh
script is copied from the build directory to the image. Users can apply their own version of the entrypoint script. The entrypoint script used by SOS looks like this:
Download: entrypoint.shCode Block language bash title Entrypoint Script linenumbers true collapse true #!/bin/sh js_args="" if [ ! "$RUN_JS_HTTP_PORT" = "" ] && [ ! "$RUN_JS_HTTP_PORT" = ":" ] then js_args="$js_args --http-port=$RUN_JS_HTTP_PORT" fi if [ ! "$RUN_JS_HTTPS_PORT" = "" ] && [ ! "$RUN_JS_HTTPS_PORT" = ":" ] then js_args="$js_args --https-port=$RUN_JS_HTTPS_PORT" fi if [ ! "$RUN_JS_JAVA_OPTIONS" = "" ] then js_args="$js_args --java-options=$RUN_JS_JAVA_OPTIONS" fi JS_USER_ID=`echo $RUN_JS_USER_ID | cut -d ':' -f 1` JS_GROUP_ID=`echo $RUN_JS_USER_ID | cut -d ':' -f 2` BUILD_GROUP_ID=`cat /etc/group | grep jobscheduler | cut -d ':' -f 3` BUILD_USER_ID=`cat /etc/passwd | grep jobscheduler | cut -d ':' -f 4` if [ "$(id -u)" = "0" ] then if [ ! "$BUILD_USER_ID" = "$JS_USER_ID" ] then echo "JS7 entrypoint script switchng ownership of image user id '$BUILD_USER_ID' -> '$JS_USER_ID', group id '$BUILD_GROUP_ID' -> '$JS_GROUP_ID'" usermod -u $JS_USER_ID jobscheduler groupmod -g $JS_GROUP_ID jobscheduler find /var/sos-berlin.com/ -group $BUILD_GROUP_ID -exec chgrp -h jobscheduler {} \; find /var/sos-berlin.com/ -user $BUILD_USER_ID -exec chown -h jobscheduler {} \; fi echo "JS7 entrypoint script switching to user account 'jobscheduler' to run start script" echo "JS7 entrypoint script starting Agent: exec su-exec jobscheduler:$JS_GROUP_ID /var/sos-berlin.com/js7/agent/bin/agent.sh start_docker $js_args" exec su-exec jobscheduler:$JS_GROUP_ID /var/sos-berlin.com/js7/agent/bin/agent.sh start_docker $js_args else if [ "$BUILD_USER_ID" = "$JS_USER_ID" ] then if [ "$(id -u)" = "$JS_USER_ID" ] then echo "JS7 entrypoint script running for user id '$(id -u)'" else echo "JS7 entrypoint script running for user id '$(id -u)' cannot switch to user id '$JS_USER_ID', group id '$JS_GROUP_ID'" echo "JS7 entrypoint script missing permission to switch user id and group id, consider to omit the 'docker run --user' option" fi else echo "JS7 entrypoint script running for user id '$(id -u)' cannot switch image user id '$BUILD_USER_ID' -> '$JS_USER_ID', group id '$BUILD_GROUP_ID' -> '$JS_GROUP_ID'" echo "JS7 entrypoint script missing permission to switch user id and group id, consider to omit the 'docker run --user' option" fi echo "JS7 entrypoint script starting Agent: exec sh -c /var/sos-berlin.com/js7/agent/bin/agent.sh start_docker $js_args" exec sh -c "/var/sos-berlin.com/js7/agent/bin/agent.sh start_docker $js_args" fi
- Line 22: The
config
folder available in the build directory is copied to theconfig
sub-folder in the image. The parent foldervar_<port>
is determined from the HTTP port that the Agent is built for. This can be useful to create for creating an image with individual default settings in configuration files, see see the JS7 - Agent Configuration Items article for more information. - Line 35 - 38: Defaults for the user id running the Agent inside the container as well as HTTP and HTTPS ports are provided. These values can be overwritten by providing the respective relevant build arguments.
- Line 41 - 44: 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 53 - 59: The image OS is updated and additional packages are installed (ps, netstat, bash).
- Line 60: The most recent Java 1.8 package available with Alpine is applied. Agents can be operated with newer Java releases, however. 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 61: The
jobscheduler
user account is created and is assigned the user id and group id handed over by the respective relevant build arguments. This translates to the fact that the account running the Agent 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 Agent in mounted volumes with identical permissions. - Line 62 - 64: The
jobscheduler
user account is made the owner of installed files and the entrypoint script is made executable. - Line 65: 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 73-75: The entrypoint script and Agent start script are executed and are dynamically parameterized from environment variables when starting the container.
...
- Line 12 - 22: Default values are specified that are used if no command line arguments are provided. This includes values for:
- the release number: adjust this value to the release of JS7 that you want to build an Agent for.
- the repository which by default is
sosberlin:js7
. - the image name is determined from the current folder name and the release number.
- the user id is by default the user id of the user running the build script.
- the HTTP port and HTTPS port: if the respective port is not specified then the Agent will not listen to a port for the respective associated protocol. You can for example disable the HTTP protocol by specifying an empty value. The default ports should be fine as they are mapped by the run script to outside ports on the Docker host. However, you can modify ports as you likerequired.
- Java options: typically you would specify default values e.g. for Java memory consumption. The Java options can be overwritten by the run script when starting the container, however. However, you might want to create your own image with adjusted default values.
- Line 27 - 50: The above options can be overwritten by command line arguments like this:
Code Block language bash title Running the Build Script with Arguments linenumbers true ./build.sh --http-port=14445 --https-port=14443 --java-options="-Xmx1G"
- Line 54 - 63: The effective
docker build
command is executed with arguments. The Dockerfile is assumed to be located in thebuild
sub-directory of the current directory.
...
Overview
Content Tools