One of the great things about OpenShift 3 is the ability for developers who enjoy using an IDE to interact with the platform without leaving the comfort of their development environment. In this blog post I will show you how to get up and running with OpenShift 3 using the Eclipse IDE and the accompanying JBoss Tools plugin.
Note: Although I will be showing how to use Eclipse and JBoss Tools, a great option that you might want to check out is JBoss Developer Studio (JBDS). You can find out more information about this IDE as well as download the latest version of JBDS at the official site.
Step 1: Download and execute Eclipse
Chances are, if you are reading this blog post, you already have Eclipse installed and ready to go. Hopefully you are running the Neon version of this IDE as that is what we will be using in this post. If you haven't used Eclipse before, now is the perfect time to try it out. Head over to the official download site for the Neon release and select download the correct distribution for your operating system. For this post, I will be using the Eclipse IDE for Java EE Developers 64bit distribution as shown in the following image:
Once you have eclipse downloaded, you will need to extract the contents of the archive which will be in either zip or tar.gz format. For example, the package I download is named eclipse-jee-neon-RC3-macosx-cocoa-x86_64.tar.gz so I would enter in the following command to extract the contents:
$ tar zxvf eclipse-jee-neon-RC3-macosx-cocoa-x86_64.tar.gz
On MacOS this creates a Eclipse.app executable that I can launch. On Windows or Linux, you will see a new directory that has been created with a suitable executable for your operating system.
Once you launch Eclipse for the first time, you will be asked to define where you want your workspace to be located. A workspace is a organizational concept in Eclipse that will allow you to group projects together if working on more than one project at at time. For the purpose of this blog post, just create a new workspace at a location of your choosing and click on Next as shown in the following image:
If everything extracted and ran correctly, you will be presented with the Eclipse welcome screen as show in the following image:
Step 2: Install JBoss Tools
Installing JBoss Tools is a pretty easy and straight forward process. Simple head over to the download site and follow the instructions.
If prompted, select to install all of the tools and accept any license agreements that may be presented after reading them. The installation process can take a few minutes depending on the speed of your connection.
Step 3: Create a new project on OpenShift Online Next Gen
Now that you have Eclipse and JBoss Tools both installed, we finally get to the good part. Making good use of that shiny new OpenShift Online Next Gen dev-preview account that you have! Wait, you don't have an account yet? Sign up now!
On the JBoss Tools welcome page, select to create a new OpenShift Application as shown in the following image:
Note: You can alternatively create a new OpenShift application by selecting File->New->Other->OpenShift->OpenShift Application
The first thing that you will need define is the version of OpenShift Online that you will be working with. During this post, we are going to be using the OpenShift 3 Platform that uses native Docker and Kubernetes as the foundation. For that reason, select OpenShift 3 from the first dialog box that is presented:
You will then need to provide the server that you are working with. For the developer preview, use the following:
For the Authentication, select to use OAuth and then click on the retrieve token link:
This will open up the OpenShift Online login page inside of Eclipse. Log in using your credentials as shown in the following image:
After you have authenticated to the platform, you will be given an API token. JBoss Tools will automatically copy the token to the OpenShift dialog box once you click the close button.
Once you have authenticated to the platform, you will be able to create a new project based off of an application template that is either on the remote OpenShift Platform or on your local filesystem. For this post, we are going to use the JBoss EAP 6.4 builder image that will allow us to provide our own source code git repository.
On the next screen, you can supply a name for your application as well as specify what git repository you want to start your project with. For the purpose of this blog post, use one of your existing repositories or feel free to use the following sample application:
Remove the checkmark for enabling a webhook build trigger (if using my repo), and delete the Git Reference and Context Directory values, then click on the next button.
On the next screen of the project creation wizard, you can set any specific environment variables that you need for your application as well as specify the number of pods you want to initially start with. For the purposes of this post, leave everything as the default and then click the next button.
Lastly, we need to specify the port that our application server will listen on for on the pod as well as the port at the load balancer (service) to handle external requests. Click the Add button and then enter in 80 for the service port and 8080 for the pod port.
After clicking on the finish button, the application source code will be built and a new docker based image will be created and pushed to the registry running on OpenShift.
Step 4: View Logs
In order to interact with your application that is being created and deployed on OpenShift, click on the OpenShift Explorer at the bottom of your IDE. If this view is not shown by default, you can add it by selecting Window->Show View->Other and then selecting OpenShift Explorer.
Once you expand your project and application, you will see that is a build is running as shown in the following image:
To view the logs of the build, right click on the Build Running message and select Build Log. You will know that your application has been compiled and the new docker image deployed as a container via a pod when you see the following two messages in the log:
I0613 13:57:32.384243 1 sti.go:272] Pushing 172.30.47.227:5000/oncap/myeap2:latest image ...
I0613 14:00:52.127159 1 sti.go:288] Successfully pushed 172.30.47.227:5000/oncap/myeap2:latest
That's all there is to getting an application deployed to the OpenShift Platform from inside of Eclipse.
I only touched the surface of what you can do with the Eclipse plugin for OpenShift during this blog post. As you may have noticed during the OpenShift project creation part of this post, you could have deployed an existing project that you have been working on from within eclipse to OpenShift. Once your project is deployed, you can fully manage your application from the IDE including running new builds, syncing deployments, as well as triggering builds based of up code updates to your repository.
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