Defining customized logic with extension points
In this lesson, you define customized Docker start-up logic with the extension point shell script.
About this task
HCL Commerce V9 has two pre-defined extension points before the Docker main process is started, so you can adopt a more flexible way to customize the docker image start-up logic.
The two extension points are executed before the application servers are started. You can define what you want to do in preconfigue.sh and cusConfiguration.sh before the server starts in the Docker image. All the complex logic can be defined in preConfigure.sh and cusCunfiguration.sh. In the Dockerfile, you only need to define the logic to copy these two customization shell files to the Docker image. Then you do not need to change the Docker image when you want to change the logic associated with these two customization shell. In this way, you can only download the customization package in the preconfigure.sh and roll out the configuration change in cusCunfiguration.sh.
Procedure
- Create a new cus folder in the local environment.
-
Create a preConfigure.sh file in the local folder to include the following
code lines:
#!/bin/bash wget -O '/opt/WebSphere/Liberty/usr/servers/default/crs-app-cus.zip ' "http://nexusServer:8081/nexus/service/local/artifact/maven/redirect?r=snapshots&g=crs-app-cus&a=crs-app-cus&v=@version@&p=zip" && \ unzip /opt/WebSphere/Liberty/usr/servers/default/crs-app-cus.zip -d /opt/WebSphere/Liberty/usr/servers/default/
-
Create a custConfiguration.sh file in the local folder to include the
following code lines:
#!/bin/bash sed -i '$a\-javaagent:./jmx_prometheus_javaagent-0.3.1.jar=8080:config.yaml' /opt/WebSphere/Liberty/usr/servers/default/jvm.options
-
Create a Docker file to include the following code lines:
FROM docker-repo/commerce/crs-app:tag COPY preConfigure.sh /SETUP/bin/ COPY custConfiguration.sh /SETUP/bin
-
Build the customized Docker image:
docker build -t docker-repo/commerce/crs-app:cus
Results
This new Docker image does not include the customization package and the shell logic to change the configuration file. However, this image knows what it should do when the container is started using the preConfiguation.sh and custConfiguration.sh scripts. Only two files are added to the base Docker image, so the image size is minimum. If you want to change the customization logic, change the preconfigure.sh and custConfiguration.sh files.
The drawback of this method is that you can define the customized logic only with the shell script. When the customized logic is complex, it might be difficult to define it in the shell script. If it is the case, consider defining the logic in run engine commands.