Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
72 changes: 58 additions & 14 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,19 +4,25 @@ This GitHub Action allows you to interact with IBM Cloud Code Engine. Deploy App

## Inputs

| Name | Required | Default Value | Description |
|------------------|----------|-----------------------------|------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
| `api-key` | ✅ | - | IAM API Key used to log into the IBM Cloud. Please store your IBM Cloud API key securely in your GitHub repository Secrets. |
| `resource-group` | ❌ | Your Default Resource Group | An IBM Cloud Resource Group, a logical container for organizing and managing related cloud resources. |
| `region` | ✅ | - | The geographical area where your Code Engine project is located, like `eu-de` [codeengine-regions](https://cloud.ibm.com/docs/codeengine?topic=codeengine-regions) |
| `project` | ✅ | - | The unique identifier (GUID) or the name that identifies your IBM Cloud Code Engine project. |
| `component` | ✅ | - | The type of component to deploy. allowed values `application`, `app`, `function`, `func`, `fn`, `job` |
| `name` | ✅ | - | The name of the App, Function, or Job. |
| `build-source` | ❌ | . | Path to the directory containing the source code. See the Docs for additional information on how Code Engine builds [Apps, Jobs](https://cloud.ibm.com/docs/codeengine?topic=codeengine-build-config-local) and [Functions](https://cloud.ibm.com/docs/codeengine?topic=codeengine-fun-create-local) |
| `build-size` | ❌ | medium | The size of the build defines how CPU cores, memory, and disk space are assigned to the build. See the Docs for additional information for [Apps, and Jobs](https://cloud.ibm.com/docs/codeengine?topic=codeengine-plan-build#build-size) |
| `cpu` | ❌ | 1 / 0.5 | CPU value set for your component Default for Apps and Jobs 1 vCPU, 0.5 vCPU for Functions. [Config for Functions](https://cloud.ibm.com/docs/codeengine?topic=codeengine-fun-runtime), [Codeengine Memory CPU combo](https://cloud.ibm.com/docs/codeengine?topic=codeengine-mem-cpu-combo) |
| `memory` | ❌ | 4G / 2G | Memory value set for your component Default for Apps and Jobs 4 GB, 2GB for Functions. [Config for Functions](https://cloud.ibm.com/docs/codeengine?topic=codeengine-fun-runtime), [Codeengine Memory CPU combo](https://cloud.ibm.com/docs/codeengine?topic=codeengine-mem-cpu-combo) |
| `runtime` | ❌ | - | The runtime used for the Function. Currently supported `nodejs-18` and `python-3.11` see [IBM Code Engine Function Runtimes](https://cloud.ibm.com/docs/codeengine?topic=codeengine-fun-runtime) for more information. |
| Name | Required | Default Value | Description |
|------------------|---------|-----------------------------|-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
| `api-key` | ✅ | - | IAM API Key used to log into the IBM Cloud. Please store your IBM Cloud API key securely in your GitHub repository Secrets. |
| `resource-group` | ❌ | Your Default Resource Group | An IBM Cloud Resource Group, a logical container for organizing and managing related cloud resources. |
| `region` | ✅ | - | The geographical area where your Code Engine project is located, like `eu-de` [codeengine-regions](https://cloud.ibm.com/docs/codeengine?topic=codeengine-regions) |
| `project` | ✅ | - | The unique identifier (GUID) or the name that identifies your IBM Cloud Code Engine project. |
| `component` | ✅ | - | The type of component to deploy. allowed values `application`, `app`, `function`, `func`, `fn`, `job`, `subscription`, `sub` |
| `subscription-type` | ❌ | - | The type of subscription. allowed values `cos`, `cron`, `kafka`. WARNING Currently only `cron` is supported |
| `name` | ✅ | - | The name of the App, Function, or Job. |
| `build-source` | ❌ | . | Path to the directory containing the source code. See the Docs for additional information on how Code Engine builds [Apps, Jobs](https://cloud.ibm.com/docs/codeengine?topic=codeengine-build-config-local) and [Functions](https://cloud.ibm.com/docs/codeengine?topic=codeengine-fun-create-local) |
| `build-size` | ❌ | medium | The size of the build defines how CPU cores, memory, and disk space are assigned to the build. See the Docs for additional information for [Apps, and Jobs](https://cloud.ibm.com/docs/codeengine?topic=codeengine-plan-build#build-size) |
| `cpu` | ❌ | 1 / 0.5 | CPU value set for your component Default for Apps and Jobs 1 vCPU, 0.5 vCPU for Functions. [Config for Functions](https://cloud.ibm.com/docs/codeengine?topic=codeengine-fun-runtime), [Codeengine Memory CPU combo](https://cloud.ibm.com/docs/codeengine?topic=codeengine-mem-cpu-combo) |
| `memory` | ❌ | 4G / 2G | Memory value set for your component Default for Apps and Jobs 4 GB, 2GB for Functions. [Config for Functions](https://cloud.ibm.com/docs/codeengine?topic=codeengine-fun-runtime), [Codeengine Memory CPU combo](https://cloud.ibm.com/docs/codeengine?topic=codeengine-mem-cpu-combo) |
| `runtime` | ❌ | - | The runtime used for the Function. Currently supported `nodejs-18` and `python-3.11` see [IBM Code Engine Function Runtimes](https://cloud.ibm.com/docs/codeengine?topic=codeengine-fun-runtime) for more information. |
| `destination-type` | ❌ | app | The type of the destination. Valid values are `app`, `function` and `job`. This value is optional. |
| `destination` | ❌ | - | The name of the application or job resource that you want to receive events; for example, `myapp`. If needed, use the --path option to further qualify an app destination. This value is required. |
| `path` | ❌ | - | The path within the destination application where events are forwarded; for example, `/events`. |
| `extension` | ❌ | - | Extension used for the Subscription. Set CloudEvents extensions to send to the destination. Must be in `NAME=VALUE` format. This action adds a new CloudEvents extension or overrides an existing CloudEvent attribute. Specify one extension per --extension option; for example, `--ext extA=A --ext extB=B`. |
| `schedule` | ❌ | - | Schedule how often the event is triggered, in crontab format. For example, specify `'*/2 * * * *'` (in string format) for every two minutes. By default, the cron event is triggered every minute and is set to the `UTC` time zone. |

## Usage and Example

Expand Down Expand Up @@ -58,7 +64,7 @@ jobs:
*Deploy a Job: `deploy-job.yml`*: Deploy your Job to `Default` resource-group in `eu-de` to the project `MY-PROJECT` with its source code in the root of the repository the name of the job is`my-job`.

```yaml
name: Deploy App to Code Engine
name: Deploy Job to Code Engine

on:
push:
Expand Down Expand Up @@ -155,3 +161,41 @@ jobs:
cpu: 1
memory: 4G
```
*Deploy a Cron Subscription: `deploy-cron-sub.yml`*: Deploy your Cron Subscription to `Default` resource-group in `eu-de` to the project `MY-PROJECT` with its source code in the root of the repository the name of the job is`my-cron-sub`.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
*Deploy a Cron Subscription: `deploy-cron-sub.yml`*: Deploy your Cron Subscription to `Default` resource-group in `eu-de` to the project `MY-PROJECT` with its source code in the root of the repository the name of the job is`my-cron-sub`.
*Deploy a Cron Subscription: `deploy-cron-sub.yml`*: Deploy your Cron Subscription to `Default` resource-group in `eu-de` to the project `MY-PROJECT` with its source code in the root of the repository the name of the job is`cron-app`. See the docs for more infromation https://cloud.ibm.com/docs/codeengine?topic=codeengine-subscribe-cron-tutorial.


```yaml
name: Deploy Cron Subscription to Code Engine

on:
push:
branches:
- main
workflow_dispatch:

jobs:

deploy-job:
runs-on: ubuntu-latest
steps:
- name: Check out code
uses: actions/checkout@v3

- name: Deploy Cron Subscription to Code Engine
uses: IBM/code-engine-github-action@v1
with:
api-key: ${{ secrets.IBM_IAM_API_KEY }}
resource-group: 'Default'
region: 'eu-de'
project: 'MY-PROJECT'
component: 'sub'
subscription-type: 'cron'
destination-type: 'app'
destination: 'my-app'
path: '/events'
extension: 'extA=A'
schedule: '*/2 * * * *'
name: 'my-cron-sub'
build-source: './'
cpu: 1
memory: 4G
Comment on lines +186 to +200
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please update docs as this is the way it was tested

Suggested change
api-key: ${{ secrets.IBM_IAM_API_KEY }}
resource-group: 'Default'
region: 'eu-de'
project: 'MY-PROJECT'
component: 'sub'
subscription-type: 'cron'
destination-type: 'app'
destination: 'my-app'
path: '/events'
extension: 'extA=A'
schedule: '*/2 * * * *'
name: 'my-cron-sub'
build-source: './'
cpu: 1
memory: 4G
api-key: ${{ secrets.IBM_IAM_API_KEY }}
resource-group: 'Default'
region: 'eu-de'
project: 'MY-PROJECT'
component: 'sub'
subscription-type: 'cron'
destination-type: 'app'
destination: 'cron-app'
path: '/events'
extension: 'extA=A'
schedule: '*/2 * * * *'
name: 'cron-sub'

```
41 changes: 39 additions & 2 deletions action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -23,11 +23,15 @@ inputs:
description: A Code Engine Project Is the grouping of your Apps, Functions and Jobs
required: true

# App, Function or Job Specific inputs
# App, Function, Job or Subscription Specific inputs
component:
description: The type of component that should be deployed [App, Function, Job]
description: The type of component that should be deployed [App, Function, Job, Subscription]
required: true

subscription-type:
description: The type of subscription that should be deployed [cos, cron, kafka]. WARNING Currently only [cron] is supported
required: false

name:
description: Name of the App, Function or Job
required: true
Expand All @@ -36,6 +40,27 @@ inputs:
description: Runtime used for the Function only required for function
required: false

destination-type:
description: Destination type used for the Subscription only required for subscription [app, function, job]. The default value is app.
required: false
default: app

destination:
description: Destination used for the Subscription only required for subscription
required: false

path:
description: Path used for the Subscription. For example, /events
required: false

extension:
description: Extension used for the Subscription. Set CloudEvents extensions to send to the destination. Must be in 'NAME=VALUE' format. This action adds a new CloudEvents extension or overrides an existing CloudEvent attribute. Specify one extension per --extension option; for example, --ext extA=A --ext extB=B.
required: false

schedule:
description: Schedule used for the Subscription. For example, specify '*/2 * * * *' (in string format) for every two minutes
required: false

build-source:
description: path to the directory containing the source code
required: false
Expand Down Expand Up @@ -149,6 +174,18 @@ runs:
ibmcloud ce job create --name ${{ inputs.name }} --build-source ${{ inputs.build-source }} --build-size ${{ inputs.build-size }} --wait ${{ steps.set-resources.outputs.cpu }} ${{ steps.set-resources.outputs.memory }}
fi

# Subscription Steps
- name: Create or Update Subscription cron
shell: bash
id: create-sub-cron
if: ( inputs.component == 'subscription' || inputs.component == 'sub' ) && inputs.subscription-type == 'cron'
run: |
if ibmcloud ce sub cron get --name ${{ inputs.name }} ; then
ibmcloud ce sub cron update --name ${{ inputs.name }} --destination-type ${{ inputs.destination-type }} --destination ${{ inputs.destination }} --path ${{ inputs.path }} --extension ${{ inputs.extension }} --schedule ${{ inputs.schedule }} --wait ${{ steps.set-resources.outputs.cpu }} ${{ steps.set-resources.outputs.memory }}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please replace with following code in order to update existing subscription

Suggested change
ibmcloud ce sub cron update --name ${{ inputs.name }} --destination-type ${{ inputs.destination-type }} --destination ${{ inputs.destination }} --path ${{ inputs.path }} --extension ${{ inputs.extension }} --schedule ${{ inputs.schedule }} --wait ${{ steps.set-resources.outputs.cpu }} ${{ steps.set-resources.outputs.memory }}
ibmcloud ce sub cron update --name ${{ inputs.name }} --destination-type ${{ inputs.destination-type }} --destination ${{ inputs.destination }} --path ${{ inputs.path }} --extension ${{ inputs.extension }} --schedule "${{ inputs.schedule }}"

else
ibmcloud ce sub cron create --name ${{ inputs.name }} --destination-type ${{ inputs.destination-type }} --destination ${{ inputs.destination }} --path ${{ inputs.path }} --extension ${{ inputs.extension }} --schedule ${{ inputs.schedule }} --wait ${{ steps.set-resources.outputs.cpu }} ${{ steps.set-resources.outputs.memory }}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please replace with the following in order to create a cron subscription

Suggested change
ibmcloud ce sub cron create --name ${{ inputs.name }} --destination-type ${{ inputs.destination-type }} --destination ${{ inputs.destination }} --path ${{ inputs.path }} --extension ${{ inputs.extension }} --schedule ${{ inputs.schedule }} --wait ${{ steps.set-resources.outputs.cpu }} ${{ steps.set-resources.outputs.memory }}
ibmcloud ce sub cron create --name ${{ inputs.name }} --destination-type ${{ inputs.destination-type }} --destination ${{ inputs.destination }} --path ${{ inputs.path }} --extension ${{ inputs.extension }} --schedule "${{ inputs.schedule }}" --wait

fi

- name: Get component
shell: bash
if: steps.fn-create.outcome == 'success' || steps.app-create.outcome == 'success' || steps.job-create.outcome == 'success'
Expand Down