How to write source-to-image scripts
Define mandatory Source-to-image (S2I) scripts, such as assemble and run to enable Red Hat OpenShift Container Platform to build, customize, and execute highly reproducible container images.
You can write S2I scripts in any programming language, as long as the scripts are executable inside the builder image. S2I supports multiple options providing assemble/run/save-artifacts scripts. All of these locations are checked on each build in the following order:
-
A script specified in the build configuration.
-
A script found in the application source
.s2i/bindirectory. -
A script found at the default image URL with the
io.openshift.s2i.scripts-urllabel.
Both the io.openshift.s2i.scripts-url label specified in the image and the script specified in a build configuration can take one of the following forms:
-
image:///path_to_scripts_dir: absolute path inside the image to a directory where the S2I scripts are located. -
file:///path_to_scripts_dir: relative or absolute path to a directory on the host where the S2I scripts are located. -
http(s)://path_to_scripts_dir: URL to a directory where the S2I scripts are located.
| Script | Description | ||
|---|---|---|---|
|
The
|
||
|
The |
||
|
The
These dependencies are gathered into a |
||
|
The |
||
|
The
|
Example S2I scripts
The following example S2I scripts are written in Bash. Each example assumes its tar contents are unpacked into the /tmp/s2i directory.
assemble script:#!/bin/bash
# restore build artifacts
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
run script:#!/bin/bash
# run the application
/opt/application/run.sh
save-artifacts script:#!/bin/bash
pushd ${HOME}
if [ -d deps ]; then
# all deps contents to tar stream
tar cf - deps
fi
popd
usage script:#!/bin/bash
# inform the user how to use the image
cat <<EOF
This is a S2I sample builder image, to use it, install
https://github.com/openshift/source-to-image
EOF