github.imxd.top/openshift/source-to-image@v1.2.0/docs/user_guide.md (about)

     1  # Using S2I images
     2  
     3  S2I builder images normally include [`assemble` and `run` scripts](https://docs.okd.io/latest/creating_images/s2i.html#s2i-scripts), but the default behavior of those scripts may not be suitable for all users. This topic covers a few approaches for customizing the behavior of an S2I builder that includes default scripts.
     4  
     5  ## Invoking scripts embedded in an image
     6  
     7  Typically, builder images provide their own version of the [S2I scripts](builder_image.md#s2i-scripts) that cover the most common use-cases. If these scripts do not fulfill your needs, S2I provides a way of overriding them by adding custom ones in the `.s2i/bin` directory. However, by doing this you are [completely replacing the standard scripts](https://docs.okd.io/latest/creating_images/s2i.html#s2i-scripts). In some cases this is acceptable, but in other scenarios you may prefer to execute a few commands before (or after) the scripts while retaining the logic of the script provided in the image. In this case, it is possible to create a wrapper script that executes custom logic and delegates further work to the default script in the image.
     8  
     9  To determine the location of the scripts inside of the builder image, look at the value of `io.openshift.s2i.scripts-url` label. Use `docker inspect`:
    10  
    11  ```console
    12  $ docker inspect --format='{{ index .Config.Labels "io.openshift.s2i.scripts-url" }}' openshift/wildfly-100-centos7
    13  image:///usr/libexec/s2i
    14  ```
    15  
    16  You inspected the `openshift/wildfly-100-centos7` builder image and found out that the scripts are in the `/usr/libexec/s2i` directory.
    17  
    18  With this knowledge, invoke any of these scripts from your own by wrapping its invocation.
    19  
    20  Example of `.s2i/bin/assemble` script:
    21  ```bash
    22  #!/bin/bash
    23  echo "Before assembling"
    24  
    25  /usr/libexec/s2i/assemble
    26  rc=$?
    27  
    28  if [ $rc -eq 0 ]; then
    29      echo "After successful assembling"
    30  else
    31      echo "After failed assembling"
    32  fi
    33  
    34  exit $rc
    35  ```
    36  
    37  The example shows a custom `assemble` script that prints the message, executes standard `assemble` script from the image and prints another message depending on the exit code of the `assemble` script.
    38  
    39  When wrapping the `run` script, you must [use `exec` for invoking it](https://docs.okd.io/latest/creating_images/guidelines.html#general-docker-guidelines) to ensure signals are handled properly. Unfortunately, the use of `exec` also precludes the ability to run additional commands after invoking the default image run script.
    40  
    41  Example of `.s2i/bin/run` script:
    42  ```bash
    43  #!/bin/bash
    44  echo "Before running application"
    45  exec /usr/libexec/s2i/run
    46  ```