Customize the assemble and run scripts of an Apache HTTP server builder image.
Override the default built-in scripts.
Outcomes
Customize the assemble and run scripts of an Apache HTTP server builder image.
Override the default built-in scripts.
As the student user on the workstation machine, use the lab command to prepare your system for this exercise.
[student@workstation ~]$ lab start builds-s2i
Instructions
Explore the S2I scripts packaged in the rhscl/httpd-24-rhel7 builder image.
Authenticate Podman running on the workstation by logging in to the classroom image registry.
[student@workstation ~]$ podman login \
-u developer -p developer \
registry.ocp4.example.com:8443
Login Succeeded!Use Podman to create a container from the httpd-24 container image.
Override the container entry point to run a shell.
[student@workstation ~]$ podman run --name webserver -it --rm \
registry.ocp4.example.com:8443/ubi9/httpd-24 bash
...output omitted...
bash-5.1$Inspect the S2I scripts packaged in the builder image.
The S2I scripts are located in the /usr/libexec/s2i folder.
bash-5.1$ cat /usr/libexec/s2i/assemble ...output omitted... bash-5.1$ cat /usr/libexec/s2i/run ...output omitted... bash-5.1$ cat /usr/libexec/s2i/usage ...output omitted...
Exit from the container.
bash-5.1$ exit
Review the application source code with the custom S2I scripts.
Change to the directory containing the application.
[student@workstation ~]$cd ~/DO288/DO288-apps/labs/builds-s2i/s2i-scriptsno output expected
Inspect the index.html file.
[student@workstation s2i-scripts]$ cat index.html
Hello Class! DO288 rocks!!!The custom S2I scripts are in the .s2i/bin folder.
Inspect the assemble script.
[student@workstation s2i-scripts]$cat .s2i/bin/assemble...output omitted... CUSTOMIZATION STARTS HERE echo "---> Installing application source" cp -Rf /tmp/src/*.html ./ DATE=date "+%b %d, %Y @ %H:%M %p"echo "---> Creating info page" echo "Page built on $DATE" >> ./info.html echo "Proudly served by Apache HTTP Server version $HTTPD_VERSION" >> ./info.html CUSTOMIZATION ENDS HERE ...output omitted...
This script copies the index.html file from the application source to the web server document root at /opt/app-root/src.
It also creates an info.html file containing page build time and environment information.
Inspect the run script.
[student@workstation s2i-scripts]$cat .s2i/bin/run...output omitted... # Make Apache show 'debug' level logs during startup exec run-httpd-e debug$@
This script changes the default log level of the startup messages in the web server to debug.
Deploy the application to a Red Hat OpenShift cluster. Verify that the custom S2I scripts are executed.
Log in to OpenShift as the developer user.
[student@workstation s2i-scripts]$ oc login -u developer -p developer \
https://api.ocp4.example.com:6443
Login successful.
...output omitted...Ensure that you use the builds-s2i project.
[student@workstation s2i-scripts]$ oc project builds-s2i
...output omitted...Create a new application called bonjour from the provided sources.
You need to prefix the Git URL with the httpd:2.4 image stream, by using the tilde notation (~), to ensure that the application uses the rhscl/httpd24-rhel7 builder image.
Ignore the security warning.
[student@workstation s2i-scripts]$ oc new-app --name bonjour \
--context-dir labs/builds-s2i/s2i-scripts \
registry.ocp4.example.com:8443/ubi9/httpd-24~https://git.ocp4.example.com/\
developer/DO288-apps
...output omitted...
--> Creating resources ...
imagestream.image.openshift.io "httpd-24" created
imagestream.image.openshift.io "bonjour" created
...output omitted...
buildconfig.build.openshift.io "bonjour" created
deployment.apps "bonjour" created
service "bonjour" created
--> Success
...output omitted...Wait until the build finishes and the application container image is pushed to the OpenShift internal registry.
[student@workstation s2i-scripts]$oc get buildNAME ... STATUS ... bonjour-1 ...Complete...
View the build logs.
[student@workstation s2i-scripts]$ oc logs -f bc/bonjour
...output omitted...
Cloning "https://git.ocp4.example.com/developer/DO288-apps" ...
...output omitted...
STEP 9/10: RUN /tmp/scripts/assemble
---> Enabling s2i support in httpd24 image
AllowOverride All
---> Installing application source
---> Creating info page
STEP 10/10: CMD /tmp/scripts/run
COMMIT temp.builder.openshift.io/builds-s2i/bonjour-1:986469c8
...output omitted...
Push successfulObserve that the custom S2I scripts provided by the application are executed instead of the built-in S2I scripts from the builder image.
Test the application.
Wait until the application is deployed and then view the status of the application pod.
The application pod should be in the Running state.
[student@workstation s2i-scripts]$oc get poNAME READY STATUS RESTARTS AGE bonjour-1-build 0/1 Completed 0 105s bonjour-7bc86dd97-wjvhx1/1Running0 72s
Expose the application for external access by using a route.
[student@workstation s2i-scripts]$ oc expose svc bonjour
route.route.openshift.io/bonjour exposedObtain the route URL by using the oc get route command.
[student@workstation s2i-scripts]$oc get routeNAME HOST/PORT ... bonjourbonjour-builds-s2i.apps.ocp4.example.com...
Retrieve the index page of the application with the URL from the previous step.
[student@workstation s2i-scripts]$ curl \
http://bonjour-builds-s2i.apps.ocp4.example.com
Hello Class! DO288 rocks!!!Retrieve the info page of the application.
[student@workstation s2i-scripts]$ curl \
http://bonjour-builds-s2i.apps.ocp4.example.com/info.html
Page built on ...output omitted...
Proudly served by Apache HTTP Server version 2.4Inspect the logs for the application pod.
Recall that the startup log level was changed to debug in the run script.
You should see debug level log messages being displayed at startup.
[student@workstation s2i-scripts]$ oc logs deploy/bonjour
...output omitted...
10.8.0.2 - - [16/Oct/2023:20:38:50 +0000] "GET / HTTP/1.1" 200 28 "-" "curl/7.61.1"
10.8.0.2 - - [16/Oct/2023:20:40:25 +0000] "GET /info.html HTTP/1.1" 200 87 "-" "curl/7.61.1"