Chapter 3. Using source-to-image for OpenShift You can use the source-to-image (S2I) for OpenShift image to run your custom Java applications on OpenShift. 3.1. Building and deploying Java applications with source-to-image for OpenShift To build and deploy a Java application from source on OpenShift by using the source-to-image (S2I) for OpenShift image, use the OpenShift S2I process. Procedure Log in to the OpenShift instance by running the following command and by providing your credentials: Create a new project: Create a new application using the S2I for OpenShift image: The <source-location> is the URL of GitHub repository or path to a local folder. For example: Get the service name: Expose the service as a route, so that you can use the server from your browser: Get the route: Access the application in your browser by using the URL. Use the value of HOST/PORT field from the command's output. Additional resources For more detailed example, see the Running flat classpath JAR on source-to-image for OpenShift . 3.2. Building and deploying Java applications from binary artifacts You can deploy your existing Java applications on OpenShift by using the binary source capability. The procedure uses undertow-servlet quickstart to build a Java application on your local machine. The quickstart copies the resulting binary Artifacts into OpenShift by using the S2I binary source capability. Prerequisites Enable Red Hat JBoss Enterprise Maven Repository on your local machine. Get the JAR application archive and build the application locally. Clone the undertow-servlet source code: Build the application: Prepare the directory structure on the local file system. Copy the application archives in the deployments/ sub-directory (where the main binary build directory) to the standard deployments folder (where the image is build on OpenShift). Structure the directory hierarchy containing the web application data for the application to deploy. Create a main directory for the binary build on the local file system and deployments/ subdirectory within it. Copy the built JAR archive to the deployments/ subdirectory: Procedure Log in to the OpenShift instance by running the following command and by providing your credentials: Create a new project: Create a new binary build, and specify the image stream and the application's name: Start the binary build. Instruct the oc executable to use main directory of the binary build you have created in step as the directory containing binary input for the OpenShift build: Create a new OpenShift application based on the build: Expose the service as route. Get the route: Access the application in your browser by using the URL (value of HOST/PORT field from the command output). Additional resources Use the binary source capability to deploy existing Java applications on OpenShift. For more information on how to configure maven repository, see Use the Maven Repository .

Commands:
oc login
oc new-project <project-name>
oc new-app <source-location>
oc new-app --context-dir=getting-started --name=quarkus-quickstart 'registry.access.redhat.com/ubi8/openjdk-11~https://github.com/quarkusio/quarkus-quickstarts.git#2.12.1.Final'
oc get svc
oc expose svc/ --port=8080
oc get route
git clone https://github.com/jboss-openshift/openshift-quickstarts.git
cd openshift-quickstarts/undertow-servlet/
mvn clean package [INFO] Scanning for projects [INFO] [INFO] ------------------------------------------------------------------------ [INFO] Building Undertow Servlet Example 1.0.0.Final [INFO] ------------------------------------------------------------------------ [INFO] ------------------------------------------------------------------------ [INFO] BUILD SUCCESS [INFO] ------------------------------------------------------------------------ [INFO] Total time: 1.986 s [INFO] Finished at: 2017-06-27T16:43:07+02:00 [INFO] Final Memory: 19M/281M [INFO] ------------------------------------------------------------------------
undertow-servlet]USD ls dependency-reduced-pom.xml pom.xml README src target
mkdir -p ocp/deployments
cp target/undertow-servlet.jar ocp/deployments/
oc login
oc new-project jdk-bin-demo
oc new-build --binary=true --name=jdk-us-app --image-stream=java:11 --> Found image c1f5b31 (2 months old) in image stream "openshift/java:11" under tag "latest" for "java:11" Java Applications ----------------- Platform for building and running plain Java applications (fat-jar and flat classpath) --> Creating resources with label build=jdk-us-app imagestream "jdk-us-app" created buildconfig "jdk-us-app" created --> Success Application is not exposed. You can expose services to the outside world by executing one or more of the commands below: 'oc expose svc/jdk-us-app'
oc start-build jdk-us-app --from-dir=./ocp --follow Uploading directory "ocp" as binary input for the build build "jdk-us-app-1" started Receiving source from STDIN as archive ================================================================== Starting S2I Java Build .. S2I source build with plain binaries detected Copying binaries from /tmp/src/deployments to /deployments ... done Pushing image 172.30.197.203:5000/jdk-bin-demo/jdk-us-app:latest Pushed 0/6 layers, 2% complete Pushed 1/6 layers, 24% complete Pushed 2/6 layers, 36% complete Pushed 3/6 layers, 54% complete Pushed 4/6 layers, 71% complete Pushed 5/6 layers, 95% complete Pushed 6/6 layers, 100% complete Push successful
oc new-app jdk-us-app --> Found image 66f4e0b (About a minute old) in image stream "jdk-bin-demo/jdk-us-app" under tag "latest" for "jdk-us-app" jdk-bin-demo/jdk-us-app-1:c1dbfb7a ---------------------------------- Platform for building and running plain Java applications (fat-jar and flat classpath) Tags: builder, java * This image will be deployed in deployment config "jdk-us-app" * Ports 8080/tcp, 8443/tcp, 8778/tcp will be load balanced by service "jdk-us-app" * Other containers can access this service through the hostname "jdk-us-app" --> Creating resources deploymentconfig "jdk-us-app" created service "jdk-us-app" created --> Success Run 'oc status' to view your app.
oc expose svc/jdk-us-app route "jdk-us-app" exposed
oc get route