Running Cloudify Github Actions Locally

Introduction

Cloudify offers a set of GitHub actions that can be used to interact with your managers. You can combine and use those actions based on your needs.

You can check them out in the GitHub marketplace.

This brings us to the main point where a developer would require a way to test GitHub workflows or debug them locally without needing to modify the workflow on the repository -extra commits for debugging- and then go through the logs using the Github actions tab.

One of the tools that can help in this case is “act” which is a tool offered by Nektos that provides a handy way to run GitHub Actions locally using Docker. 

You can check out the documentation for more information about it nektos/act.

Using act to test Cloudify GitHub Actions locally.

After following “act” documentation install and configure it to use your local docker.

We have this example workflow that we want to test before committing it to the GitHub repository 

The workflow does the following:

  • Check out the repository
  • Upload a blueprint -blueprint.yaml-
  • Create and Install a deployment from that blueprint
  • Get Deployment capabilities and set them as step output
  • Uninstall Deployment
  • Delete Blueprint

GitHub workflow content:

name: auto deploy environment
on:
  push:
jobs:
  install_environment:
    runs-on: ubuntu-latest
    steps:
      - name: Checkout code
        uses: actions/checkout@v2

      - name: Upload blueprint
        id: upload-blueprint
        uses: cloudify-cosmo/cli-action@v1.2
        with:
          command: blueprints upload blueprint.yaml -b env-${{ github.run_id }}

      - name: Install or update environment
        id: install-environemnt
        uses: cloudify-cosmo/install-or-update-action@v1.2
        with:
          environment-name: env-${{ github.run_id }}
          blueprint-id: env-${{ github.run_id }}
          delete-old-blueprint: false

      - name: format environemnt data
        id: get_env_capabilities
        shell: python
        run: |
          import json
          env_data = ${{steps.install-environemnt.outputs.environment-data}}
          env_data = json.dumps(env_data)
          env_data = env_data.replace('%','%25')
          env_data = env_data.replace('\n','%0A')
          env_data = env_data.replace('\r','%0D')
          print ('::set-output name=env_data::{0}'.format(env_data))

      - name: Uninstall environemnt
        uses: cloudify-cosmo/delete-environment-action@v1.2
        with:
         environment-name: ${{fromJson(steps.get_env_capabilities.outputs.env_data).deployment_id}}

      - name: Delete blueprint
        uses: cloudify-cosmo/cli-action@v1.2
        with:
         command: blueprints delete env-${{ github.run_id }}

env:
  CLOUDIFY_HOST: ${{ secrets.CLOUDIFY_HOST }}
  CLOUDIFY_USERNAME: ${{ secrets.CLOUDIFY_USERNAME }}
  CLOUDIFY_PASSWORD: ${{ secrets.CLOUDIFY_PASSWORD }}
  CLOUDIFY_TENANT: ${{ secrets.CLOUDIFY_TENANT }}
  CLOUDIFY_SSL: ${{ secrets.CLOUDIFY_SSL }}

Pay attention to the environment variables that we store in a secret file.

This is the content in our case since we will be using a local docker installation of Cloudify Manager

We will use this blueprint.yaml to test the workflow:

tosca_definitions_version: cloudify_dsl_1_3

description: ‘small blueprint for testing capabilities’

imports:
  – http://cloudify.co/spec/cloudify/6.3.0/types.yaml

outputs:
  output_1:
    value: Testing output

capabilities:
  capability_1:
    value: Testing capability

Steps that we will follow to check the workflow locally:

  • To list all workflows that you can execute `act -l`
➜  act-cloudify-demo git:(master) act -l
Stage  Job ID               Job name             Workflow name            Workflow file              Events
0      install_environment  install_environment  auto deploy environment  automate-environment.yaml  push
➜  act-cloudify-demo git:(master)
  • To execute a dry run `act -n` and that is if the event is push, and if the event is something else you need to specify it after `act`
  • To execute the workflow we will run the following command on our environment `act –secret-file ~/Documents/cloudify/my.secrets`
➜  act-cloudify-demo git:(master) act –secret-file ~/Documents/cloudify/my.secrets
…..
[auto deploy environment/install_environment]   🐳  docker exec cmd=[python /var/run/act/workflow/get_env_capabilities.py] user= workdir=
[auto deploy environment/install_environment]   ⚙  ::set-output:: env_data={“blueprint_id”: “env-1”, “deployment_id”: “e67067ab-90cc-4ce4-ab92-d26d86d21b96”, “outputs”: {“output_1”: “Testing output”}, “capabilities”: {“capability_1”: “Testing capability”}}
……
[auto deploy environment/install_environment] 🏁  Job succeeded

Conclusion

You can see how easy it was to set up and start using the ACT tool and make changes to GitHub workflows so you can test them quickly. This will shorten the workflow development time and you can experiment locally before pushing them to production.

comments

    Leave a Reply

    Your email address will not be published.

    Back to top