In the past you have seen how OpenShift can take your existing java code, build it and deploy the resultant docker image as an application. OpenShift S2I process includes an assemble script that copies the source code from a git repository, invokes a maven build, places the resultant war file in the deployments folder, builds a new application image and pushes that image into the registry.
But how about if you want OpenShift to deploy a war file that you built yourself?
In this exercise you will learn to deploy a war file. We will assume that you built your source code outside of OpenShift build process and want to download the WAR file on your workstation.
Step 1: Create project & folder structure
oc new-project binarydeploy-UserName
mkdir binarytest && cd binarytest
mkdir deployments
Step 1: Create war file
Create a war file and place it in deployments directory.
As an example here we have a WAR file called petstore.war
that we renamed to ROOT.war
and placed in the deployments folder (you can download this example WAR file here).
$ ls -lR
total 0
drwxr-xr-x 3 veer staff 102 Jul 5 2015 deployments
./deployments:
total 12024
-rwxr-xr-x 1 veer staff 6155452 Jul 5 2015 ROOT.war
Step 2: Using builder image
Create a new build using the builder image of your choice. Here we are using JBoss EWS (tomcat 8) image. The flag binary=true
indicates that this build will use the binary content instead of the url to the source code.
Here I am naming my application as myapp. So all the artifacts will get the name myapp.
$ oc new-build --image-stream=jboss-webserver30-tomcat8-openshift --binary=true --name=myapp
--> Found image 58272fb (11 weeks old) in image stream "jboss-webserver30-tomcat8-openshift" in project "openshift" under tag "latest" for "jboss-webserver30-tomcat8-openshift"
JBoss Web Server 3.0
--------------------
Platform for building and running web applications on JBoss Web Server 3.0 - Tomcat v8
Tags: builder, java, tomcat8
* A source build using binary input will be created
* The resulting image will be pushed to image stream "myapp:latest"
* Use 'start-build --from-dir=DIR|--from-repo=DIR|--from-file=FILE' to trigger a new build
* WARNING: a binary build was created, you must specify one of --from-dir|--from-file|--from-repo when starting builds
--> Creating resources with label build=myapp ...
imagestream "myapp" created
buildconfig "myapp" created
--> Success
Step 3: Executing the build
Start the build by uploading the contents of your deployments
directory. Make sure you are in the parent folder where you created the deployments
folder inside previously. Remember the war file is in the deployments
folder. The jboss-ews builder image knows to copy the contents of the deployments
folder to the deployments
directory and then builds the application image.
$ oc start-build myapp --from-dir=.
Uploading directory "." as binary input for the build ...
build "myapp-1" started
You can check the build logs by executing:
$ oc logs myapp-1-build
Receiving source from STDIN as archive ...
Copying all deployments war artifacts from /home/jboss/source/deployments directory into /opt/webserver/webapps for later deployment...
'/home/jboss/source/deployments/ROOT.war' -> '/opt/webserver/webapps/ROOT.war'
Pushing image 172.30.89.28:5000/mycliproject-admin/myapp:latest ...
Pushed 0/6 layers, 2% complete
Pushed 1/6 layers, 18% complete
Pushed 2/6 layers, 40% complete
Pushed 3/6 layers, 54% complete
Pushed 4/6 layers, 83% complete
Pushed 5/6 layers, 93% complete
Pushed 6/6 layers, 100% complete
Push successful
Step 4: Create the application
Now create the application with the same name as what you gave for the build.
Here we are using the name myapp, so that the rest of the objects such as deployment configuration and service are created with the same name and refer to the image-stream created earlier.
$ oc new-app myapp --allow-missing-imagestream-tags
--> Found image d4954db (4 minutes old) in image stream myapp under tag "latest" for "myapp"
mycliproject-admin/myapp-1:cd51ae53
-----------------------------------
Platform for building and running web applications on JBoss Web Server 3.0 - Tomcat v8
Tags: builder, java, tomcat8
* This image will be deployed in deployment config "myapp"
* Ports 8080/tcp, 8443/tcp, 8778/tcp will be load balanced by service "myapp"
* Other containers can access this service through the hostname "myapp"
--> Creating resources with label app=myapp ...
deploymentconfig "myapp" created
service "myapp" created
--> Success
Run 'oc status' to view your app.
Now, expose the service as a route to be able to use it from the browser.
$ oc expose svc myapp
route "myapp" exposed
You can use the route to access the application using the URL.