Introduction
- This article describes the build process for official Agent images.
- Users can build their own container images for Agents and adjust to their needs.
Build Environment
The following directory hierarchy is assumed for the build environment:
agent
build.sh
build
Dockerfile
entrypoint.sh
js7_install_agent.sh
config
The root directory agent
can have any name. Note that the build script listed below will, by default, use the directory name and release number to determine the resulting image name.
The build script build.sh
and entrypoint script entrypoint.sh
are described below.
Dockerfile
Download: Dockerfile
Container images for JS7 Agents provided by SOS make use of the following Dockerfile:
Explanation:
- The Dockerfile 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 10 - 13: 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 relevant build arguments.
- Line 16 - 17: Users can either download the Agent tarball directly from the SOS web site or store the tarball with the build directory and copy from this location.
Line 20: The tarball integrity is tested.
- Line 23 - 24: The Agent Installer Script is downloaded or copied, see JS7 - Unix Shell Installation Script - js7_install_agent.sh
- Line 27: The
jobscheduler
account is created. - Line 27 - 35: The Agent Installer Script is executed with arguments performing installation for the
jobscheduler
account. - Line 55 - 58: 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 64: 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 for creating an image with individual default settings in configuration files, see the JS7 - Agent Configuration Items article for more information. - Line 67: 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: - Line 72 - 78: The image OS is updated and additional packages are installed (ps, netstat, bash).
- Line 79: The most recent Java 11 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 on top of this. For details see Which Java versions is JobScheduler available for?
- Line 80: Java releases might 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 81: Users might want to disable certain TLS protocol versions or algorithms by applying changes to the Java security file.
- Line 82 - 84: The
jobscheduler
account is created and is assigned the user id handed over by the relevant build argument. This suggests that the account running the Agent inside the container and the account that starts the container are assigned the same user id. This allows the account running the container to access any files created by the Agent in mounted volumes with identical permissions.- Consider that the account is assigned the
root
group. For environments in which the entrypoint script is executed with an arbitrary non-root user id this allows access to files created by the Agent provided to any accounts that are assigned theroot
group. - Accordingly any files owned by the
jobscheduler
account are made accessible to theroot
group with similar user permissions. Read access to/etc/passwd
can be required in such environments. - For details see JS7 - Running Containers for User Accounts.
- Consider that the account is assigned the
- Line 85: The entrypoint script is made executable.
- Line 89: The entrypoint script is executed and is dynamically parameterized from environment variables when starting the container.
Entrypoint Script
Download: entrypoint.sh
The following entrypoint script is used to start Agent containers.
Build Script
The build script offers a number of options to parameterize the Dockerfile:
Explanation:
- 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 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 container's host. However, you can modify ports as required.
- 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, 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:Running the Build Script with Arguments
./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.