Skip to main content
Redhat Developers  Logo
  • AI

    Get started with AI

    • Red Hat AI
      Accelerate the development and deployment of enterprise AI solutions.
    • AI learning hub
      Explore learning materials and tools, organized by task.
    • AI interactive demos
      Click through scenarios with Red Hat AI, including training LLMs and more.
    • AI/ML learning paths
      Expand your OpenShift AI knowledge using these learning resources.
    • AI quickstarts
      Focused AI use cases designed for fast deployment on Red Hat AI platforms.
    • No-cost AI training
      Foundational Red Hat AI training.

    Featured resources

    • OpenShift AI learning
    • Open source AI for developers
    • AI product application development
    • Open source-powered AI/ML for hybrid cloud
    • AI and Node.js cheat sheet

    Red Hat AI Factory with NVIDIA

    • Red Hat AI Factory with NVIDIA is a co-engineered, enterprise-grade AI solution for building, deploying, and managing AI at scale across hybrid cloud environments.
    • Explore the solution
  • Learn

    Self-guided

    • Documentation
      Find answers, get step-by-step guidance, and learn how to use Red Hat products.
    • Learning paths
      Explore curated walkthroughs for common development tasks.
    • Guided learning
      Receive custom learning paths powered by our AI assistant.
    • See all learning

    Hands-on

    • Developer Sandbox
      Spin up Red Hat's products and technologies without setup or configuration.
    • Interactive labs
      Learn by doing in these hands-on, browser-based experiences.
    • Interactive demos
      Click through product features in these guided tours.

    Browse by topic

    • AI/ML
    • Automation
    • Java
    • Kubernetes
    • Linux
    • See all topics

    Training & certifications

    • Courses and exams
    • Certifications
    • Skills assessments
    • Red Hat Academy
    • Learning subscription
    • Explore training
  • Build

    Get started

    • Red Hat build of Podman Desktop
      A downloadable, local development hub to experiment with our products and builds.
    • Developer Sandbox
      Spin up Red Hat's products and technologies without setup or configuration.

    Download products

    • Access product downloads to start building and testing right away.
    • Red Hat Enterprise Linux
    • Red Hat AI
    • Red Hat OpenShift
    • Red Hat Ansible Automation Platform
    • See all products

    Featured

    • Red Hat build of OpenJDK
    • Red Hat JBoss Enterprise Application Platform
    • Red Hat OpenShift Dev Spaces
    • Red Hat Developer Toolset

    References

    • E-books
    • Documentation
    • Cheat sheets
    • Architecture center
  • Community

    Get involved

    • Events
    • Live AI events
    • Red Hat Summit
    • Red Hat Accelerators
    • Community discussions

    Follow along

    • Articles & blogs
    • Developer newsletter
    • Videos
    • Github

    Get help

    • Customer service
    • Customer support
    • Regional contacts
    • Find a partner

    Join the Red Hat Developer program

    • Download Red Hat products and project builds, access support documentation, learning content, and more.
    • Explore the benefits

Maven mirrors on OpenShift with and without Source to Image (S2I)

