Task:
Override S2I builder script in OpenShift w/o updating image repo.
Notes:
- Build scripts are run, by default, from a folder w/in the registry image code.
- Overrides are made by wrapping/updating the S2I scripts, typically the assemble and run scripts, and placing the updated versions in the .s2i/bin directory of the source code repo.
- The save-artifacts script be be used to copy downloaded library and component dependancies and save them for the next build so it does not have be done every time.
Important:
- If you are customizing another registry image, the simple way is to fork the original GitHub repo and update/replace the scripts, but then the new fork would have to be be maintained. Therefore, the proper way to automate this would be to place the overrides in a "derived image" instead of local or a web server by overriding the io.openshift.s2i.scripts-url label on the Docker image. This provides a way for the BuildConfig triggers to occur.
Derived Image Gotchas:
- The derived registry's image source code is not copied into place until after the repo's assembly script is run (e.g. /usr/libexec/s2i/assemble ).
- When wrapping the run script, ensure to use exec before the original script (e.g. exec /usr/libexec/s2i/run ). Neglecting to do so will result in script not running w/Process ID of 1, and pod shutdown results in signal propagation errors, and additional commands in the wrapper script cannot be run after the first run script.
Steps:
1. Pull the registry image so we can inspect it.
(Alternately, we could go to the registry and look at it w/in a browser or use skopeo or curl.)
$ podman pull myregistry.mindwatering.net/<workspace_project>/<image_name>
Alternate:
$ skopeo inspect docker://myrestry.mindwatering.net/<workspace_project>/<image_name> | grep io.openshift.s2i.scripts-url
<view output - e.g. image:///usr/libexec/s2i>
2. Get the io.openshift.s2i.scripts-url label:
$ podman inspect --format='{{ index .Config.Labels "io.openshift.s2i.scripts-url"}}' <image_name>
<view output - e.g. image:///usr/libexec/s2i>
3. Create the override wrapper scripts:
a. Example of post-invocation assemble wrapper script:
$ vi assemble
#!/bin/bash
echo "Making pre-invocation changes..."
/usr/libexec/s2i/assemble
rc=$?
if [ $rc -eq 0 ]; then
echo "Making post-invocation changes..."
# add additional code below here
else
echo "Error: assemble failed!"
fi
exit $rc
b. Example of run wrapper script:
#!/bin/bash
echo "Before calling run..."
# add pre-run customizations below here
exec /usr/libexec/s2i/run
previous page
|