From 6477e86a7f41c673db0c767c90a7d628afd5040f Mon Sep 17 00:00:00 2001 From: Stefan Sauterleute Date: Fri, 8 Nov 2024 11:20:32 +0100 Subject: [PATCH 1/4] Add subscription cron Signed-off-by: Stefan Sauterleute --- README.md | 31 ++++++++++++++++++------------- action.yml | 37 +++++++++++++++++++++++++++++++++++-- 2 files changed, 53 insertions(+), 15 deletions(-) diff --git a/README.md b/README.md index 35bf4b8..6607552 100644 --- a/README.md +++ b/README.md @@ -4,19 +4,24 @@ 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`. | +| `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 diff --git a/action.yml b/action.yml index 6e581e2..f8a4973 100644 --- a/action.yml +++ b/action.yml @@ -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 @@ -36,6 +40,23 @@ 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 only required for subscription + required: false + + schedule: + description: Schedule used for the Subscription only required for 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 @@ -149,6 +170,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 }} --schedule ${{ inputs.schedule }} --wait ${{ steps.set-resources.outputs.cpu }} ${{ steps.set-resources.outputs.memory }} + else + ibmcloud ce sub cron create --name ${{ inputs.name }} --destination-type ${{ inputs.destination-type }} --destination ${{ inputs.destination }} --path ${{ inputs.path }} --schedule ${{ inputs.schedule }} --wait ${{ steps.set-resources.outputs.cpu }} ${{ steps.set-resources.outputs.memory }} + fi + - name: Get component shell: bash if: steps.fn-create.outcome == 'success' || steps.app-create.outcome == 'success' || steps.job-create.outcome == 'success' From 3f0c7e172a27206ec01a3b3196ab01294a0dde9c Mon Sep 17 00:00:00 2001 From: Stefan Sauterleute Date: Wed, 13 Nov 2024 14:04:13 +0100 Subject: [PATCH 2/4] Add extension to subscription cron Signed-off-by: Stefan Sauterleute --- README.md | 1 + action.yml | 12 ++++++++---- 2 files changed, 9 insertions(+), 4 deletions(-) diff --git a/README.md b/README.md index 6607552..1172f03 100644 --- a/README.md +++ b/README.md @@ -21,6 +21,7 @@ This GitHub Action allows you to interact with IBM Cloud Code Engine. Deploy App | `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 diff --git a/action.yml b/action.yml index f8a4973..adee0f2 100644 --- a/action.yml +++ b/action.yml @@ -50,11 +50,15 @@ inputs: required: false path: - description: Path used for the Subscription only required for subscription + 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 only required for subscription. For example, specify '*/2 * * * *' (in string format) for every two minutes + description: Schedule used for the Subscription. For example, specify '*/2 * * * *' (in string format) for every two minutes required: false build-source: @@ -177,9 +181,9 @@ runs: 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 }} --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 }} --wait ${{ steps.set-resources.outputs.cpu }} ${{ steps.set-resources.outputs.memory }} else - ibmcloud ce sub cron create --name ${{ inputs.name }} --destination-type ${{ inputs.destination-type }} --destination ${{ inputs.destination }} --path ${{ inputs.path }} --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 ${{ steps.set-resources.outputs.cpu }} ${{ steps.set-resources.outputs.memory }} fi - name: Get component From b2b1c0e1b8899d4f63ced5679fe7bc66b86c6735 Mon Sep 17 00:00:00 2001 From: Stefan Sauterleute Date: Wed, 13 Nov 2024 14:16:40 +0100 Subject: [PATCH 3/4] Add cron subscription example Signed-off-by: Stefan Sauterleute --- README.md | 40 +++++++++++++++++++++++++++++++++++++++- 1 file changed, 39 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index 1172f03..3be3559 100644 --- a/README.md +++ b/README.md @@ -64,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: @@ -161,3 +161,41 @@ jobs: cpu: 1 memory: 4G ``` +*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 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 +``` \ No newline at end of file From 81bbf4660050d7d68cb418436afade9c77cca243 Mon Sep 17 00:00:00 2001 From: Stefan Sauterleute Date: Wed, 13 Nov 2024 14:18:51 +0100 Subject: [PATCH 4/4] Add cron subscription example Signed-off-by: Stefan Sauterleute --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 3be3559..950e047 100644 --- a/README.md +++ b/README.md @@ -161,7 +161,7 @@ jobs: cpu: 1 memory: 4G ``` -*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`. +*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`. ```yaml name: Deploy Cron Subscription to Code Engine