{{announcement.body}}
{{announcement.title}}

Quarkus Quickstart - Deployment of The Hello-World App by Gradle Tasks

DZone 's Guide to

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.

· Microservices Zone ·
Free Resource

To 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:

Groovy
 




x
10


 
1
plugins {
2
    id 'org.jetbrains.kotlin.jvm' version "1.3.72"
3
}
4
 
          
5
dependencies {
6
    implementation 'io.quarkus:quarkus-resteasy'
7
    implementation 'io.quarkus:quarkus-smallrye-health'
8
    implementation 'io.quarkus:quarkus-config-yaml'
9
    implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk8"
10
}



Create a simple controller:

Kotlin
 




xxxxxxxxxx
1


1
@Path("/hello")
2
class GreetingResource {
3
 
          
4
    @GET
5
    @Produces(MediaType.TEXT_PLAIN)
6
    fun hello(): String {
7
        return "Hello from Quarkus!"
8
    }
9
}


 

Docker Support 

Setup container-image-docker dependency on build.gradle:

Groovy
 




xxxxxxxxxx
1


 
1
dependencies {
2
    implementation 'io.quarkus:quarkus-container-image-docker'
3
}


Set in resources/application.yaml property for enabling image build in quarkusBuild command:

YAML
 




xxxxxxxxxx
1


 
1
quarkus:
2
  container-image:
3
    name: quarkus-quickstart
4
    tag: latest
5
    registry: docker.io
6
    username: <username>
7
    password: <password>
8
    push: true


Run in command-line: ./gradlew quarkusBuild or with credentials options:

Shell
 




x


 
1
./gradlew quarkusBuild  -Dquarkus.container-image.username=<USERNAME> \                        
2
                        -Dquarkus.container-image.password=<PASSWORD> \                       
3
                        -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:

Shell
 




xxxxxxxxxx
1


 
1
gcloud projects create PROJECT_ID --set-as-default 
2
gcloud app create --project=PROJECT_ID


Plugin Setup

For deploying to GCP used appengine-gradle-plugin.

Setup plugin configuration in the project build.gradle:

Groovy
 




xxxxxxxxxx
1
25


 
1
buildscript {
2
    repositories {
3
        jcenter()
4
        mavenLocal()
5
    }
6
 
          
7
    dependencies {
8
        classpath 'com.google.cloud.tools:appengine-gradle-plugin:2.2.0'
9
    }
10
}
11
 
          
12
apply plugin: "com.google.cloud.tools.appengine-appyaml"
13
 
          
14
appengine {
15
    stage.artifact =
16
            "${buildDir}/libs/${project.name}-${project.version}.jar"
17
 
          
18
    deploy {
19
        stopPreviousVersion = true
20
        promote = true
21
        projectId = GCLOUD_CONFIG
22
        version = GCLOUD_CONFIG
23
    }
24
}


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:

YAML
 




xxxxxxxxxx
1


1
runtime: java11
2
instance_class: F4
3
entrypoint: 'java -agentpath:/opt/cdbg/cdbg_java_agent.so=--log_dir=/var/log
4
                  -jar <JAR_FILE_NAME>.jar'


Deploy Task

Execute Gradle command:

Shell
 




xxxxxxxxxx
1


 
1
./gradlew appengineDeploy
2
 
          


Browse your application:

Shell
 




xxxxxxxxxx
1


 
1
gcloud app browse
2
 
          


 

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:

Groovy
 




xxxxxxxxxx
1


 
1
dependencies {
2
    implementation 'io.quarkus:quarkus-kubernetes'
3
}


Set in resources/application.yaml property for enabling build templates for OpenShift and Kubernetes:

YAML
 




xxxxxxxxxx
1


1
quarkus:
2
  kubernetes:
3
    deployment-target: kubernetes, openshift
4
    labels:
5
      app: quarkus


Plugin Setup

Setup plugin configuration in the project build.gradle:

Groovy
 




xxxxxxxxxx
1
14


 
1
plugins {
2
                    ...
3
    id "com.elvaliev.k8s_aws_plugin" version "1.0.4"
4
}
5
 
          
6
 apply plugin: "com.elvaliev.k8s_aws_plugin"
7
 
          
8
 kubernetes {
9
    image = 'elvaliev/quarkus-quickstart'
10
 }
11
 
          
12
 openshift {
13
    image = 'elvaliev/quarkus-quickstart'
14
 }


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:

Shell
 




xxxxxxxxxx
1


 
1
./gradlew openshiftDeploy --image=elvaliev/quarkus-quickstart
2
 
          


For deploying to Kubernetes by using extensions: ./gradlew kubernetesDeploy or by using command-line options:

Shell
 




xxxxxxxxxx
1


 
1
./gradlew kubernetesDeploy --image=elvaliev/quarkus-quickstart
2
 
          


 

AWS Lambda

Prerequisites: SAM Client - already logged in.

Dependency

Setup AWS dependency in the project build.gradle:

Groovy
 




xxxxxxxxxx
1


1
dependencies {
2
    implementation 'io.quarkus:quarkus-amazon-lambda-http'
3
}


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:

Groovy
 




xxxxxxxxxx
1
12


 
1
plugins {
2
                    ...
3
    id "com.elvaliev.k8s_aws_plugin" version "1.0.4"
4
}
5
 
          
6
apply plugin: "com.elvaliev.k8s_aws_plugin"
7
 
          
8
aws {
9
        template = "sam.jvm.yaml"
10
        bucket = AWS_BUCKET_NAME
11
        stack = AWS_STACK_NAME
12
}


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:

Shell
 




xxxxxxxxxx
1


 
1
./gradlew awsLocal --template="sam.jvm.yaml")
2
 
          


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:

Shell
 




xxxxxxxxxx
1


 
1
./gradlew awsPackage --template="sam.jvm.yaml" --bucket=AWS_BUCKET_NAME --stack=AWS_STACK_NAME
2
 
          



Github: https://github.com/ElinaValieva/micronaut-quarkus-quickstarts 

Topics:
aws lambda, google cloud platform, gradle, gradle plugins, kubernates, openshift, quarkus, quarkus tutorial

Opinions expressed by DZone contributors are their own.

{{ parent.title || parent.header.title}}

{{ parent.tldr }}

{{ parent.urlSource.name }}