$ s2i create _<image name>_ _<destination directory>_
As an Source-to-Image (s2i) builder image author, you can test your s2i image locally and use the OKD build system for automated testing and continuous integration.
Check the s2i Requirements topic to learn more about the s2i architecture before proceeding. |
As described in the s2i Requirements topic, s2i requires the assemble and run scripts to be present in order to successfully run the s2i build. Providing the save-artifacts script reuses the build artifacts, and providing the usage script ensures that usage information is printed to console when someone runs the container image outside of the s2i.
The goal of testing an s2i image is to make sure that all of these described commands work properly, even if the base container image has changed or the tooling used by the commands was updated.
The standard location for the test script is test/run. This script is invoked by the OKD s2i image builder and it could be a simple Bash script or a static Go binary.
The test/run script performs the s2i build, so you must have the s2i binary
available in your $PATH
. If required, follow the installation instructions
in the
s2i
README.
s2i combines the application source code and builder image, so in order to test
it you need a sample application source to verify that the source successfully
transforms into a runnable container image. The sample application should be simple,
but it should exercise the crucial steps of assemble
and run
scripts.
The s2i tooling comes with powerful generation tools to speed up the process of
creating a new s2i image. The s2i create
command produces all the necessary s2i
scripts and testing tools along with the Makefile:
$ s2i create _<image name>_ _<destination directory>_
The generated test/run script must be adjusted to be useful, but it provides a good starting point to begin developing.
The test/run script produced by the |
The easiest way to run the s2i image tests locally is to use the generated Makefile.
If you did not use the s2i create
command, you can copy the
following Makefile template and replace the IMAGE_NAME
parameter with
your image name.
IMAGE_NAME = openshift/ruby-20-centos7 CONTAINER_ENGINE := $(shell command -v podman 2> /dev/null | echo docker) build: ${CONTAINER_ENGINE} build -t $(IMAGE_NAME) . .PHONY: test test: ${CONTAINER_ENGINE} build -t $(IMAGE_NAME)-candidate . IMAGE_NAME=$(IMAGE_NAME)-candidate test/run
The test script assumes you have already built the image you want to test. If required, first build the s2i image. Run one of the following commands:
If you use Podman, run the following command:
$ podman build -t _<BUILDER_IMAGE_NAME>_
If you use Docker, run the following command:
$ docker build -t _<BUILDER_IMAGE_NAME>_
The following steps describe the default workflow to test s2i image builders:
Verify the usage script is working:
If you use Podman, run the following command:
$ podman run _<BUILDER_IMAGE_NAME>_ .
If you use Docker, run the following command:
$ docker run _<BUILDER_IMAGE_NAME>_ .
Build the image:
$ s2i build file:///path-to-sample-app _<BUILDER_IMAGE_NAME>_ _<OUTPUT_APPLICATION_IMAGE_NAME>_
Optionally, if you support save-artifacts, run step 2 once again to verify that saving and restoring artifacts works properly.
Run the container:
If you use Podman, run the following command:
$ podman run _<OUTPUT_APPLICATION_IMAGE_NAME>_
If you use Docker, run the following command:
$ docker run _<OUTPUT_APPLICATION_IMAGE_NAME>_
Verify the container is running and the application is responding.
Running these steps is generally enough to tell if the builder image is working as expected.
Once you have a Dockerfile
and the other artifacts that make up your new
s2i builder image, you can put them in a git repository and use OKD
to build and push the image. Simply define a Docker build that points
to your repository.
If your OKD instance is hosted on a public IP address, the build can be triggered each time you push into your s2i builder image GitHub repository. See webhook triggers for more information.
You can also use the ImageChangeTrigger
to trigger a rebuild of your applications that are
based on the s2i builder image you updated. See image change triggers
for more information.