Arkadiusz Kałkus
Arkadiusz Kałkus

Reputation: 18443

How to execute commands during S2I build in Openshift?

Openshift CLI command to start S2I (source to image) build looks like this:

oc start-build buildname --from-dir=./someDirectory--wait=true

But how can we execute some shell command? os start-build is going to create image (described in the build definition) and copy someDirectory to it, but what if we need additional configuration of that image, not only to push compiled source code there?

Upvotes: 0

Views: 2009

Answers (1)

Oligzeev
Oligzeev

Reputation: 511

There're a couple of options:

  • Provide a layer in the Dockerfile
  • Override assemble script

assemble script override options:

  • Provide .s2i/bin/assemble into the code repository
  • Specify spec.strategy.sourceStrategy.scripts in the BuildConfig with URL of a directory containing the scripts (see override builder image scripts)

Example of assemble script and s2i workflow you can check in s2i or there's simple example:

#!/bin/bash

# Run additional build before steps

# Execute original assemble script.
/usr/libexec/s2i/assemble

# Run additional build after steps

In addition, There's postCommit build hooks which executes after commiting the image and before pushing it to the registry. It executes in temporary container so it can only be used to do some tests.

Upvotes: 1

Related Questions