Deploying your MicroProfile app at Oracle Container Native Platform

Rodrigo Candido da Silva
8 min readDec 17, 2018

--

MicroProfile is a base platform of specifications and APIs that optimize the Java Enterprise ecosystem for a microservices architecture offering portability for different implementations through different implementations. It was launched in 2016 in an initiative of some Java EE vendors (Red Hat, Payara, Tomitribe, IBM) and Java User Groups (SouJava and London Java Community) whose main goal was to bring innovations faster to the Java Enterprise environment. It is currently in version 2.1 supported by the Java EE 8 platform and includes the following specifications:

Source: Eclipse MicroProfile blog

Thorntail (formerly Wildfly Swarm) is one of the possible existing implementations of MicroProfile and already supports the implementation of the MicroProfile 2.1 APIs. It is a framework based on the Wildfly application server and enables the creation of small standalone applications based on microservices using the uber JAR model. To create a new application is quite simple, just use the Thorntail generator site and inform the Maven group, artifact and the necessary dependencies to your new application.

After clicking the generation process, a zip file will be provided with the structure (sources) of the generated project and ready to use at development of the application. You can open this project in any IDE with Maven support and perform the first build. To run the application, simply enter the following Maven command on the console.

mvn thorntail:run

At the end, a successful message will be displayed (Thorntail is Ready) and will be available for local access on port 8080. You can test this application using one of the following URLs:

http://localhost:8080/hellohttp://localhost:8080/health

To move your MicroProfile application to the cloud environment, you need to distribute your application into containers. In this way, you will need to add the Docker configuration using the following Dockerfile file.

