This repository demonstrate how to build test and deploy a Multicloud with GraalVM Development Kit for Micronaut (GDK) It is divided in two independent GDK projects
- ImageGeneratorGatewayFn
- GraalPictureStorage
- Both projects relies on Maven for build but it is quite simple to adapt it with Gradle.
- Install GDK client and GraalVM
$ sdk install java 21.0.3-oracle
$ sdk install gcn
- Check your java runtime environment
$ java -version
java version "21.0.3" 2024-04-16 LTS
Java(TM) SE Runtime Environment Oracle GraalVM 21.0.3+7.1 (build 21.0.3+7-LTS-jvmci-23.1-b37)
Java HotSpot(TM) 64-Bit Server VM Oracle GraalVM 21.0.3+7.1 (build 21.0.3+7-LTS-jvmci-23.1-b37, mixed mode, sharing)
- Setup your cloud accounts for OCI and AWS Coud Provider Setup and install the associated clients.
For this demo we consider a SPA Front end Application using back end projects ImageGeneratorGatewayFn
and GraalPictureStorage
to genearte(1) and store (only the selected image) in Object storage.
ImageGeneratorGatewayFn
is Serverless GDK Gateway Function based on LangChain4j to genrate PNG images from OpenAI DALL-E-2 API
- Build the Fn
$./mvnw install -pl lib -am
$ ./mvnw deploy -Dpackaging=docker -pl oci
For native image build use
$ ./mvnw package -pl oci -Dpackaging=native-image
- Deploy the Fn in Oracle Cloud Follow the GDK Guide for Serverless deployment
GraalPictureStorage
uses GDK Object Storage common API to store and retreive generated images in/from a public cloud ( OCI/AWS for the stake of this demo)
Use the GDK Launcher to generate a new Application
project.
gcn create-app com.oracle.demo.GraalPixgenStorageDemo --build=MAVEN --jdk=21 --lang=JAVA --test=JUNIT --example-code=true --clouds=OCI,AWS --services=LOGGING,OBJECTSTORE,TRACING --features=graalvm
- Adjust your configuration file
in
oci/src/main/resources/application.properties
micronaut.object-storage.oracle-cloud.default.namespace=MON_NAMESAPCE
micronaut.object-storage.oracle-cloud.default.bucket=MON_BUCKET
- Build the aplication
$./mvnw install -pl lib -am
3.Test the Application locally and target Oracle Cloud Infrastructure
$ ./mvnw mn:run -pl oci
The application starts on port 8080
__ __ _ _
| \/ (_) ___ _ __ ___ _ __ __ _ _ _| |_
| |\/| | |/ __| '__/ _ \| '_ \ / _` | | | | __|
| | | | | (__| | | (_) | | | | (_| | |_| | |_
|_| |_|_|\___|_| \___/|_| |_|\__,_|\__,_|\__|
13:53:31.688 [main] INFO io.micronaut.runtime.Micronaut - Startup completed in 1879ms. Server Running: http://localhost:8080
- Send an image in the Object Storage
$ curl -i -F "fileUpload=@/Users/nono/Projects/Workshops/DevLive2024/Workbook/images/nono1.png" <http://localhost:8080/pictures/nono1>
HTTP/1.1 100 Continue
HTTP/1.1 201 Created
location: <http://localhost:8080/pictures/nono1>
ETag: b913d3a5-4870-4481-8120-26d659ab0d44
date: Fri, 10 May 2024 14:07:06 GMT
content-length: 0
The image is uploaded.
- Use OCI Client/Console to verify
$ oci os object list --bucket-name $MON_BUCKET | jq .
{
"data": [
...
{
"archival-state": null,
"etag": "b913d3a5-4870-4481-8120-26d659axyzb0d44",
"md5": "bv+Xdfdfdfdf==",
"name": "nono1.jpg",
"size": 3147981,
"storage-tier": "Standard",
"time-created": "2024-05-14T12:23:31.133000+00:00",
"time-modified": "2024-05-14T12:23:31.133000+00:00"
}
],
"prefixes": []
}
replace $MON_BUCKET by your Bucket
- Adjust your configuration file
in
aws/src/main/resources/application.properties
micronaut.object-storage.aws.default.bucket=MON_S3_BUCKET
- Build the aplication
$./mvnw install -pl lib -am
3.Test the Application locally and target AWS
./mvnw mn:run -pl aws
The application starts on port 8080
__ __ _ _
| \/ (_) ___ _ __ ___ _ __ __ _ _ _| |_
| |\/| | |/ __| '__/ _ \| '_ \ / _` | | | | __|
| | | | | (__| | | (_) | | | | (_| | |_| | |_
|_| |_|_|\___|_| \___/|_| |_|\__,_|\__,_|\__|
13:53:31.688 [main] INFO io.micronaut.runtime.Micronaut - Startup completed in 1879ms. Server Running: http://localhost:8080
- Send an image in the Object Storage
$ curl -i -F "fileUpload=@/Users/nono/Projects/Workshops/DevLive2024/Workbook/images/nono1.png" <http://localhost:8080/pictures/nono1>
HTTP/1.1 100 Continue
HTTP/1.1 201 Created
location: <http://localhost:8080/pictures/nono1>
ETag: b913d3a5-4870-4481-8120-26d659ab0d44
date: Fri, 10 May 2024 14:07:06 GMT
content-length: 0
The image is uploaded.
- Use AWS Client/Console to verify the newly created png image
$ aws s3 ls $MON_S3_BUCKET
2024-04-23 17:41:11 529892 avatar.jpg
2024-05-14 14:27:44 3147981 nono.jpg
2024-05-10 16:40:39 3147981 nono1.jpg
replace $MON_S3_BUCKET by your S3 Bucket name
-
VSCode Extension to develop Cloud Apps here
-
GDK Cloud modules support Oracle Cloud’s Modern App Development framework here
-
Graal Development Kit Hands On Lab here
-
GDK guides here
-
GDK - OCI Serverless here
-
Self Hosted Labs Object Storage Labs with GDK here
-
Micronaut Oracle Cloud here
-
Miconaut - Setup Custom file Size for uploads here
-
OpenAI - Image Generation API
-
LangChain4J Interfacing LLM in Java