1

I want to create an action for a trigger in IBM Cloud Functions, but instead of only adding the code in the console, I want the action to deploy from code on a github repository. How can I do this?

Thanks in advance.

1 Answers1

1

I don't believe (or at least have not seen anywhere in the docs) you can just point the Cloud Functions to a GitHub repo. With that said you could do the following:

Make sure ibmcloud CLI is installed and you have the Cloud Functions plugin also installed ibmcloud plugin install cloud-functions

  1. ibmcloud login - You need a valid session in the CLI or use an IBM Cloud API key or a Service ID key that has the right IAM access to deploy to a Cloud Function namespace in IBM Cloud ibmcloud login --apikey "YOUR_API_KEY".
  2. ibmcloud target -r eu-gb - You need to target the right region where the Cloud Function will live.
  3. ibmcloud target -g test-resource-group - Once logged in, you need to make sure you target the right resource group where the Cloud Function will be pushed too.

If you are lazy like me then you can roll all 3 of the above commands into 1 like so: ibmcloud login --apikey "YOUR_API_KEY" -r "eu-gb" -g "test-resource-group"

  1. ibmcloud functions namespace target test-function-namespace - Finally, after logging in you need to use the cloud-functions plugin to target the right namespace where the Cloud Function will be pushed.

There are multiple ways to deploy the Cloud Function. For example, using the CLI to push the cloud function or using a manifest.yml file as a config.

Using IBM Cloud CLI

Creating a trigger assuming test-action is already created.

ibmcloud functions trigger create test-trigger --feed test-action

Using Manifest File

The example below is triggering the test-action Cloud Function every 15 minutes using a Cloud Function trigger.

manifest.yaml

project:
  namespace: _
  packages:
    test-package:
      actions:
        test-action:
          function: ./src/actions/action.js
          runtime: nodejs:12
      
      triggers:
        test-trigger:
          feed: /whisk.system/alarms/interval
          inputs:
            minutes: 15

      rules:
        rile-test-trigger:
          trigger: test-trigger
          action: test-action

To deploy this you essentially just:

ibmcloud functions deploy -m ./manifest.yaml

Both options can essentially be wired into a CD tool like Travis or Jenkins and can automatically deploy latest changes to the Cloud from GitHub.

harnamc
  • 541
  • 6
  • 20