fat fantasma
fat fantasma

Reputation: 7613

Openshift 3 - Overriding .s2i/bin files - assemble & run scripts

I wanted clarification on the possible scripts that can be added in the .s2i/bin directory in my project repo.

The docs say when you add these files they will override the default files of the same name when the project is built. For example, if I place my own "assemble" file in the .s2i/bin directory will the default assemble file run also or be totally replaced by my script? What If I want some of the behavior of the default file? Do I have to copy the default "assemble" contents into my file so both will be executed?

Upvotes: 2

Views: 1730

Answers (2)

Andreas Panagiotidis
Andreas Panagiotidis

Reputation: 3032

Using OpenShift, I want to execute my own run script (run). So, I added in the src of my application a file in ./s2i/run that slightly changes the default run file https://github.com/sclorg/nginx-container/blob/master/1.20/s2i/bin/run

Here is my run file

#!/bin/bash
source /opt/app-root/etc/generate_container_user

set -e

source ${NGINX_CONTAINER_SCRIPTS_PATH}/common.sh

process_extending_files ${NGINX_APP_ROOT}/src/nginx-start ${NGINX_CONTAINER_SCRIPTS_PATH}/nginx-start

if [ ! -v NGINX_LOG_TO_VOLUME -a -v NGINX_LOG_PATH ]; then
    /bin/ln -sf /dev/stdout ${NGINX_LOG_PATH}/access.log
    /bin/ln -sf /dev/stderr ${NGINX_LOG_PATH}/error.log
fi

#nginx will start using the custom nginx.conf from configmap
exec nginx -c /opt/mycompany/mycustomnginx/nginx-conf/nginx.conf -g "daemon    off;"

Then, changed the dockerfile to execute my run script as follows The CMD command can be called once and dictates where is the script located that is executed when the Deployment pod starts.

FROM registry.access.redhat.com/rhscl/nginx-120

# Add application sources to a directory that the assemble script expects them
# and set permissions so that the container runs without root access
USER 0

COPY dist/my-portal /tmp/src

COPY --chmod=0755 s2i /tmp/
RUN ls -la /tmp
USER 1001

# Let the assemble script to install the dependencies
RUN /usr/libexec/s2i/assemble

# Run script uses standard ways to run the application
#CMD /usr/libexec/s2i/run
# here we override the script that will be executed when the deployment pod starts
CMD /tmp/run

Upvotes: 0

Will Gordon
Will Gordon

Reputation: 3583

you will need to call out the original "assemble" script from your own. Similar to this

#!/bin/bash -e
# The assemble script builds the application artifacts from a source and 
# places them into appropriate directories inside the image.

# Execute the default S2I script
source ${STI_SCRIPTS_PATH}/assemble

# You can write S2I scripts in any programming language, as long as the 
# scripts are executable inside the builder image.

Upvotes: 2

Related Questions