top of page

Cloudhub 2.0 Deployment- mule maven plugin+GitHub Actions (Part 3)

Updated: Apr 28, 2023

Continue to our CloudHub 2.0 Deployment series, this will be blog explaining how you can use Github actions to setup CI/CD pipeline to build and deployment automatically.


I am sure you are familiar with Github and its functionalities very well.With this assumption I am going to put next thing for CI/CD setup using github action as below


1. Setup Build pipeline


Go to github.com website and reposirotry where you have pushed mule example code which we have created in previous blog.

Click on Actions -> click on new Workflow -> click on simple workflow

This will provide you sample workflow structure. You can update name from CI to Cloudhub2.0 pipeline



  # This is a basic workflow to help you get started with Actions 
  name: CI

Next it to determine -> On which action you wanted to this job to run automatically or you can run manually as well. So setup "On" element


# Controls when the workflow will run
on:
  # Triggers the workflow on push or pull request events but only for the "main" branch
  push:
    branches: [ "main" ]
  pull_request:
    branches: [ "main" ]
# Allows you to run this workflow manually from the Actions tab
  workflow_dispatch:

Now we are going to setup build step of a job.

We are going to run this on ubuntu-latest docker image where code checkout,maven ,java setup needs to be done before start running maven command for building mule application


# A workflow run is made up of one or more jobs that can run sequentially or in parallel
jobs:
  # This workflow contains a single job called "build"
  build:
    # The type of runner that the job will run on
    runs-on: ubuntu-latest

lets checkout code first on this docker image


Lets setup java OpenJDk 1.8 version on machine.

# setup JDK 1.8
      - name: Set up JDK 8
        uses: actions/setup-java@v1
        with:
          java-version: 1.8

Next step is configure maven settings config file in which we need to store clientId,clientsecret for connected app which we did on our local machine maven config settings.xml file

# setup maven credentials for server
      - name: Add Server Connected App credentials on maven settings
        uses: s4u/maven-settings-action@v2.8.0
        with:
          servers: |
            [{
              "id": "anypoint-exchange-v3",
              "username": "~~~Client~~~",
              "password": "${{ secrets.CONNECTEDAPPSECRET }}"
            }]

Here we are going to use secret and environment variable which i will explain in this blog how to setup. This is to make no one has access to this clientId/secret apart from devops or deployment team.


Next step to cache maven dependency which is optional but recommended to run build quick and fast


Now lets build and publish artefact to Anypoint exchange using below commands -

      #print maven settings to confirm changes
      - name: Print effective-settings (confirm step)
        run: mvn help:effective-settings
        
      #build artifact  
      - name: Build with Maven
        run: mvn clean -B package --file pom.xml
        
      #push maven artifact to anypoint exchange
      - name: Upload artefact to exchange
        run: mvn clean -B deploy --file pom.xml

At any point you need to verify any step or information you can use Print effective-settings to confirm changes which we applied are correct or not.


You can commit file. As soon as you commit build job will be initiated. You can check build job by clicking on actions tab again and see each n every step logs.


2. Setup Deploy Pipeline


As you know for cloudhub 2.0 deployment artefact needs to published on exchange that needs we do not need to store built artefact on local machine or on nexus repo.

So now in our Deploy steps we are going to setup similar steps which we did for build and publish artefact to exchange only change is to deploy artefact to cloudhub 2.0

#run maven deploy command to deploy artefact on runtime manager
      - name: Deploy to cloudHub2.0
        run: |
          mvn clean deploy -DmuleDeploy -Denv=dev -DencKey=${{ secrets.ENCKEY }}

So above command will pull latest published artefact on exchange and run it with arguments provided as it should pickup dev.yaml file and encKey as from secrets variable.


Once you commit this change on build.yaml file it will initiate job which will run two steps

a.build and once build is completed successfully b.deploy

On left hand you can see steps for this job and their status. Green means success.


3. Setup secrets and environment variable


This plays a vital role as we always have this requirement to send which environment which we going deploy application and which is secret key to decrypt encrypted values from properties file.

For this. Go To settings -> click on secrets and variable ->actions

You can setup secrets on repository level or environment level. Lets setup for repository secrets here as below

Secrets variable values once setup, you cannot see it, you can either update it with new value or you can delete it.


Once these values are setup. You build and deploy job can be invoked manually by clicking on Actions tab and click on Run Workflow.


In case if you face any challenge or issue, please comment below.


Happy Coding !!


Github Repository -



Reference :-


Comments

Rated 0 out of 5 stars.
No ratings yet

Add a rating
bottom of page