Openshift offers a whole pipeline to create container images directly from source code.
It is usable for general purpose Java applications as well as for Fuse Integration Service projects.
This post will present how to accelerate the build time of those images by setting up a local Nexus Repository and configuring application templates
to use this repository for the build process. The idea is not having to download from the Internet all the FIS maven dependencies when building a new project.
At the time of writing FIS 2.0 is available as tech preview.
(update 22/02/2017) February 21, 2017 : FIS 2.0 GA has been released.
The method shown here doesn't use the MVN_MIRROR_URL parameter which was enabled in FIS 2.0.
This will work on FIS 2.0 and also FIS 1.0.
JDK 1.8+ installed
Maven 3.3+ installed
Setting up a Nexus repository
The reason why build times can be long with the source S2I pipeline is because each new application build requires to spin up a
S2I container to launch the maven goals in order to package your application.
Building the same application template after the first time is faster because the downloaded artifacts are reused.
But every time we create a new application, it will go through the same initial downloading process again.
That is why instead of having the S2I container download everything from Internet repositories each time,
we can setup a Nexus server that will proxy these repositories and store already downloaded artifacts locally.
Here we will show how to setup a local standalone Nexus2 repository
Add these dependencies to the pom.xml file in order to create a JSON Rest Webservice.
Create routes to expose a rest webservice
Open the camel-context.xml file to create the following RestConfigurations and routes.
To avoid a tcp port conflict with the default Nexus port (8081), make sure to change the parameter "management.port" in
the resources/application.properties file. You can change it to 8086 for example.
Run the project locally to see if everything is fine. Go to the root folder of your project.
Call the service using a browser/
Create a settings.xml file
At the root of your project copy your current maven settings.xml file
(the one with all the repositories defined) and add a mirror bloc as follows.
This will be used later by Openshift S2I. It there to configure Maven to get artifacts from your local Nexus repository.
Deploy on Openshift using S2i
Connect to your Openshift instance using the "oc" command
The important parameters to change in the template are the following.
The most important change is the following MAVEN_ARGS parameter. It is where we point to the Nexus repo we created and where we use
the settings.xml file at to root of the project.
Note that the IP address here 172.17.0.1 is the one that belongs to the host machine bound to the docker network interface. Adapt
it to your situation if necessary.
You should also add the following parameter to tweak the heap size of the JVM used for the maven build. In some rare cases you could run into an out of heap space exception.
It is always good to keep control over this parameter.
Add the environment parameter MAVEN_OPTS in the sourceStrategy bloc of the buildConfig so it is taken into account in the Maven command
We should also add the service and routes to expose the Rest service to the external world
Note that the build takes only about 2 minute the second time you run it instead of 20 minutes (in my case with a not so fast internet connection). This is thanks to the fact that the maven dependencies are
taken from the local Nexus instead of being downloaded from the Internet.