X

Step Up to Modern Cloud Development

Build and Deploy a Helidon Microservice Using Oracle Developer Cloud

Abhinav Shroff
Principal Product Manager

Project Helidon was recently introduced by Oracle. It provides a new way to write microservices. This blog will help you understand how use Oracle Developer Cloud to build and deploy your first Helidon-based microservice on Oracle Container Engine for Kubernetes.

Before we begin, let’s examine a few things:

What is Helidon?

Project Helidon is a set of Java Libraries for writing microservices.  Helidon supports two programming models: Helidon MP, based on MicroProfile 1.2, and Helidon SE, a small, functional style API.

Regardless of which model you choose, you’ll be writing an application that is a Java SE-based program. Helidon is open source and the code is available on GitHub.  To read and learn more about Project Helidon, see the following links:

Get Started

Helidon doesn’t have downloads. Instead, you’ll need to use the Maven releases. This means that you’ll be using the Maven Archetype to get started with your Helidon microservice project. In this blog, we’ll be using the Helidon SE programming model.

The following basic prerequisites should be installed on your machine to develop with Helidon:

  • Maven
  • Java 8
  • Gitcli (for pushing code to the Oracle Developer Cloud Git repository)

Download the Sample Microservice Project for Helidon with Maven

Open the command prompt, if you’re using a Windows machine. Then go to (or create) the directory or folder where you’d like to create the sample Helidon microservice project and execute the following Maven command.

mvn archetype:generate -DinteractiveMode=false \

    -DarchetypeGroupId=io.helidon.archetypes \

    -DarchetypeArtifactId=helidon-quickstart-se \

    -DarchetypeVersion=1.1.0 \

    -DgroupId=io.helidon.examples \

    -DartifactId=helidon-quickstart-se \

    -Dpackage=io.helidon.examples.quickstart.se

 

When executed, this Maven command will create the helidon-quickstart-se folder.

The microservice application code, the build files, and the deployment files all reside in the helidon-quickstart-se folder.

 

These are the files and folder(s):

  • src folder –  Contains the microservice application source code
  • app.yml – Describes the Kubernetes deployment
  • Dockerfile – Provides instructions for building the Docker image
  • Dockerfile.native – Provides instructions for building the Docker image using the Graal VM
  • Pom.xml – Project descriptor for the Maven build
  • README.md –  File that contains a description of the project

 

Now let’s create an Oracle Developer Cloud project with a Git repository. We’ll call the Git repository Helidon.git.

 

Navigate to the helidon-quickstart-se folder in your command prompt window and execute the following Git commands to push the Helidon microservice application code to the Git repository you created.

Note: You need to have gitcli installed on your development machine to execute Git commands.

git init

git add --all

git commit -m "First commit"

git remote add origin <git repository url>

git push origin master

 

Your Helidon.git repository should have the structure shown below.

 

Configure the Build Job

In Developer Cloud, select Builds in the left navigation bar to display the Builds page. Then click the +Create Job button.  

In the New Job dialog, enter BuildHelidon for the Name and select a Template that has the Docker runtime. Then click the Create button. This build job will build Docker image for the Helidon Microservice code in the Git repository and push it to the DockerHub registry.

In the Git tab, select Git from the Add Git dropdown, select Helidon.git as the Git repository and, for the branch, select master.

 

In the Steps tab, use the Add Step dropdown to add Docker login, Docker build, and Docker push steps.

In the Docker login step, provide your DockerHub Username and Password. Leave the Registry Host empty, since we’re using DockerHub as the registry.

In the Docker build step, enter <DockerHub Username>/helidonmicro for the Image Name and 1,0 for the Version Tag. The full image name shown is <DockerHub Username>/helidonmicro:1.0

 

In the Docker push step, enter <DockerHub Username>/helidonmicro for the Image Name and 1.0 for the Version Tag. Then click the Save button.

Before we create the build job that will deploy the Helidon Microservice Docker container, you need to edit the app.yaml file and modify the Docker image name. To edit that file, go to the Git page, select the Helidon.git repository, and click the app.yml file link.

 

Click the pencil icon to edit the file.

 

Replace the image name with <your DockerHub username>/helidonmicro:1.0, then click the Commit button to commit the code changes to the master branch.

 

To create another build job, navigate to the Builds page and click the +Create Job button. 

In the New Job dialog enter DeployHelidon for the Name, select the template with Kubectl, then click the Create button. This build job will deploy the Docker image built by the BuildHelidon build job to the Kubernetes cluster.

 

The first thing you’ll do to configure the DeployHelidon build job is to specify the repository where the code is found and select the branch where you’ll be working on the files.  To do this, in the Git tab, add Git from the dropdown, select Helidon.git as the Git repository and, for the branch, select master.

In the Steps tab, select OCIcli and Unix Shell from the Add Step drop down. Take a look at this blog link to see how and where to get the values for the OCIcli configuration. Then, in the Unix Shell build step, enter the following script. You can get the Kubernetes Cluster Id from the Oracle Cloud Infrastructure console. 

mkdir -p $HOME/.kube
oci ce cluster create-kubeconfig --cluster-id  --file $HOME/.kube/config --region us-ashburn-1
export KUBECONFIG=$HOME/.kube/config

kubectl create -f app.yaml
sleep 30
kubectl get services helidon-quickstart-se
kubectl get pods
kubectl describe pods

When you’re done, click the Save button.

 

Create the Build Pipeline

Navigate to the Pipelines tab in the Builds page. Then click the +Create Pipeline button.

 

In the Create Pipeline dialog, you can enter the Name as HelidonPipeline. Then click the Create button.

Drag and drop the BuildHelidon and DeployHelidon build jobs and then connect them.

 

Double click the link that connects the build jobs and select Successful as the Result Condition. Then click the Apply button.

 

Click the Build button, as shown, to run the build pipeline. The BuildHelidon build job will be executed first and, if it is successful, then the DeployHelidon build job that deploys the container on the Kubernetes cluster on Oracle Cloud will be executed next.

 

After the jobs in the build pipeline finish executing, navigate to the Jobs tab and click the link for the DeployHelidon build job.  Then click the log icon for the executed build. You should see messages that the service and deployment were successfully created.  Now, for the helidon-quickstart-se service and deployment that were created on the Kubernetes cluster, search the log, and find the public IP address and port to access the microservice, as shown below.

 

 

Enter the IP address and port that you retrieved from the log, into the browser using the format shown in the following URL:

http://<retrieved IP address>:<retrieved port>/greet

You should see the “Hello World!” message in your browser.

 

 

So, you’ve seen how Oracle Developer Cloud can help you manage the complete DevOps lifecycle for your Helidon-based microservices and how out-of-the-box support for Build and Deploy to Oracle Container Engine for Kubernetes makes it easier.

To learn more about other new features in Oracle Developer Cloud, take a look at the What's New in Oracle Developer Cloud Service document and explore the links it provides to our product documentation. If you have any questions, you can reach us on the Developer Cloud Slack channel or in the online forum.

Happy Coding!

**The views expressed in this post are my own and do not necessarily reflect the views of Oracle

Join the discussion

Comments ( 1 )
  • Vishnu Friday, May 31, 2019
    Nice Article.
Please enter your name.Please provide a valid email address.Please enter a comment.CAPTCHA challenge response provided was incorrect. Please try again.Captcha

Recent Content