FROM openjdk:8EXPOSE 9990EXPOSE 8080ADD target/*.jar /app.jarRUN sh -c ‘touch /app.jar’USER rootRUN touch /audit.log && chmod 777 /audit.logCMD java -Djava.net.preferIPv4Stack=true -jar /app.jar

You can test if your Docker image creation is working properly. To do that you will first need to perform the application’s Maven build generating a uber JAR, and then perform the respective docker build based on the Dockerfile file defined before.

mvn packagedocker build -t microprofile .

Oracle Container Native Platform

Oracle Cloud is a cloud computing platform providing servers, storage, networking, applications and services in a global network of data centers managed by Oracle. It provides Infrastructure solutions such as a service (IaaS), Platform as a service (PaaS), Software as a service (SaaS) and Data as a service (DaaS) that are used to build, distribute and integrate applications in the cloud. It supports many open standards (SQL, HTML5, REST, etc.), open-source platforms (Kubernetes, Hadoop, Kafka, etc.) and a variety of programming languages, database, tools, frameworks including proprietary Oracle or third party options.

One of the PaaS solutions offered by Oracle Cloud is the Oracle Container Native Platform which is a managed, integrated and easy-to-use solution for development, build, distribution and management of containers. It is basically composed of three structures: Oracle Container Engine for Kubernetes (OKE), Oracle Cloud Infrastructure Registry (OCIR) and Oracle Container Pipelines (Wercker) all those integrated and running into the Oracle Cloud infrastructure.

Source: Oracle Container Native Platform website
  • Oracle OKE: Kubernetes cluster managed by Oracle Cloud. It is certified by Kubernetes foundation with multi AZ support, and a user-friendly configuration and administration interface;
  • Oracle OCIR: Docker image repository compliant with Docker registry version 2. Provides tokens for authentication, with support for high scalability and availability;
  • Oracle Wercker: automated CI / CD environment for containers fully integrated with the Oracle Cloud platform.

This platform promotes the easy development and distribution of containers using the concept of pipelines and respecting the best practices and standards of CI/CD. The following image demonstrates how this integration cycle works at this platform.

Source: Oracle Cloud Infrastructure blog

Basically, all projects are configured in Oracle Wercker through integration pipelines, which manages the build, test, and publishing of Docker images at OCIR repository. At this repository it is possible to maintain a catalog of images versioned and labeled different by project. Once the image is published, it will be possible to distribute it into the container execution and orchestration environment (OKE) managed by Kubernetes. You can define different orchestration environments according with the desired execution profile you want such as development, staging and production, each one with its own namespace isolated and separated from the others.

Creating a new Kubernetes cluster at Oracle OKE

To create a new Kubernetes cluster is pretty straightforward, you can access the Oracle OKE dashboard and click to create a new cluster. It will open a new window with additional options, where you can simply set the cluster name, Kubernetes version supported, and choice the option for quick creation.

In addition, it is possible to enable add-ons such as Kubernetes Dashboard and Tiller (Helm) to be enabled during the creation process. After confirmation, the cluster should be available within few minutes.

The Kubernetes cluster will be ready as soon as the creation status demonstrates active, and the cluster instances become available.

To access and manage the Kubernetes cluster environment remotely, you will need to install and configure the kubectl (Kubernetes command line) and Oracle CLI (Oracle Cloud command line) utilities. After installing and configuring these tools, you can simply perform the following configuration.

mkdir -p $HOME/.kubeoci ce cluster create-kubeconfig — cluster-id [cluster id] — file $HOME/.kube/config

Once this is done, you can remotely manage your Kubernetes cluster, and also enabling a local access proxy for the Kubernetes Dashboard.

kubectl proxyhttp://localhost:8001/api/v1/namespaces/kube-system/services/https:kubernetes-dashboard:/proxy/

Defining the Docker images repository at Oracle OCIR

You will need to define a repository for each Docker images to be distributed into the Oracle OKE. To do that, you can access the Oracle OCIR dashboard and request the new repository creation. Just define the name of the repository and define if it will have public or private access.

Once the repository is defined, it is ready to receive the Docker project images for distribution in Oracle OKE.

Setting up pipelines for your MicroProfile app at Oracle Wercker

Before configuring the CI / CD integration pipeline, you need to upload your project to an existing Git repository. Oracle Wercker already has native integration with Github, Bitbucket, Gitlab or Oracle Developer Cloud Service, but you can also use any other Git repository with public access thru the Internet. To setup a new application, just follow the step-by-step guide from the Oracle Wercker home page.

After the application is created, you can define the pipelines configuration file via wercker.xml. This file will define the pipeline workflow to be executed during the CI / CD process.

To distribute your application into the OKE cluster, it is also necessary to define the Kubernetes deployment and service description file. This is a standard file and is used to setup a new application service within the Kubernetes cluster.

Finally, few environmental variables were defined to complete the pipelines execution. You must set up the values for these variables through the application environment configuration in the project defined at Oracle Wercker.

  • DOCKER_USERNAME: user with access to the OCIR repository;
  • DOCKER_REGISTRY: register address of the OCIR repository;
  • DOCKER_REPO: name of the project image repository defined in OCIR;
  • DOCKER_PASSWORD: authentication token for OCIR repository access;
  • KUBERNETES_MASTER: OKE cluster access address;
  • KUBERNETES_TOKEN: OKE cluster access token;

To generate the OCIR repository access authentication token, you must request a new token for an existing user defined in the Oracle Cloud identity database.

The Kubernetes cluster access token definition, you can check it from the kubeconfig configuration that you performed earlier. Just access the ~/.kube/config file located on your localhost and search for the user token reference.

To finish your configuration, you need to define the pipelines via the workflow editor in Oracle Wercker. For each pipeline defined in the wercker.yml file previously, you must add a new pipeline record.

Finally, you can define the workflow stream by representing the execution of the pipelines sequence at all.

Running pipelines to run your MicroProfile app at Oracle OKE

By default, pipelines execution will be triggered by any modification made in the Git repository defined (at the master branch). But you can also manually perform pipelines from the project’s execution tab in the Oracle Wercker environment.

After the successful completion of the pipelines, you will be able to see the results by checking the new Docker image(s) persisted in the OCIR repository…

… and also, the distribution and execution at the OKE cluster.

To access the running application, you can simply check the external endpoint defined by Kubernetes accessing the following standard URLs:

http://[external-endpoint]/hellohttp://[external-endpoint]/health

The source code for this example is available in Github and the pipeline settings are available at this project in Oracle Wercker.

--

--

Rodrigo Candido da Silva

Brazilian, Software Developer helping other developers to learn the new cutting edge development technologies. Oracle Dev Champion and GroundBreaker Ambassador.