Deploy Quarkus Application with GitLab-CI to Heroku PaaS

Build a full pipeline and deploy a Quarkus application to different environments with GitLab-CI

Photo by Sigmund on Unsplash

Introduction

Prerequisites

Quarkus Application

Quarkus dependencies

Starting the application

Default Endpoint created by Quarkus
Quarkus Test

Rest Endpoint Modification (Optional)

Adding the model

Data would create all setters/getters and toString

Setting the interface

https://jsonplaceholder.typicode.com/users

Configure the Client URL

Update the controller and the test

GitLab Project Creation

GitLab repository

Heroku Application Creation

GitLab Repository Configuration

Protect the merge request

Protect branches and tags

GitLab-CI Pipeline Initialization

.gitlab-ci.yml
Simple Pipeline

Pipeline Syntax

stages:
- build
- test
- deploy
build-job:
stage: build
script:
- echo "Project compilation"

test-job:
stage: test
script:
- echo "Project test execution"

package-job:
stage: deploy
script:
- echo "Project packaging"

deploy-job:
stage: deploy
script:
- echo "Project deployment"

Validate GitLab CI Configuration

Building Quarkus Application

Define the stages

stages:
- build
- test
- deploy

build-job:
stage: build
script:
- ./mvnw compile -B
# keep compilation for test stage
artifacts:
paths:
- target

test-job:
stage: test
script:
- ./mvnw test -B

deploy-job:
stage: deploy
script:
- echo "deploying to heroku..."

Deploying Quarkus Application

Staging Deployment

deploy-staging:
stage: deploy
before_script:
- apt-get update -qy
- apt-get install -y ruby-dev
- gem install dpl
script:
- dpl --provider=heroku --app=$HEROKU_APP_STAGING --api-key=$HEROKU_API_KEY --skip-cleanup=true
only:
- staging
Merge Request could be accepted as Pipeline has succeeded

Pre-production and Production Deployment

deploy-staging:
extends: .deploy
variables:
HEROKU_APP: $HEROKU_APP_STAGING
only:
- staging

deploy-preprod:
extends: .deploy
variables:
HEROKU_APP: $HEROKU_APP_PREPROD
only:
- master

deploy-production:
extends: .deploy
variables:
HEROKU_APP: $HEROKU_APP_PRODUCTION
only:
- tags

Caching dependencies

cache key using Project Id

Clearing the cache

Clear Runner Caches

Security Checks

SAST and Secret detection
Don’t compile, check only

Wrapping Up

Lead Web Application Architect. Passionate about refactoring, clean code, and building scalable solutions with simplicity.

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store