Hello there friendly OpenShift Online Next Gen traveler.  You are probably familiar with the Source-to-Image builder mechanism that allows you to push source code directly to the platform.  Using this process is quick and easy in that it allows the platform to build the source and then create a new docker image for you on the fly.  It truly seems like magic.  What's that you say friendly traveler, you don't have an account for OpenShift Online Next Gen yet?

Well then,  Sign up now!

However, one of the questions you may be asking yourself after using the developer preview for a few days is how to deploy a .war directly to OpenShift instead of relying on the platform to build your source code and resolve all of your dependencies for you (maven for example).  I am happy to report that you can do this with just a few taps of the keys at your trusty command line using the oc command line tool.
If you just simply want to try this out if you don’t a .war file ready to go, I would suggest downloading the sample war file from the apache tomcat project to use as our example.  Once you have the .war file downloaded and ready to go, we need to do a few housekeeping items.  

First, create a directory for your project on your local file system.  For example, I like to store all of my project in my ~/code directory so I would issue the following command (assuming sample.war is located in my Downloads directory):

$ mkdir sample
$ cd sample
$ cp ~/Downloads/sample.war .

 

Now that we a project directory created named sample, and our .war file located in the deployment subdirectory, it’s time to create our application.

$ oc new-app wildfly:latest~. --name mysample


This will create all of the necessary kubernetes and openshift objects required for our application.  The last thing we need to do is to create a build that will push our .war file up to the OpenShift server and deploy it.  Enter in the following command:

 

<span>$ oc start-build mysample --from-file=sample.war</span>

At this point, the file will be uploaded.  Once it has finished, that last you need to do is create a route for your application so that it is available publicly.

<span>$ oc expose svc mysample</span>

 

Boom!  That’s all there is to it.  You can view the sample application deployed via a .war file by loading the route in your browser:

<span>$ oc get routes</span>

You will see output similar to the following:

NAME      HOST/PORT                                      PATH      SERVICE            TERMINATION   LABELS

mysample   mysample-oncap.44fs.preview.openshiftapps.com             mysample:8080-tcp                 app=mysample

 

In this case, my URL is mysample-oncap.44fs.preview.openshiftapps.com so I would enter in the following:

<span>http://</span><span>mysample</span><span>-oncap.44fs.preview.openshiftapps.com/sample</span>

What's next

OpenShift Online Next Gen is now in developer preview! For more information on how to use the platform or how to sign up, check out the following:

OpenShift Online Developer Preview  FAQ


Sobre o autor

UI_Icon-Red_Hat-Close-A-Black-RGB

Navegue por canal

automation icon

Automação

Últimas novidades em automação de TI para empresas de tecnologia, equipes e ambientes

AI icon

Inteligência artificial

Descubra as atualizações nas plataformas que proporcionam aos clientes executar suas cargas de trabalho de IA em qualquer ambiente

open hybrid cloud icon

Nuvem híbrida aberta

Veja como construímos um futuro mais flexível com a nuvem híbrida

security icon

Segurança

Veja as últimas novidades sobre como reduzimos riscos em ambientes e tecnologias

edge icon

Edge computing

Saiba quais são as atualizações nas plataformas que simplificam as operações na borda

Infrastructure icon

Infraestrutura

Saiba o que há de mais recente na plataforma Linux empresarial líder mundial

application development icon

Aplicações

Conheça nossas soluções desenvolvidas para ajudar você a superar os desafios mais complexos de aplicações

Virtualization icon

Virtualização

O futuro da virtualização empresarial para suas cargas de trabalho on-premise ou na nuvem