Simple blog api with Quarkus - the Supersonic Subatomic Java Framework.
JDK 11at least - for running appGradle 6+- for building packageDocker- for containerizationOpenShift Client- for deploying app on OpenShiftAWS CLI,AWS SAM CLI- for deploying AWS Lambda
You can run your application in dev mode that enables live coding using:
./gradlew quarkusDev
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
Using GraalVM:
./gradlew build -Dquarkus.package.type=native
Without GraalVM:
./gradlew build -Dquarkus.package.type=native -Dquarkus.native.container-build=true
Run server:
docker run -p 8090:8090 elvaliev/blog-apiRun application with the UI:
docker-compose upApplication support open api - swagger and health check
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-apiOverride 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
Deployment using kubernetes template:
oc create -f build/kubernetes/openshift.yml
oc tag elvaliev/blog-api blog:1.0.0-SNAPSHOTNote: from version
1.5.1use for tagging image stream:latestversion instead of1.0.0-SNAPSHOT
Deployment using docker image:
oc new-app elvaliev/blog-api:latest
oc expose svc/blog-apiDeployment 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-
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
Timeoutinbuild/sam.jvm.yaml