diff --git a/dsl-reference.md b/dsl-reference.md index c605988e..8c115817 100644 --- a/dsl-reference.md +++ b/dsl-reference.md @@ -928,6 +928,8 @@ Enables the execution of external processes encapsulated within a containerized | ports | `map` | `no` | The container's port mappings, if any | | volumes | `map` | `no` | The container's volume mappings, if any | | environment | `map` | `no` | A key/value mapping of the environment variables, if any, to use when running the configured process | +| stdin | `string` | `no` | A runtime expression, if any, passed as standard input to the command or default container CMD| +| arguments | `string[]` | `no` | A list of the arguments, if any, passed as argv to the command or default container CMD | | lifetime | [`containerLifetime`](#container-lifetime) | `no` | An object used to configure the container's lifetime. | ###### Examples @@ -939,10 +941,23 @@ document: name: run-container-example version: '0.1.0' do: + - setInput: + set: + message: Hello World - runContainer: + input: + from: ${ .message } run: container: - image: fake-image + image: alpine + stdin: ${ . } + command: | + input=$(cat) + echo "STDIN was: $input" + echo "ARGS are $1 $2" + arguments: + - Foo + - Bar ``` > [!NOTE] @@ -961,9 +976,11 @@ Enables the execution of custom scripts or code within a workflow, empowering wo | language | `string` | `yes` | The language of the script to run.
*Supported values are: [`js`](https://tc39.es/ecma262/2024/) and [`python`](https://www.python.org/downloads/release/python-3131/).* | | code | `string` | `no` | The script's code.
*Required if `source` has not been set.* | | source | [externalResource](#external-resource) | `no` | The script's resource.
*Required if `code` has not been set.* | -| arguments | `map` | `no` | A list of the arguments, if any, of the script to run | +| stdin | `string` | `no` | A runtime expression, if any, to the script as standard input (stdin).| +| arguments | `string[]` | `no` | A list of the arguments, if any, to the script as argv | | environment | `map` | `no` | A key/value mapping of the environment variables, if any, to use when running the configured script process | + > [!WARNING] > To ensure cross-compatibility, Serverless Workflow strictly limits the versions of supported scripting languages. These versions may evolve with future releases. If you wish to use a different version of a language, you may do so by utilizing the [`container process`](#container-process). @@ -977,19 +994,21 @@ Enables the execution of custom scripts or code within a workflow, empowering wo ```yaml document: - dsl: '1.0.2' - namespace: test + dsl: 1.0.2 + namespace: examples name: run-script-example - version: '0.1.0' + version: 1.0.0 do: - runScript: run: script: language: js arguments: - greetings: Hello, world! - code: > - console.log(greetings) + - hello + - world + code: | + const [_, __, arg0, arg1] = process.argv; + console.log('arg > ', arg0, arg1) ``` ##### Shell Process @@ -1001,7 +1020,8 @@ Enables the execution of shell commands within a workflow, enabling workflows to | Name | Type | Required | Description | |:--|:---:|:---:|:---| | command | `string` | `yes` | The shell command to run | -| arguments | `map` | `no` | A list of the arguments of the shell command to run | +| stdin | `string` | `no` | A runtime expression, if any, to the shell command as standard input (stdin).| +| arguments | `string[]` | `no` | A list of the arguments, if any, to the shell command as argv | | environment | `map` | `no` | A key/value mapping of the environment variables, if any, to use when running the configured process | ###### Examples @@ -1013,10 +1033,22 @@ document: name: run-shell-example version: '0.1.0' do: + - setInput: + set: + message: Hello World - runShell: + input: + from: ${ .message } run: shell: - command: 'echo "Hello, ${ .user.name }"' + stdin: ${ . } + command: | + input=$(cat) + echo "STDIN was: $input" + echo "ARGS are $1 $2" + arguments: + - Foo + - Bar ``` ##### Workflow Process @@ -2829,4 +2861,4 @@ Describes the client of a [Model Context Protocol (MCP)](https://modelcontextpro ```yaml name: synapse version: '1.0.0-alpha5.2' -``` \ No newline at end of file +``` diff --git a/examples/run-container-stdin-and-arguments.yaml b/examples/run-container-stdin-and-arguments.yaml new file mode 100644 index 00000000..1bed2db8 --- /dev/null +++ b/examples/run-container-stdin-and-arguments.yaml @@ -0,0 +1,23 @@ +document: + dsl: '1.0.2' + namespace: test + name: run-container-stdin-and-arguments + version: '0.1.0' +do: + - setInput: + set: + message: Hello World + - runContainer: + input: + from: ${ .message } + run: + container: + image: alpine + command: | + input=$(cat) + echo "STDIN was: $input" + echo "ARGS are $1 $2" + stdin: ${ . } + arguments: + - Foo + - Bar diff --git a/examples/run-script-with-arguments.yaml b/examples/run-script-with-arguments.yaml deleted file mode 100644 index 78a25ea6..00000000 --- a/examples/run-script-with-arguments.yaml +++ /dev/null @@ -1,14 +0,0 @@ -document: - dsl: '1.0.2' - namespace: samples - name: run-script-with-arguments - version: 0.1.0 -do: - - log: - run: - script: - language: javascript - arguments: - message: ${ .message } - code: > - console.log(message) \ No newline at end of file diff --git a/examples/run-script-with-stdin-and-arguments.yaml b/examples/run-script-with-stdin-and-arguments.yaml new file mode 100644 index 00000000..915a0266 --- /dev/null +++ b/examples/run-script-with-stdin-and-arguments.yaml @@ -0,0 +1,28 @@ +document: + dsl: 1.0.2 + namespace: examples + name: run-script-with-stdin-and-arguments + version: 1.0.0 +do: + - runScript: + run: + script: + language: javascript + stdin: "Hello Workflow" + environment: + foo: bar + arguments: + - hello + code: | + // Reading Input from STDIN + import { readFileSync } from 'node:fs'; + const stdin = readFileSync(process.stdin.fd, 'utf8'); + console.log('stdin > ', stdin) // Output: stdin > Hello Workflow + + // Reading from argv + const [_, __, arg] = process.argv; + console.log('arg > ', arg) // Output: arg > hello + + // Reading from env + const foo = process.env.foo; + console.log('env > ', foo) // Output: env > bar diff --git a/examples/run-shell-stdin-and-arguments.yaml b/examples/run-shell-stdin-and-arguments.yaml new file mode 100644 index 00000000..22171d7d --- /dev/null +++ b/examples/run-shell-stdin-and-arguments.yaml @@ -0,0 +1,22 @@ +document: + dsl: 1.0.2 + namespace: examples + name: run-shell-with-stdin-and-arguments + version: 1.0.0 +do: + - setInput: + set: + message: Hello World + - runShell: + input: + from: ${ .message } + run: + shell: + stdin: ${ . } + command: | + input=$(cat) + echo "STDIN was: $input" + echo "ARGS are $1 $2" + arguments: + - Foo + - Bar diff --git a/schema/workflow.yaml b/schema/workflow.yaml index e47ff664..40569a4a 100644 --- a/schema/workflow.yaml +++ b/schema/workflow.yaml @@ -809,6 +809,16 @@ $defs: type: object title: ContainerEnvironment description: A key/value mapping of the environment variables, if any, to use when running the configured process. + stdin: + type: string + title: ContainerStdin + description: A runtime expression, if any, passed as standard input (stdin) to the command or default container CMD + arguments: + type: array + title: ContainerArguments + description: A list of the arguments, if any, passed as argv to the command or default container CMD + items: + type: string lifetime: $ref: '#/$defs/containerLifetime' title: ContainerLifetime @@ -828,11 +838,16 @@ $defs: type: string title: ScriptLanguage description: The language of the script to run. + stdin: + type: string + title: ScriptStdin + description: A runtime expression, if any, to the script as standard input (stdin). arguments: - type: object + type: array title: ScriptArguments - description: A key/value mapping of the arguments, if any, to use when running the configured script. - additionalProperties: true + description: A list of the arguments, if any, to the script as argv + items: + type: string environment: type: object title: ScriptEnvironment @@ -870,11 +885,16 @@ $defs: type: string title: ShellCommand description: The shell command to run. + stdin: + type: string + title: ShellStdin + description: A runtime expression, if any, to the shell command as standard input (stdin). arguments: - type: object + type: array title: ShellArguments - description: A list of the arguments of the shell command to run. - additionalProperties: true + description: A list of the arguments, if any, to the shell command as argv + items: + type: string environment: type: object title: ShellEnvironment @@ -1928,4 +1948,4 @@ $defs: export: $ref: '#/$defs/export' title: SubscriptionIteratorExport - description: An object, if any, used to customize the content of the workflow context. \ No newline at end of file + description: An object, if any, used to customize the content of the workflow context.