Invoke scripts embedded in an image
To extend builder image behavior while preserving supported script logic and upgrade compatibility in Red Hat OpenShift Container Platform, you can start embedded S2I image scripts by creating wrapper scripts. These wrapper scripts run custom logic and then call the default scripts from the image.
-
Inspect the value of the
io.openshift.s2i.scripts-urllabel to determine the location of the scripts inside of the builder image:$ podman inspect --format='{{ index .Config.Labels "io.openshift.s2i.scripts-url" }}' wildfly/wildfly-centos7Example outputimage:///usr/libexec/s2i -
Create a script that includes an invocation of one of the standard scripts wrapped in other commands:
.s2i/bin/assemblescript#!/bin/bash echo "Before assembling" /usr/libexec/s2i/assemble rc=$? if [ $rc -eq 0 ]; then echo "After successful assembling" else echo "After failed assembling" fi exit $rcThis example shows a custom assemble script that prints the message, runs the standard assemble script from the image, and prints another message depending on the exit code of the assemble script.
When wrapping the run script, you must use
execfor invoking it to ensure signals are handled properly. The use ofexecalso precludes the ability to run additional commands after invoking the default image run script..s2i/bin/runscript#!/bin/bash echo "Before running application" exec /usr/libexec/s2i/run
Override source-to-image builder image scripts
You can override the assemble, run, and save-artifacts source-to-image (S2I) scripts provided by the builder image.
-
To override the
assemble,run, andsave-artifactsS2I scripts provided by the builder image, complete one of the following actions:-
Provide an
assemble,run, orsave-artifactsscript in the.s2i/bindirectory of your application source repository. -
Provide a URL of a directory containing the scripts as part of the strategy definition in the
BuildConfigobject. For example:strategy: sourceStrategy: from: kind: "ImageStreamTag" name: "builder-image:latest" scripts: "http://somehost.com/scripts_directory"The build process appends run,assemble, andsave-artifactsto the path. If any or all scripts with these names exist, the build process uses these scripts in place of scripts with the same name that are provided in the image.Files located at the
scriptsURL take precedence over files located in.s2i/binof the source repository.
-
Source-to-image environment variables
There are two ways to make environment variables available to the source build process and resulting image: environment files and BuildConfig environment values. The variables that you provide using either method will be present during the build process and in the output image.
Source build enables you to set environment values, one per line, inside your application, by specifying them in a .s2i/environment file in the source repository. The environment variables specified in this file are present during the build process and in the output image.
If you provide a .s2i/environment file in your source repository, source-to-image (S2I) reads this file during the build. This allows customization of the build behavior as the assemble script may use these variables. The complete list of supported environment variables is available in the using images section for each image.
-
To disable assets compilation for your Rails application during the build, add the following line to the
.s2i/environmentfile:DISABLE_ASSET_COMPILATION=true -
In addition to builds, the specified environment variables are also available in the running application itself. To start the Rails application in
developmentmode instead ofproductionmode, add the following line to the.s2i/environmentfile:RAILS_ENV=development
Ignore source-to-image source files
Source-to-image (S2I) supports a .s2iignore file, which contains a list of file patterns that should be ignored. Files in the build working directory, as provided by the various input sources, that match a pattern found in the .s2iignore file will not be made available to the assemble script.