Deploying to Payara Cloud from a GitHub Action Workflow

Cloud & Microservices

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 account here.

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 with PCL – 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 repository Payara Artifacts either as executable jar file or zip 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 Payara Cloud’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:
  deploy:
    runs-on: ubuntu-latest
    env:
      ACTIONS_STEP_DEBUG: true
    steps:
      - name: Checkout code
        uses: actions/checkout@v2
      - name: Set up JDK
        uses: actions/setup-java@v4
        with:
          distribution: zulu
          java-version: 17
      - name: Build with Maven
        run: mvn clean package
      - name: Deploy to Payara Cloud
        uses: payara/cloud-deploy@master
        with:
        token:

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 or register to be the first in the know:

  {{ secrets.PCL_AUTH_TOKEN }}’
          subscription_name: ‘you-subscription-name’
          namespace: ‘your-namespace-name’
          app_name: ‘your-app-name’
          artifact_location: ‘your-war-file-location’
        deploy: true

 

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 or register to be the first in the know:

 

Comments (0)

Post a comment

Your email address will not be published. Required fields are marked *

Payara needs the contact information you provide to us to contact you about our products and services. You may unsubscribe from these communications at any time. For information on how to unsubscribe, as well as our privacy practices and commitment to protecting your privacy, please review our Legal & Privacy Policy.

Related Posts

payara qube logo 5 minutes
Payara

Payara Cloud Is Now part of Payara Qube family of Unified Platforms for Enterprise Java

Payara Cloud is becoming part of Payara Qube family of Java application deployment runtimes. This move reflects how the […]

Payara promotional graphic showing transition from Spring to Jakarta EE, including technology logos, a code icon and arrows leading from Spring to Jakarta EE. 6 minutes
Jakarta EE

From Spring Boot To Jakarta EE 11: How Payara Starter Eases The Transition

If you’ve been living in the Spring ecosystem, you’re used to fast project setup. Spring Initializr gives you a […]

Promotional graphic for a podcast episode titled “Why Open Source is the Future of Business Innovation - A conversation with Arun Gupta”. The podcast is hosted by Payara Community. The right side features a photo of the speaker, Arun Gupta, labeled as a “VP, Developer Experience at JetBrains”. The design uses dark blue and teal backgrounds with coral and fish illustrations. 2 minutes
Community

Payara Podcast – Why Open Source is the Future of Business Innovation – A Conversation with Arun Gupta

Open source is no longer a developer-only concern — it’s at the heart of how modern businesses innovate, build […]