June 3, 2016
James Falkner
Related topics:
Developer toolsKubernetes
Related products:
Red Hat JBoss Enterprise Application PlatformRed Hat OpenShift Container Platform

    velocimetroI'm guessing if you've done enough repeated builds on OpenShift, using Maven, that you are probably aware of the "download the internet" phenomenon that plagues build times. You start a build, expecting all those Maven dependencies you downloaded for your last build to be re-used, but quickly see your network traffic ramp up while the same 100MB of jars are downloaded again and again. Even builds of a few minutes tend to grind on me, frustrate me as a developer when I'm trying to test/deploy/fix quickly.

    Thankfully, Maven has a nice feature that allows you to set up local mirrors that cache dependencies and make them available to future builds, only updating from the upstream repo as needed on a regular (and configurable) schedule.

    For those using OpenShift, and in particular many of the available JBoss S2I images, you can:

    • Use incremental builds to save Maven dependencies after a build, and re-use them during subsequent builds
    • Setup a local Maven mirror and set a buildtime environment variable MAVEN_MIRROR_URL that points to it.
    • Extend existing Source to Image (S2I) builder images to provide a custom settings.xml

    Jorge outlines how to do all these in an awesome blog post.

    Maven mirrors for Docker-based builds

    When using S2I, you more or less get the Maven mirror capability for free. And for production use, I would recommend creating or extending S2I images as Jorge outlined. But what if there is no S2I images available for you to use? In my case, I wanted the Maven mirror behavior and wanted to use JBoss EAP 7 Beta and a Keycloak adapter to SSO-enable my app. Unfortunately, the available S2I image for EAP 7 doesn't include Keycloak, and the Keycloak adapter docker image is based on EAP 6. so I had two choices:

    • Create a new S2I image by extending the existing EAP 7 Beta S2I image and modifying (extending) its S2I assemble script to add the Keycloak adapter
    • Use a Docker build (FROM the EAP 7 Beta S2I image), injecting the local Maven mirror and Keycloak adapter

    My workflow isn't advanced enough to be able to keep track of custom build images, so I went with option 2 and put in some logic into my Dockerfile:

    # Use EAP 7 Beta as a base image
    FROM jboss-eap-7-beta/eap70-openshift
    
    ENV KEYCLOAK_VERSION 1.9.4.Final
    
    # add maven mirror
    RUN sed -i -e 's/<mirrors>/&\n    <mirror>\n      <id>sti-mirror<\/id>\n      <url>${env.MAVEN_MIRROR_URL}<\/url>\n      <mirrorOf>external:*<\/mirrorOf>\n    <\/mirror>/' ${HOME}/.m2/settings.xml
    
    # install adapter
    WORKDIR ${JBOSS_HOME}
    RUN curl -L https://downloads.jboss.org/keycloak/$KEYCLOAK_VERSION/adapters/keycloak-oidc/keycloak-wildfly-adapter-dist-$KEYCLOAK_VERSION.tar.gz | tar zx
    
    # Standalone.xml modifications.
    RUN sed -i -e 's/<extensions>/&\n        <extension module="org.keycloak.keycloak-adapter-subsystem"\/>/' $JBOSS_HOME/standalone/configuration/standalone-openshift.xml && \
        sed -i -e 's/<profile>/&\n        <subsystem xmlns="urn:jboss:domain:keycloak:1.1"\/>/' $JBOSS_HOME/standalone/configuration/standalone-openshift.xml && \
        sed -i -e 's/<security-domains>/&\n                <security-domain name="keycloak">\n                    <authentication>\n                        <login-module code="org.keycloak.adapters.jboss.KeycloakLoginModule" flag="required"\/>\n                    <\/authentication>\n                <\/security-domain>/' $JBOSS_HOME/standalone/configuration/standalone-openshift.xml
    
    # perform the build
    
    RUN mvn package
    
    # after build, copy artifacts (e.g. .war files from target/) to deploy directory (e.g. $JBOSS_HOME/standalone/deployments)

    Notice the use of ${env.MAVEN_MIRROR_URL} in the Dockerfile. This must be set as an environment variable in your OpenShift BuildConfig so that the Dockerfile picks it up.

    Screen Shot 2016-05-24 at 12.05.04 PM

    Also note the fancy sed command to alter the standalone-openshift.xml file (this is the EAP configuration file in use when EAP runs on OpenShift). It would have been nice to be able to invoke Keycloak's adapter-install-offline.cli file, but unfortunately the shenanigans the base image goes through to launch EAP in OpenShift renders jboss-cli.sh pretty much useless.

    Finally, note the URL above is the public endpoint (route) to the Nexus server. S2I builds on OpenShift are able to use an internal hostname (such as nexus.ci.svc.cluster.local) to get to the Nexus server at buildtime, but unfortunately for Docker-based builds, this naming is not configured in the underlying container (it is only possible for S2I builds at the moment.)

    Last updated: March 18, 2024

    Recent Posts

    • Tekton joins the CNCF as an incubating project

    • Federated identity across the hybrid cloud using zero trust workload identity manager

    • Confidential virtual machine storage attack scenarios

    • Introducing virtualization platform autopilot

    • Integrate zero trust workload identity manager with Red Hat OpenShift GitOps

    Red Hat Developers logo LinkedIn YouTube Twitter Facebook

    Platforms

    • Red Hat AI
    • Red Hat Enterprise Linux
    • Red Hat OpenShift
    • Red Hat Ansible Automation Platform
    • See all products

    Build

    • Developer Sandbox
    • Developer tools
    • Interactive tutorials
    • API catalog

    Quicklinks

    • Learning resources
    • E-books
    • Cheat sheets
    • Blog
    • Events
    • Newsletter

    Communicate

    • About us
    • Contact sales
    • Find a partner
    • Report a website issue
    • Site status dashboard
    • Report a security problem

    RED HAT DEVELOPER

    Build here. Go anywhere.

    We serve the builders. The problem solvers who create careers with code.

    Join us if you’re a developer, software engineer, web designer, front-end designer, UX designer, computer scientist, architect, tester, product manager, project manager or team lead.

    Sign me up

    Red Hat legal and privacy links

    • About Red Hat
    • Jobs
    • Events
    • Locations
    • Contact Red Hat
    • Red Hat Blog
    • Inclusion at Red Hat
    • Cool Stuff Store
    • Red Hat Summit
    © 2026 Red Hat

    Red Hat legal and privacy links

    • Privacy statement
    • Terms of use
    • All policies and guidelines
    • Digital accessibility

    Chat Support

    Please log in with your Red Hat account to access chat support.