Skip to content

ElinaValieva/quarkus-quickstarts

Repository files navigation

Quarkus QuickStart Project - Simple Blog

Java CI with Gradle Update Docker Hub Description Quarkus

Simple blog api with Quarkus - the Supersonic Subatomic Java Framework.

 

Prerequisites ❗

  1. JDK 11 at least - for running app
  2. Gradle 6+ - for building package
  3. Docker - for containerization
  4. OpenShift Client - for deploying app on OpenShift
  5. AWS CLI, AWS SAM CLI - for deploying AWS Lambda

 

Quarkus lifecycle 🔨

Running the application in dev mode

You can run your application in dev mode that enables live coding using:

./gradlew quarkusDev

Packaging and running the application

The application can be packaged using ./gradlew quarkusBuild. It produces the blog-1.0.0-SNAPSHOT-runner.jar file in the build directory.

./gradlew quarkusBuild

java -jar build/blog-1.0.0-SNAPSHOT-runner.jar

Creating a native executable

Using GraalVM:

./gradlew build -Dquarkus.package.type=native

Without GraalVM:

./gradlew build -Dquarkus.package.type=native -Dquarkus.native.container-build=true

Docker run

Run server:

docker run -p 8090:8090 elvaliev/blog-api

Run application with the UI:

docker-compose up

OpenApi and Health Check

Application support open api - swagger and health check

 

Docker build 🐳

Build and run image manually

Application supports multiple Dockerfiles with different extentions .jvm, .multistage and .native. Extention .jvm used in quarkus-container-image-docker in packaging with next push to docker registry.

Specify Dockerfile native or multistage build in command parameter with option -f and run image:

docker build -t blog-api -f src/main/docker/Dockerfile.multistage .

docker run -i --rm -p 8090:8090 blog-api

Push your image with Quarkus

Override parameters in application.properties:

Properties Description
quarkus.container-image.name Name of your image [application name]
quarkus.container-image.tag Version [latest]
quarkus.container-image.registry Docker registry [docker.io]
quarkus.container-image.username Credentials
quarkus.container-image.password Credentials
quarkus.container-image.push Flag for pushing image [false]

 

To push a container image for your project, quarkus.container-image.push=true needs to be set using any of the ways that Quarkus supports:

./gradlew  quarkusBuild -Dquarkus.container-image.username=<USERNAME> \
                        -Dquarkus.container-image.password=<PASSWORD> \
                        -Dquarkus.container-image.push=true

 

Openshift deployment 🚩

Deployment using kubernetes template:

oc create -f build/kubernetes/openshift.yml

oc tag elvaliev/blog-api blog:1.0.0-SNAPSHOT

Note: from version 1.5.1 use for tagging image stream: latest version instead of 1.0.0-SNAPSHOT

Deployment using docker image:

oc new-app elvaliev/blog-api:latest

oc expose svc/blog-api

Deployment using template:

oc tag elvaliev/blog-api:latest

oc process NAMESPACE_NAME=<OPENSHIFT-PROJECT> \
           SELECTOR_APP_NAME=<SELECTOR> \
           HOST_NAME=<APPLICATION_HOST> \
           -f OpenShiftTemplate.yaml | oc apply -f-

 

AWS deployment 🚩

Enable property awsLambdaEnabled = true when you package jar

./gradlew -PawsLambdaEnabled=true quarkusBuild

For native build use template build/sam.native.yaml.

sam local start-api --template build/sam.jvm.yaml

sam package --template-file build/sam.jvm.yaml --output-template-file packaged.yaml --s3-bucket <YOUR_S3_BUCKET>

sam deploy --template-file packaged.yaml --capabilities CAPABILITY_IAM --stack-name <YOUR_STACK_NAME>

To avoiding timeout error (502 - BAD GATEWAY) - increase Timeout in build/sam.jvm.yaml