The default S2I build process does not suit me, how can I customize it?

S2I has two main scripts that may come in mind when there is a need to customize the build process:

assemble

The assemble script is executed during the build process, after the source code is downloaded from Git. It’s job is to prepare an environment which contains the application in a runnable format. It compiles the source codes if needed, and copies the resulting artifacts to a place where the run script needs them to be.

Default Location: /usr/libexec/s2i/assemble

run

The run script is executed when the build is completed, and the resulting image gets deployed. Its job is to start up the application runtime environment, and make the application ready to serve requests.

Default Location: /usr/libexec/s2i/run

You can find these scripts in the locations mentioned above, in any image built with S2I. There are a number of ways to override these builder scripts:

  1. Place a modified version of these scripts in the .s2i/bin directory of your application source repository.

  2. Provide a URL of a directory containing the scripts as part of the BuildConfig definition, for example:

    strategy:
      type: "Source"
      sourceStrategy:
        from:
          kind: "ImageStreamTag"
          name: "builder-image:latest"
        scripts: "http://somehost.com/scripts_directory"
  3. Create your own custom builder image with a Dockerfile-based build, which contains the modified builder scripts. Then use this custom builder image as the base image in your S2I build.