This guide describes how to create a Micronaut
application that runs natively on Oracle Cloud Infrastructure (OCI) and Amazon Web Services (AWS) without
any source code changes.
The application demonstrates how to store and retrieve user profile pictures in OCI and AWS Object Storage using
the Micronaut Object Storage API.
Create a new project using the following selections. (Alternatively, use these shortcuts for Maven
or Gradle.)
Project Type: Application (default)
Project name: GettingStarted
Base Package: com.example (default)
Clouds: AWSandOCI
Language: Java (default)
Build Tool: Gradle (Groovy) or Maven
Test Framework: JUnit (default)
Java Version: 17 (default)
Micronaut Version: (default)
Cloud Services: Object Storage
Features: GraalVM Native Image (default)
Sample Code: Yes
Click Generate Project. The GCN Launcher creates an application with
the default package com.example in a directory named GettingStarted. The application ZIP
file will be downloaded to your default downloads directory. Unzip it, open it in Visual Studio (VS) Code, and
proceed to the next steps.
The GCN Launcher creates the following sample source code files that use the Micronaut
Object Storage API to create, read, and delete objects in the major cloud providers:
an interface describing the endpoints of the "profile pictures" microservice:
For this section, you will need an OCI account and an Object Storage bucket created
already.
See how to create an Object Storage bucket from the OCI Console
or using the OCI CLI.
Update the OCI configuration file
(oci/src/main/resources/application-oraclecloud.yml) with details of the bucket name and namespace:
Running tests for your GCN application is easy with VSCode Test Explorer.
6. Build a Native Executable of Your Application with GraalVM
To build a native executable of your application, you should install GraalVM with Native Image. Once your local
environment is setup, run the following command to build a native executable:
The native executable is created in the aws/target/ directory
and can be run with the following command:
aws/target/aws
./gradlew :oci:nativeCompile
The native executable is created in the
oci/build/native/nativeCompile directory and can be run with
the following command:
oci/build/native/nativeCompile/oci
./gradlew :aws:nativeCompile
The native executable is created in the
aws/build/native/nativeCompile directory and can be run with
the following command:
aws/build/native/nativeCompile/aws
7. Use VS Code and Oracle Cloud DevOps Service
Thanks to the GCN extension, you can leverage the OCI DevOps Resources in VS Code to build a native
executable of your application on the cloud instead of locally.
8. Deploy the Application as a Container on the Cloud
Next you can create a container with Native Image version of the application and deploy it
on a Kubernetes cluster on OCI and AWS.
With your AWS account ready and access to EKS configured, simply invoke command:
Build ToolFilter
Gradle
Maven
All
./mvnw deploy -Dpackaging=docker -pl aws
./gradlew aws:dockerPush
This will push an AWS container image to a correct AWS container registry. When you setup
your Kubernetes deployment for AWS EKS, simply invoke the command:
kubectl apply -f deployment.yml
OCI
You can also install the GCN extension and use OCI DevOps Resources to leverage Oracle Cloud DevOps service and deploy your application
to a pre-created Kubernetes cluster from within VS Code.
Using the OCI DevOps Resources in VS Code, you can easily deploy a Java application to OCI, make
source code changes, push them into the OCI Git repository, and then trigger the build of a container image with
your native executable or a container image with JVM using the predefined OCI Build Pipelines.
Develop Java applications in VS Code with Graal Cloud Native support. It offers help in the
form of relevant code completion suggestions when editing GCN specific configuration files.
Java language support speeds up development of Java code with hints, etc.
When developing database applications, the GCN tooling provides advanced database related
code completion for `find… ()` methods:
It offers the SQL code completion in @Query annotations among others, and so on.
Next Steps
Explore
GCN provides easy step-by-step guides, and companion sample applications, for the developer to learn how to use a specific cloud service (such as Micronaut Data). Browse the GCN site for list of modules and guides to learn more.