Cloud Platform as a Service

 View Only

Integrating IBM Cloud Code Engine with GitHub and Event Notifications

By Enrique Encalada posted 7 days ago

  

Written by

Prashanth Bhat (prashabh@in.ibm.com)

Architect - IBM Cloud Event Notifications

Enrique Encalada (encalada@de.ibm.com)

Software Engineer - IBM Cloud Code Engine

Automating software deployment upon changes in your Git repository isn't  a novel idea. In IBM Cloud Code Engine, we provide samples like Github or Github Action Workflows, enabling users to respond to changes in their repositories through Code Engine workloads.

Given the importance of automated continuous deployments for cloud-native applications, this blog post delves deeper into the topic and proposes a new architecture for IBM Cloud users.

By integrating, Git, IBM Cloud Code Engine and IBM Cloud Event Notifications, we can offer users an end-to-end workflow from changes in Git to notifications across multiple destinations, including a Code Engine Job.

Architecture

Our starting point is Git. The source code of cloud-native applications is commonly hosted in these version control systems. Through Github webhooks, changes such as push events (e.g. committing to your main branch) can trigger integrations to take responsive actions.

Knowing when these events occur leads us to the questions; what actions can we take? and who can take an action?

In this architecture, IBM Cloud Event Notifications is our integration of choice, taking a responsive action upon Git Events.

In the image above, we use Event Notifications as an intermediary, leveraging their source and destination concepts to facilitate the transportation of our Github event payloads to multiple destinations.

Our final destination is a Code Engine Job, which, upon receiving the event, will trigger the creation of a Code Engine Build (rebuilds a container image from the Git code where the event originated) and will redeploy any Code Engine Application referencing that container image.

Tell me more!

By leveraging Code Engine with Event Notifications, we can take continuous deployments of cloud-native applications to the next level. Users can switch destinations or use multiple ones, such as Slack, Email, IBM Cloud Object Storage, IBM Cloud Functions, and more. The fan-out capability in Event Notifications enhances the overall workflow by ensuring that various parts of the system are updated and informed in near-real-time.

Additionally, you can use the Event filtering capability in Event Notifications to fine-tune which events trigger actions.

A Clever Workaround

If you paid attention to the first diagram, you will have noticed the need for an Application Adapter. This adapter is essential for translating the Github Webhook payload into a format that an Event Notification Source can understand, enabling the complete end-to-end flow.

However, there's no need to worry - this application adapter runs as a Code Engine Application, scaling to zero when no events are occurring.

Pre-requisites

If you reach this point, it's clear you have an interest in this architecture. Before diving in, there are some key prerequisites we need to have in place for deploying the architecture:

1. An Event Notifications Instance. See docs.

2. A valid IBM Cloud IAM API Key. See docs.

3. A Code Engine Project. See docs.

4. A Code Engine Build. This needs to be defined in advance, so that the architecture knows how to rebuild your container image. See docs.

Try It!

The architecture and code is located in our Samples Public Github repository. Ensure you download it, and move into the github-webhook directory. In this directory, you will find a ready-to-use architecture that provides an end-to-end workflow for rebuilding your container image upon code changes. To run the architecture, you need to set some environment variables in advance:

- EN_INSTANCE_ID: Your Event Notification Instance ID.

- IAM_API_KEY: A valid IAM API Key.

- CE_PROJECT_NAME: The name of the Code Engine Project.

- USER_BUILD_NAME: The name of the Code Engine Build.

Finally, you just need to execute the following command:

```sh

./run.sh

```

If you want to clean-up your Code Engine resources, you can run the following:

```sh

./run.sh clean

```

Questions and feedback

If you have feedback, suggestions, or questions on this post, you can always open GitHub issues on the related code samples for clarification. Alternatively, please reach out to us on LinkedIn (Prashanth Bhat or Enrique Encalada).

0 comments
3 views

Permalink