$ 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 OpenShift Origin 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 execute 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 OpenShift Origin 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
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
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:
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 build: docker build -t $(IMAGE_NAME) . .PHONY: test test: docker 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 using:
The following steps describe the default workflow to test S2I image builders:
Verify the usage script is working:
Build the image:
Optionally, if you support save-artifacts, execute step 2 once again to verify that saving and restoring artifacts works properly.
Run the container:
Verify the container is running and the application is responding.
Executing these steps is generally enough to tell if the builder image is working as expected.
Another way you can execute the S2I image tests is to use the OpenShift Origin platform itself as a continuous integration system. The OpenShift Origin platform is capable of building container images and is highly customizable.
To set up an S2I image builder continuous integration system, define a Custom build and use the openshift/sti-image-builder image. This image executes all the steps mentioned in the Basic Testing Workflow section and creates a new S2I builder image.
kind: "BuildConfig" apiVersion: "v1" metadata: name: "ruby-20-centos7-build" spec: triggers: - type: "GitHub" github: secret: "secret101" source: type: "Git" git: uri: "git://github.com/openshift/sti-ruby.git" strategy: type: "Custom" customStrategy: from: kind: "DockerImage" name: "openshift/sti-image-builder" env: - name: "IMAGE_NAME" value: "openshift/ruby-20-centos7" - name: "CONTEXT_DIR" value: "/2.0/" exposeDockerSocket: true output: to: kind: "ImageStreamTag" name: "ruby-20-centos7:latest"
You can use the
oc create command to create this
BuildConfig. After you create the
BuildConfig, you can start the build using the following command:
If your OpenShift Origin 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
CustomBuild to trigger a rebuild of your application
based on the S2I image you updated. See image change triggers
for more information.