From a58f04b7070a8c2037cca91aed213bd3f832308f Mon Sep 17 00:00:00 2001 From: Lior Soffer Date: Mon, 23 Jun 2025 16:51:37 +0300 Subject: [PATCH] fix(orchestrator): update orchestrator:workflow:run to use workflow_id input Signed-off-by: Lior Soffer --- .../.changeset/tricky-peas-help.md | 6 ++ .../orchestrator/entities/yamlgreet.yaml | 3 +- .../README.md | 90 +++++++++++++++---- .../src/actions/runWorkflow.ts | 14 ++- 4 files changed, 93 insertions(+), 20 deletions(-) create mode 100644 workspaces/orchestrator/.changeset/tricky-peas-help.md diff --git a/workspaces/orchestrator/.changeset/tricky-peas-help.md b/workspaces/orchestrator/.changeset/tricky-peas-help.md new file mode 100644 index 0000000000..ba55ddc82d --- /dev/null +++ b/workspaces/orchestrator/.changeset/tricky-peas-help.md @@ -0,0 +1,6 @@ +--- +'@red-hat-developer-hub/backstage-plugin-scaffolder-backend-module-orchestrator': patch +--- + +- update orchestrator:workflow:run to use workflow_id +- update README for scaffolder-backend-module-orchestrator diff --git a/workspaces/orchestrator/entities/yamlgreet.yaml b/workspaces/orchestrator/entities/yamlgreet.yaml index 34560c1b24..1b34e33fa7 100644 --- a/workspaces/orchestrator/entities/yamlgreet.yaml +++ b/workspaces/orchestrator/entities/yamlgreet.yaml @@ -1,7 +1,7 @@ apiVersion: scaffolder.backstage.io/v1beta3 kind: Template metadata: - name: yamlgreet # matches workflow ID + name: greet title: Greeting description: Greeting workflow tags: @@ -35,6 +35,7 @@ spec: name: Run workflow action: orchestrator:workflow:run input: + workflow_id: yamlgreet parameters: ${{ parameters }} output: diff --git a/workspaces/orchestrator/plugins/scaffolder-backend-module-orchestrator/README.md b/workspaces/orchestrator/plugins/scaffolder-backend-module-orchestrator/README.md index 8b60056d87..dc96a82c13 100644 --- a/workspaces/orchestrator/plugins/scaffolder-backend-module-orchestrator/README.md +++ b/workspaces/orchestrator/plugins/scaffolder-backend-module-orchestrator/README.md @@ -6,15 +6,19 @@ An example of using these actions can be found in the `workspaces/orchestrator/e ## Installation -### As a static plugin +### Static Plugin Installation In `packages/backend/src/index.ts`: -``` -backend.add(import('@red-hat-developer-hub/backstage-plugin-scaffolder-backend-module-orchestrator')); +```ts +backend.add( + import( + '@red-hat-developer-hub/backstage-plugin-scaffolder-backend-module-orchestrator' + ), +); ``` -# The software template generating templates from workflows - convertWorkflowToTemplate +## convertWorkflowToTemplate: A Software Template for Converting Workflows into Templates The `workspaces/orchestrator/entities/convertWorkflowToTemplate.yaml` scaffolder software template is used for generating templates to be used to execute a serverless workflow via the Orchestrator. @@ -26,7 +30,7 @@ The rest of parameters cover details about the target GitHub repository to eithe The generated yaml template is accompanied by a README file highlighting instructions how to register the new template in the Backstage catalog. -## Important Note on Template Input Structure +**Important Note on Template Input Structure:** The structure of the template input differs from that of the page used for collecting input parameters for workflows, despite some similarities. These two pages are supported by distinct implementations. While the set of parameters should remain consistent, their visual representation and especially grouping into steps may vary. @@ -35,7 +39,7 @@ The structure of the template input differs from that of the page used for colle The `[workflowId]` matches the identifier from the workflow definition. For example, in the [workflow definition](https://github.com/rhdhorchestrator/serverless-workflows/blob/main/workflows/greeting/greeting.sw.yaml) below, the identifier is `greeting`: -```yaml greeting.sw.yaml +```yaml id: greeting version: '1.0' specVersion: '0.8' @@ -49,6 +53,52 @@ extensions: outputSchema: schemas/workflow-output-schema.json ``` +## Available Actions + +### Action: `orchestrator:workflow:run` + +Runs a SonataFlow workflow from a Software Template. + +**Input:** + +- `workflow_id` (string, required): The workflow ID from the definition. +- `parameters` (object, required): Input parameters for the workflow. + +**Dry Run:** Supported — logs the event without executing the call. + +**Example:** + +```yaml +steps: + - id: runWorkflow + name: Run workflow + action: orchestrator:workflow:run + input: + workflow_id: yamlgreet + parameters: ${{ parameters }} +``` + +--- + +### Action: `orchestrator:workflow:get_params` + +Retrieves metadata and input schema from a SonataFlow workflow. + +**Input:** + +- `workflow_id` (string, required): The workflow ID. +- `indent` (number, optional): Indentation level for the resulting YAML. + +**Output:** + +- `title` +- `description` +- `parameters` + +**Dry Run:** Not supported. + +--- + ## GitHub integration The `convertWorkflowToTemplate.yaml` template pushes the result into a GitHub repository. @@ -76,18 +126,26 @@ export GITHUB_TOKEN=....... - configure `app-config.yaml`: -``` -integrations: - github: - - token: ${GITHUB_TOKEN} -``` + ```yaml + integrations: + github: + - token: ${GITHUB_TOKEN} + ``` -## Resources +--- + +## Hints -- [Upstream documentation](https://backstage.io/docs/features/software-templates/builtin-actions) +- When using **Node.js 20+**, add this environment variable **before** running the backend: -# Hints + ```bash + export NODE_OPTIONS="${NODE_OPTIONS:-} --no-node-snapshot" + ``` -Mind using `export NODE_OPTIONS="${NODE_OPTIONS:-} --no-node-snapshot"` before running the Backstage backend app with Node 20+ (per actual [warning in the upstream documentation](https://backstage.io/docs/features/software-templates/#getting-started)) - this might be changed in the future. + [Reference from Backstage documentation](https://backstage.io/docs/features/software-templates/#getting-started) + +--- + +## Resources -Before running the Backstage backend app with **Node 20+**, be sure to execute `export NODE_OPTIONS="${NODE_OPTIONS:-} --no-node-snapshot` as recommended by the [warning in the upstream documentation](https://backstage.io/docs/features/software-templates/#getting-started) (this might be changed in the future). +- [Backstage Template Actions Documentation](https://backstage.io/docs/features/software-templates/builtin-actions) diff --git a/workspaces/orchestrator/plugins/scaffolder-backend-module-orchestrator/src/actions/runWorkflow.ts b/workspaces/orchestrator/plugins/scaffolder-backend-module-orchestrator/src/actions/runWorkflow.ts index af8f40dd94..f9af4cfcd0 100644 --- a/workspaces/orchestrator/plugins/scaffolder-backend-module-orchestrator/src/actions/runWorkflow.ts +++ b/workspaces/orchestrator/plugins/scaffolder-backend-module-orchestrator/src/actions/runWorkflow.ts @@ -14,7 +14,6 @@ * limitations under the License. */ import { AuthService } from '@backstage/backend-plugin-api'; -import { parseEntityRef } from '@backstage/catalog-model'; import { DiscoveryApi } from '@backstage/plugin-permission-common/index'; import { createTemplateAction } from '@backstage/plugin-scaffolder-node'; import { JsonObject } from '@backstage/types'; @@ -23,7 +22,10 @@ import { isAxiosError } from 'axios'; import { getOrchestratorApi, getRequestConfigOption } from './utils'; -type RunWorkflowTemplateActionInput = { parameters: JsonObject }; +type RunWorkflowTemplateActionInput = { + parameters: JsonObject; + workflow_id: string; +}; type RunWorkflowTemplateActionOutput = { instanceUrl: string }; const getError = (err: unknown): Error => { @@ -77,9 +79,15 @@ export const createRunWorkflowAction = ( return; } + if (!ctx.input.workflow_id) { + throw new Error( + "Missing required 'workflow_id' input. Ensure that the step invoking the 'orchestrator:workflow:run' action includes an explicit 'workflow_id' field in its input.", + ); + } + try { const { data } = await api.executeWorkflow( - parseEntityRef(entity).name, + ctx.input.workflow_id, { inputData: ctx.input.parameters }, undefined, reqConfigOption,