OpenShift 4

Concepts Builds and Deployments

S2I

In this article, we explore the Source-to-Image (S2I) build process and its various benefits. Whether you're a developer focused on application code or an operations engineer managing container builds, S2I offers an automated, repeatable process for creating Docker-compliant container images—without the need to handle Dockerfiles or complex build configurations.

S2I simplifies the container image creation process by abstracting the complexity of Dockerfile management and orchestration. Instead of juggling multiple build scripts, you concentrate on your source code while S2I automates the image creation and registry push process. This streamlined approach not only simplifies your workflow but also enhances consistency by reducing manual intervention.

The image is a flowchart illustrating the process of building and deploying a Docker container, starting from local source code to a running container. It includes steps like building an app image and storing it in a Docker registry.

The S2I Workflow

The S2I workflow initiates whenever you commit your source code to a repository. The process is as follows:

  • S2I extracts the source code.
  • It automatically assembles the source into a Docker-formatted container image.
  • The resulting image is pushed to a Docker registry.

This automation eliminates manual Dockerfile maintenance and ensures the build process remains reproducible and standardized.

Key Advantages of S2I

  1. Produces a Docker image directly from your source code, removing the need to manage Dockerfiles or separate build scripts.
  2. Ensures consistent and automated builds, reducing the risk of human error.
  3. Abstracts the container runtime concerns, making your workflows independent of the specific OCI-compliant runtime.
  4. Enhances security by enforcing permissions, authentication, and authorization, thereby limiting image build initiation to trusted users or teams.

Additional Benefits

  • Faster Build Times: Optimized operations reduce build times.
  • Efficient Patching: S2I can compare current artifacts with previous builds, enabling incremental updates.

The image poses the question "What's the point of S21?" and lists three points, with the third stating "Don’t have to worry about container runtime," alongside a clock icon with a question mark.

The image is a diagram highlighting the primary advantages of "S21," which include injecting code into a Docker-formatted container image, faster build times, and easily patching the build.

S2I Implementation and Scripts

Implementing S2I typically involves defining a script that explains how to build the container image from your source code. Although this script can be written in any programming language, its structure often mirrors a simplified Dockerfile, outlining clear steps for the build process.

Below is an example of a simple Bash script that might be placed in the /tmp/S2I directory. This script shows how to manage pre-built artifacts, compile the source code, and install the resulting artifacts:

#!/bin/bash

# Restore build artifacts if they exist
if [ "$(ls /tmp/s2i/artifacts/ 2>/dev/null)" ]; then
  mv /tmp/s2i/artifacts/* $HOME/.
fi

# Move the application source
mv /tmp/s2i/src $HOME/src

# Build application artifacts
pushd ${HOME}
make all

# Install the artifacts
make install
popd

In this script, all contents are initially unpacked into the default directory. The source code is then relocated, the build artifacts are created using make, and finally, the artifacts are installed. This basic process demonstrates the powerful automation capabilities of S2I for container image creation.

Conclusion

S2I streamlines the container image build process by allowing you to focus on your source code while the system handles the heavy lifting. This approach provides a secure, efficient, and standardized method for creating container images ready for modern orchestration platforms.

For more detailed information, refer to the OpenShift Container Platform documentation, which provides extensive details on S2I scripts and configuration.

The image shows a section of the Red Hat OpenShift documentation, specifically focusing on S2I (Source-to-Image) requirements, with a table listing scripts and their descriptions.

Summary

Leveraging S2I enables developers and DevOps engineers to integrate code changes seamlessly into production-ready container images, benefiting from automated processes, enhanced security, and optimized build times.

Watch Video

Watch video content

Previous
Docker Build