Deploying to Payara Cloud from a GitHub Action Workflow

Photo of Patrik Duditš by Patrik Duditš

Payara Cloud provides an easy-to-use user interface to allow your application to run in a managed cloud environment. While this is very convenient for configuration and troubleshooting work, integration in continuous deployment pipelines calls for something else. Our answer is deploying to Payara Cloud using a GitHub Action Workflow and Payara Cloud Command Line (PCL). 

What is Payara Cloud?

Payara Cloud is a Payara-as-a-Service, where Kubernetes tasks related to cloud deployments of Jakarta EE applications are managed for you. You simply select your WAR file, click deploy, and have your app automatically deployed to the cloud.

Payara Cloud takes your uploaded WAR file, packages it into a Docker image with Payara Micro – our microservices runtime – generates all the YAML configurations, builds container images, creates a pod, deploys it on Kubernetes, updates the API server to manage ingress on Microsoft Azure and even creates an SSL certificate for the application. All of these are done transparently so you don't have to even think about them. Check it out for yourself with a free accounthere.

Integrating Payara Cloud Into Your CI/CD

You can find monitoring and configuration options in the user interface of Payara Cloud. However, you may not want to configure via this user interface each time if you are dealing with automated workflows.

This is why, in addition to the user interface, we have made it possible to control the deployment and configuration of applications running in Payara Cloud withPCL – Payara Cloud Command Line. In this article, we look at how to use it and the most common commands to use in the deployment pipeline script.

Downloading PCL

The tool is distributed via Maven repositoryPayara Artifactseither asexecutable jarfile orzip file with binary and documentation. In a shell script, PCL can be downloaded by using an approach similar to this:

PCL_VERSION=1.1.0
curl https://nexus.payara.fish/repository/payara-artifacts/fish/payara/cloud/pcl/$PCL_VERSION/pcl-$PCL_VERSION.zip -o pcl.zip && unzip pcl.zip && rm pcl.zip

PCL=$PWD/pcl-$PCL_VERSION/bin/pcl

This downloads the full package, extracts it, and sets variable $PCL to point to PCL binary.

Running PCL

Payara Cloud Command Line is an executable JAR file and requires at least the Java 8 development kit to be present in the environment it should run in. The binary we pointed to in a previous step is just a shell wrapper for executing Java.

Logging In

As a user, you authenticate using a browser. The deployment script obviously cannot do that. Instead, you log in once via the command PCL login and get a token which the script will use as its identity. The entire process is described in detail in PayaraCloud's documentation, the command line interaction will look like this:

# Uncomment when you're using Cloud Trial instance:
#PCL_ENDPOINT=https://manage.trial.payara.cloud
$PCL login --print-token
[INFO] In order to log in follow following link: https://login.payara.cloud/activate
[INFO] Your confirmation code is CVJF-XKGH
[SUCCESS] Token for environment-based login:
PCL_AUTH_TOKEN=eyJyZWZyZXNoX3Rva2VuIjoiWktMTFVQaUVIeEZ3c2JfOGNXSzFILUdnaUR1OVlXZUdDR3h3TUVFUlVrM3VLIn0=

The output of the script represents the environment variable you would need to provide to your deployment pipeline so that script can assume your identity.

Deploying an Application

Since this is continuous deployment set up, let's assume the namespace for our application already exists, that the application was already deployed once and its current configuration is also valid for the new version being deployed.

In this example let's assume we're deploying to namespace cli-demo, and our application binary is created in target/petclinic.war:

$PCL upload -n cli-demo target/petclinic.war --deploy
[UPDATE] State of inspection process is DEPLOYING
[UPDATE] State of deployment process is DEPLOYING
[UPDATE] State of deployment process is DEPLOYED
[SUCCESS] Deployment completed

{
    "name": "petclinic-jakartaee",
    "applicationEndpoint": "https://cli-demo-0547af24.payara.app/petclinic-jakartaee/",
    "status": "RUNNING",
    "pendingChanges": false,
    "liveRuntimeSize": "QUARTER_CORE",
    "horizontalScaling": false
}

Deploying to Payara Cloud via GitHub Actions Workflow

Let's put all the steps together into a GitHub actions workflow.

As a first step, obtain the CLI token as described above, and set that into your repository's secrets:

Screenshot 2024-04-11 162826-1

Then, create the workflow under directory .github/workflows/ such as this one:

name: Deploy to Payara Cloud

on:
push:
branches: [ main ]

jobs:
build:

runs-on: ubuntu-latest

env:
# non-standard Payara Cloud Endpoint, not really thing to document at this point
# token obtained from `pcl login --print-token`
PCL_AUTH_TOKEN: $
PCL_VERSION: 1.1.0
PCL: pcl-1.1.0/bin/pcl

steps:
- uses: actions/checkout@v2
- name: Set up JDK 11
uses: actions/setup-java@v1
with:
java-version: 11
- name: Cache repository
uses: actions/cache@v2
with:
path: |
~/.m2/repository
# we only use direct match of pom.xml. So a version change will surely drop the cache
key: $-maven-$

- name: Build with Maven
run: mvn -B verify

# upload-artifact / download-artifact actions can be used to sepearate these into separate jobs
- name: Download PCL
# This should download PCL from official download location rather than our internal Maven repo
# unzip cannot do pipes. jar can, but it ignores file permissions
run: |
curl https://nexus.payara.fish/repository/payara-artifacts/fish/payara/cloud/pcl/$PCL_VERSION/pcl-$PCL_VERSION.zip -o pcl.zip
unzip pcl.zip
rm pcl.zip

- name: Deploy application
run: |
$PCL upload -n cli-demo target/petclinic.war --deploy

And there we have it! Now on every push to branch main the application will be rebuilt and deployed into your Payara Cloud namespace. You can find the demo code in GitHub Repo.

Like What You See? - Payara Cloud 

Payara Cloud - offering a serverless option for running your Jakarta EE apps on the cloud! 

Download the Datasheet to find out more orregisterto be the first in the know:

Payara Cloud Datasheet

 

Related Posts

Comments