Skip to content

Simplification of run:* tasks #1106

Open
@hirenr

Description

@hirenr

What would you like to be added?

Extending the discussion from
Slack Discussion

Update the run:* syntax to have a unified structure.

  • Env Variables
  • Arguments (as string[]) passed as CLI args to run:shell / run:container / run:script underlying code command
  • Transformed Task Input passed as STDIN to the run:shell / run:container / run:script underlying code!
  • Transformed Task input passed as Input Object to run:workflow

Proposal(s):

The advantages to the following are:

  • No injection of code into scripts (for input args etc) and other underlying code!
  • Makes the inline/referenced scripts fully portable without relying on the runtime
  • Execution and passing of data to scripts similiar, with how it would work outside of a workflow environment. For eg. when running the script directly via node command.
  • Input (via STDIN) and Output (via STDOUT, STDERR, CODE) more inline with each other.

Below is an example run:script, but other run:* would be similar!

e.g run:script

document:
  dsl: 1.0.0-alpha1
  namespace: examples
  name: call-script-input-type-example
  version: 1.0.0-alpha1
do:
  - setInput:
      set:
        url: https://petstore.swagger.io/v2/pet/2
  - runScript:
      output: 
        as: "${ fromjson }"
      run:
        script:
          language: javascript
          environment:
           url: https://petstore.swagger.io/v2/pet/2
          arguments:
          - https://petstore.swagger.io/v2/pet/2
          source:
            endpoint: file:///scripts/hello_world.js

/scripts/hello_world.js

import axios from 'axios';

// Reading Input from STDIN
const input = await new Promise((resolve) => {
  let data = '';
  process.stdin.setEncoding('utf8');
  process.stdin.on('data', chunk => data += chunk);
  process.stdin.on('end', () => {
    try {
      resolve(JSON.parse(data));
    } catch (error) {
      resolve({})
    }
  });
});
const responseStdin = await axios(input.url);

// Reading from argv
const [_, __, url] = process.argv;
const responseArgv = await axios(url);

// Reading from env
const envUrl = process.env.url;
const responseEnv = await axios(envUrl);

console.log(JSON.stringify({responseStdin: responseStdin.data, responseArgv: responseArgv.data, responseEnv: responseEnv.data }))

Alternative(s):

No response

Additional info:

Why?

  • Current argv/env variables are limited by the underlying OS
  • Cannot pass large data via args/env
  • STDIN has no such limits
  • Inserting named parameters needs code injection. This goes against the ethos of a declarative workflow. Ideally, runtime should not touch the code.

Community Notes

  • Please vote by adding a 👍 reaction to the feature to help us prioritize.
  • If you are interested to work on this feature, please leave a comment.

Metadata

Metadata

Assignees

No one assigned

    Labels

    area: examplesarea: specChanges in the Specificationchange: breakingA breaking change that will impact in a major version change.change: documentationImprovements or additions to documentation. It won't impact a version change.change: featureNew feature or request. Impacts in a minor version changetype: feature

    Projects

    Status

    Backlog

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions