Quarkus Quickstart - Deployment of The Hello-World App by Gradle Tasks
Gradle supports a multitude of plugins that make it easy to deploy to multiple platforms. Take a look at how to do those deployments here.
Join the DZone community and get the full member experience.
Join For FreeTo facilitate deployment across platforms, you can use Gradle tasks and plugins. Gradle supports different plugins to deploy to Kubernetes, OpenShift, GCP, and deploy as AWS Lambda.
Let's focus on Quarkus framework, we are going to consider a simple "hello-world" application on Kotlin language with multiple platform deployment (OpenShift/Kubernetes/Amazon/Google Cloud Platform) by using Gradle tasks.
Quarkus is positioned as “Supersonic Subatomic Java” with Kubernetes Native Java stack tailored for OpenJDK HotSpot and GraalVM, crafted from the best of breed Java libraries and standards.
Source: quarkus project
Application
Create your first Kotlin application from code.quarkus.io with Gradle
build tools.
Setup necessary dependency and Kotlin plugin in build.gradle
:
plugins {
id 'org.jetbrains.kotlin.jvm' version "1.3.72"
}
dependencies {
implementation 'io.quarkus:quarkus-resteasy'
implementation 'io.quarkus:quarkus-smallrye-health'
implementation 'io.quarkus:quarkus-config-yaml'
implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk8"
}
Create a simple controller:
xxxxxxxxxx
@Path("/hello")
class GreetingResource {
@GET
@Produces(MediaType.TEXT_PLAIN)
fun hello(): String {
return "Hello from Quarkus!"
}
}
Docker Support
Setup container-image-docker
dependency on build.gradle
:
xxxxxxxxxx
dependencies {
implementation 'io.quarkus:quarkus-container-image-docker'
}
Set in resources/application.yaml
property for enabling image build in quarkusBuild
command:
xxxxxxxxxx
quarkus
container-image
name quarkus-quickstart
tag latest
registry docker.io
username <username>
password <password>
pushtrue
Run in command-line: ./gradlew quarkusBuild
or with credentials options:
./gradlew quarkusBuild -Dquarkus.container-image.username=<USERNAME> \
-Dquarkus.container-image.password=<PASSWORD> \
-Dquarkus.container-image.push=true
Google Cloud Platform (GCP)
Prerequisites: Google Cloud Platform account.
Create a Project
Create a project directly in your GCP or by using a command-line tool:
xxxxxxxxxx
gcloud projects create PROJECT_ID --set-as-default
gcloud app create --project=PROJECT_ID
Plugin Setup
For deploying to GCP used appengine-gradle-plugin
.
Setup plugin configuration in the project build.gradle
:
xxxxxxxxxx
buildscript {
repositories {
jcenter()
mavenLocal()
}
dependencies {
classpath 'com.google.cloud.tools:appengine-gradle-plugin:2.2.0'
}
}
apply plugin: "com.google.cloud.tools.appengine-appyaml"
appengine {
stage.artifact =
"${buildDir}/libs/${project.name}-${project.version}.jar"
deploy {
stopPreviousVersion = true
promote = true
projectId = GCLOUD_CONFIG
version = GCLOUD_CONFIG
}
}
Parameter GCLOUD_CONFIG
(it’s PROJECT_ID
from the previous step) you could set in build.gradle
directly or in gradle.properties
.
AppEngine Setup
In your project create file: src/main/appengine/app.yaml
:
xxxxxxxxxx
runtime java11
instance_class F4
entrypoint'java -agentpath:/opt/cdbg/cdbg_java_agent.so=--log_dir=/var/log
-jar <JAR_FILE_NAME>.jar'
Deploy Task
Execute Gradle command:
xxxxxxxxxx
./gradlew appengineDeploy
Browse your application:
xxxxxxxxxx
gcloud app browse
Kubernetes/OpenShift
Prerequisites: OC/Kubernetes Client
- already logged in.
For deploying to Kubernetes/OpenShift used my plugin k8s_aws_plugin
, which used templates or file configuration list (supported .json
and .yaml
formats) and image-streams for deployment.
Dependency
Setup Kubernetes dependency in build.gradle
:
xxxxxxxxxx
dependencies {
implementation 'io.quarkus:quarkus-kubernetes'
}
Set in resources/application.yaml
property for enabling build templates for OpenShift and Kubernetes:
xxxxxxxxxx
quarkus
kubernetes
deployment-target kubernetes, openshift
labels
app quarkus
Plugin Setup
Setup plugin configuration in the project build.gradle
:
xxxxxxxxxx
plugins {
...
id "com.elvaliev.k8s_aws_plugin" version "1.0.4"
}
apply plugin: "com.elvaliev.k8s_aws_plugin"
kubernetes {
image = 'elvaliev/quarkus-quickstart'
}
openshift {
image = 'elvaliev/quarkus-quickstart'
}
Note: Don’t need to specify templates - the plugin will recognize it from build/kubernetes
folder.
Note: Plugin support command options, it’s not necessary to specify extensions “openshift” and “kubernetes”
Deploy tasks
For deploying to Openshift by using extensions: ./gradlew openshiftDeploy
or by using command-line options:
xxxxxxxxxx
./gradlew openshiftDeploy --image=elvaliev/quarkus-quickstart
For deploying to Kubernetes by using extensions: ./gradlew kubernetesDeploy
or by using command-line options:
xxxxxxxxxx
./gradlew kubernetesDeploy --image=elvaliev/quarkus-quickstart
AWS Lambda
Prerequisites: SAM Client
- already logged in.
Dependency
Setup AWS dependency in the project build.gradle
:
xxxxxxxxxx
dependencies {
implementation 'io.quarkus:quarkus-amazon-lambda-http'
}
Plugin Setup
For deploying to Kubernetes/OpenShift used my plugin k8s_aws_plugin
. This plugin runs sam commands from quarkus tutorial to simulating and deploying Lambda.
Define AWS_BUCKET_NAME
and AWS_STACK_NAME
in gradle.properties
.
Setup plugin configuration in the project build.gradle
:
xxxxxxxxxx
plugins {
...
id "com.elvaliev.k8s_aws_plugin" version "1.0.4"
}
apply plugin: "com.elvaliev.k8s_aws_plugin"
aws {
template = "sam.jvm.yaml"
bucket = AWS_BUCKET_NAME
stack = AWS_STACK_NAME
}
Note: Plugin support command options, it’s not necessary to specify extension “aws”
Deploy Tasks
Simulate Amazon Lambda Deployment: ./gradlew awsLocal
or by using command-line options:
xxxxxxxxxx
./gradlew awsLocal --template="sam.jvm.yaml")
This will start a Docker container that mimics Amazon’s Lambda’s deployment environment. Once the environment started you can invoke the example Lambda in your browser by going to http://127.0.0.1:3000
and in the console, you’ll see startup messages from the Lambda.
Deploy to AWS: ./gradlew awsPackage
or by using command-line options:
xxxxxxxxxx
./gradlew awsPackage --template="sam.jvm.yaml" --bucket=AWS_BUCKET_NAME --stack=AWS_STACK_NAME
Github: https://github.com/ElinaValieva/micronaut-quarkus-quickstarts
Opinions expressed by DZone contributors are their own.
Trending
-
Security Challenges for Microservice Applications in Multi-Cloud Environments
-
Azure Virtual Machines
-
What Is JHipster?
-
Application Architecture Design Principles
Comments