diff --git a/docs/examples/workflows/coinflip.md b/docs/examples/workflows/coinflip.md index 8ada43a6d..04101c8d3 100644 --- a/docs/examples/workflows/coinflip.md +++ b/docs/examples/workflows/coinflip.md @@ -4,105 +4,107 @@ -## Hera -```python -from hera.workflows import DAG, Workflow, script +=== "Hera" + ```python linenums="1" + from hera.workflows import DAG, Workflow, script -@script() -def flip(): - import random - - result = "heads" if random.randint(0, 1) == 0 else "tails" - print(result) + @script() + def flip(): + import random -@script() -def heads(): - print("it was heads") + result = "heads" if random.randint(0, 1) == 0 else "tails" + print(result) -@script() -def tails(): - print("it was tails") + @script() + def heads(): + print("it was heads") -with Workflow(generate_name="coinflip-", entrypoint="d") as w: - with DAG(name="d") as s: - f = flip() - heads().on_other_result(f, "heads") - tails().on_other_result(f, "tails") -``` + @script() + def tails(): + print("it was tails") -## YAML -```yaml -apiVersion: argoproj.io/v1alpha1 -kind: Workflow -metadata: - generateName: coinflip- -spec: - entrypoint: d - templates: - - dag: - tasks: + with Workflow(generate_name="coinflip-", entrypoint="d") as w: + with DAG(name="d") as s: + f = flip() + heads().on_other_result(f, "heads") + tails().on_other_result(f, "tails") + ``` + +=== "YAML" + + ```yaml linenums="1" + apiVersion: argoproj.io/v1alpha1 + kind: Workflow + metadata: + generateName: coinflip- + spec: + entrypoint: d + templates: + - dag: + tasks: + - name: flip + template: flip + - depends: flip + name: heads + template: heads + when: '{{tasks.flip.outputs.result}} == heads' + - depends: flip + name: tails + template: tails + when: '{{tasks.flip.outputs.result}} == tails' + name: d - name: flip - template: flip - - depends: flip - name: heads - template: heads - when: '{{tasks.flip.outputs.result}} == heads' - - depends: flip - name: tails - template: tails - when: '{{tasks.flip.outputs.result}} == tails' - name: d - - name: flip - script: - command: - - python - image: python:3.7 - source: 'import os - - import sys - - sys.path.append(os.getcwd()) + script: + command: + - python + image: python:3.7 + source: 'import os - import random + import sys + sys.path.append(os.getcwd()) - result = "heads" if random.randint(0, 1) == 0 else "tails" + import random - print(result) - ' - - name: heads - script: - command: - - python - image: python:3.7 - source: 'import os + result = "heads" if random.randint(0, 1) == 0 else "tails" - import sys + print(result) - sys.path.append(os.getcwd()) + ' + - name: heads + script: + command: + - python + image: python:3.7 + source: 'import os - print("it was heads") + import sys - ' - - name: tails - script: - command: - - python - image: python:3.7 - source: 'import os + sys.path.append(os.getcwd()) - import sys + print("it was heads") - sys.path.append(os.getcwd()) + ' + - name: tails + script: + command: + - python + image: python:3.7 + source: 'import os - print("it was tails") + import sys + + sys.path.append(os.getcwd()) + + print("it was tails") + + ' + ``` - ' -``` diff --git a/docs/examples/workflows/dag_conditional_parameters.md b/docs/examples/workflows/dag_conditional_parameters.md index 35ba37755..a6f28c2cb 100644 --- a/docs/examples/workflows/dag_conditional_parameters.md +++ b/docs/examples/workflows/dag_conditional_parameters.md @@ -4,98 +4,100 @@ -## Hera -```python -from hera.expr import g -from hera.workflows import DAG, Parameter, Workflow, script +=== "Hera" + ```python linenums="1" + from hera.expr import g + from hera.workflows import DAG, Parameter, Workflow, script -@script(add_cwd_to_sys_path=False, image="python:alpine3.6") -def heads(): - print("heads") + @script(add_cwd_to_sys_path=False, image="python:alpine3.6") + def heads(): + print("heads") -@script(add_cwd_to_sys_path=False, image="python:alpine3.6") -def tails(): - print("tails") + @script(add_cwd_to_sys_path=False, image="python:alpine3.6") + def tails(): + print("tails") -@script(add_cwd_to_sys_path=False, image="python:alpine3.6") -def flip_coin(): - import random - print("heads" if random.randint(0, 1) == 0 else "tails") + @script(add_cwd_to_sys_path=False, image="python:alpine3.6") + def flip_coin(): + import random + print("heads" if random.randint(0, 1) == 0 else "tails") -with Workflow( - generate_name="dag-conditional-parameter-", - entrypoint="main", -) as w: - with DAG(name="main") as main_dag: - fc = flip_coin(name="flip-coin") - h = heads(name="heads").on_other_result(fc, "heads") - t = tails(name="tails").on_other_result(fc, "tails") - - expression = g.tasks["flip-coin"].outputs.result == "heads" - expression = expression.check(g.tasks.heads.outputs.result, g.tasks.tails.outputs.result) # type: ignore - main_dag.outputs = [Parameter(name="stepresult", value_from={"expression": str(expression)})] -``` - -## YAML -```yaml -apiVersion: argoproj.io/v1alpha1 -kind: Workflow -metadata: - generateName: dag-conditional-parameter- -spec: - entrypoint: main - templates: - - dag: - tasks: + with Workflow( + generate_name="dag-conditional-parameter-", + entrypoint="main", + ) as w: + with DAG(name="main") as main_dag: + fc = flip_coin(name="flip-coin") + h = heads(name="heads").on_other_result(fc, "heads") + t = tails(name="tails").on_other_result(fc, "tails") + + expression = g.tasks["flip-coin"].outputs.result == "heads" + expression = expression.check(g.tasks.heads.outputs.result, g.tasks.tails.outputs.result) # type: ignore + main_dag.outputs = [Parameter(name="stepresult", value_from={"expression": str(expression)})] + ``` + +=== "YAML" + + ```yaml linenums="1" + apiVersion: argoproj.io/v1alpha1 + kind: Workflow + metadata: + generateName: dag-conditional-parameter- + spec: + entrypoint: main + templates: + - dag: + tasks: + - name: flip-coin + template: flip-coin + - depends: flip-coin + name: heads + template: heads + when: '{{tasks.flip-coin.outputs.result}} == heads' + - depends: flip-coin + name: tails + template: tails + when: '{{tasks.flip-coin.outputs.result}} == tails' + name: main + outputs: + parameters: + - name: stepresult + valueFrom: + expression: 'tasks[''flip-coin''].outputs.result == ''heads'' ? tasks.heads.outputs.result + : tasks.tails.outputs.result' - name: flip-coin - template: flip-coin - - depends: flip-coin - name: heads - template: heads - when: '{{tasks.flip-coin.outputs.result}} == heads' - - depends: flip-coin - name: tails - template: tails - when: '{{tasks.flip-coin.outputs.result}} == tails' - name: main - outputs: - parameters: - - name: stepresult - valueFrom: - expression: 'tasks[''flip-coin''].outputs.result == ''heads'' ? tasks.heads.outputs.result - : tasks.tails.outputs.result' - - name: flip-coin - script: - command: - - python - image: python:alpine3.6 - source: 'import random - - - print("heads" if random.randint(0, 1) == 0 else "tails") + script: + command: + - python + image: python:alpine3.6 + source: 'import random + + + print("heads" if random.randint(0, 1) == 0 else "tails") + + ' + - name: heads + script: + command: + - python + image: python:alpine3.6 + source: 'print("heads") + + ' + - name: tails + script: + command: + - python + image: python:alpine3.6 + source: 'print("tails") + + ' + ``` - ' - - name: heads - script: - command: - - python - image: python:alpine3.6 - source: 'print("heads") - - ' - - name: tails - script: - command: - - python - image: python:alpine3.6 - source: 'print("tails") - - ' -``` diff --git a/docs/examples/workflows/dag_diamond_with_callable_container.md b/docs/examples/workflows/dag_diamond_with_callable_container.md index 6bd523210..08a73eb34 100644 --- a/docs/examples/workflows/dag_diamond_with_callable_container.md +++ b/docs/examples/workflows/dag_diamond_with_callable_container.md @@ -4,81 +4,83 @@ -## Hera -```python -from hera.workflows import ( - DAG, - Container, - Parameter, - Workflow, -) +=== "Hera" -with Workflow( - generate_name="dag-diamond-", - entrypoint="diamond", -) as w: - echo = Container( - name="echo", - image="alpine:3.7", - command=["echo", "{{inputs.parameters.message}}"], - inputs=[Parameter(name="message")], + ```python linenums="1" + from hera.workflows import ( + DAG, + Container, + Parameter, + Workflow, ) - with DAG(name="diamond"): - A = echo(name="A", arguments={"message": "A"}) - B = echo(name="B", arguments={"message": "B"}) - C = echo(name="C", arguments={"message": "C"}) - D = echo(name="D", arguments={"message": "D"}) - A >> [B, C] >> D -``` -## YAML + with Workflow( + generate_name="dag-diamond-", + entrypoint="diamond", + ) as w: + echo = Container( + name="echo", + image="alpine:3.7", + command=["echo", "{{inputs.parameters.message}}"], + inputs=[Parameter(name="message")], + ) + with DAG(name="diamond"): + A = echo(name="A", arguments={"message": "A"}) + B = echo(name="B", arguments={"message": "B"}) + C = echo(name="C", arguments={"message": "C"}) + D = echo(name="D", arguments={"message": "D"}) + A >> [B, C] >> D + ``` -```yaml -apiVersion: argoproj.io/v1alpha1 -kind: Workflow -metadata: - generateName: dag-diamond- -spec: - entrypoint: diamond - templates: - - container: - command: - - echo - - '{{inputs.parameters.message}}' - image: alpine:3.7 - inputs: - parameters: - - name: message - name: echo - - dag: - tasks: - - arguments: - parameters: - - name: message - value: A - name: A - template: echo - - arguments: - parameters: - - name: message - value: B - depends: A - name: B - template: echo - - arguments: - parameters: - - name: message - value: C - depends: A - name: C - template: echo - - arguments: +=== "YAML" + + ```yaml linenums="1" + apiVersion: argoproj.io/v1alpha1 + kind: Workflow + metadata: + generateName: dag-diamond- + spec: + entrypoint: diamond + templates: + - container: + command: + - echo + - '{{inputs.parameters.message}}' + image: alpine:3.7 + inputs: parameters: - name: message - value: D - depends: B && C - name: D - template: echo - name: diamond -``` + name: echo + - dag: + tasks: + - arguments: + parameters: + - name: message + value: A + name: A + template: echo + - arguments: + parameters: + - name: message + value: B + depends: A + name: B + template: echo + - arguments: + parameters: + - name: message + value: C + depends: A + name: C + template: echo + - arguments: + parameters: + - name: message + value: D + depends: B && C + name: D + template: echo + name: diamond + ``` + diff --git a/docs/examples/workflows/dag_diamond_with_callable_decorators.md b/docs/examples/workflows/dag_diamond_with_callable_decorators.md index e9981f2cc..8318d8010 100644 --- a/docs/examples/workflows/dag_diamond_with_callable_decorators.md +++ b/docs/examples/workflows/dag_diamond_with_callable_decorators.md @@ -4,86 +4,88 @@ -## Hera - -```python -from hera.workflows import ( - DAG, - Workflow, - script, -) - - -@script(add_cwd_to_sys_path=False, image="python:alpine3.6") -def echo(message): - print(message) - - -with Workflow(generate_name="dag-diamond-", entrypoint="diamond") as w: - with DAG(name="diamond"): - A = echo(name="A", arguments={"message": "A"}) - B = echo(name="B", arguments={"message": "B"}) - C = echo(name="C", arguments={"message": "C"}) - D = echo(name="D", arguments={"message": "D"}) - A >> [B, C] >> D -``` - -## YAML - -```yaml -apiVersion: argoproj.io/v1alpha1 -kind: Workflow -metadata: - generateName: dag-diamond- -spec: - entrypoint: diamond - templates: - - dag: - tasks: - - arguments: - parameters: - - name: message - value: A - name: A - template: echo - - arguments: - parameters: - - name: message - value: B - depends: A - name: B - template: echo - - arguments: - parameters: - - name: message - value: C - depends: A - name: C - template: echo - - arguments: + +=== "Hera" + + ```python linenums="1" + from hera.workflows import ( + DAG, + Workflow, + script, + ) + + + @script(add_cwd_to_sys_path=False, image="python:alpine3.6") + def echo(message): + print(message) + + + with Workflow(generate_name="dag-diamond-", entrypoint="diamond") as w: + with DAG(name="diamond"): + A = echo(name="A", arguments={"message": "A"}) + B = echo(name="B", arguments={"message": "B"}) + C = echo(name="C", arguments={"message": "C"}) + D = echo(name="D", arguments={"message": "D"}) + A >> [B, C] >> D + ``` + +=== "YAML" + + ```yaml linenums="1" + apiVersion: argoproj.io/v1alpha1 + kind: Workflow + metadata: + generateName: dag-diamond- + spec: + entrypoint: diamond + templates: + - dag: + tasks: + - arguments: + parameters: + - name: message + value: A + name: A + template: echo + - arguments: + parameters: + - name: message + value: B + depends: A + name: B + template: echo + - arguments: + parameters: + - name: message + value: C + depends: A + name: C + template: echo + - arguments: + parameters: + - name: message + value: D + depends: B && C + name: D + template: echo + name: diamond + - inputs: parameters: - name: message - value: D - depends: B && C - name: D - template: echo - name: diamond - - inputs: - parameters: - - name: message - name: echo - script: - command: - - python - image: python:alpine3.6 - source: 'import json - - try: message = json.loads(r''''''{{inputs.parameters.message}}'''''') - - except: message = r''''''{{inputs.parameters.message}}'''''' + name: echo + script: + command: + - python + image: python:alpine3.6 + source: 'import json + try: message = json.loads(r''''''{{inputs.parameters.message}}'''''') - print(message) + except: message = r''''''{{inputs.parameters.message}}'''''' + + + print(message) + + ' + ``` - ' -``` diff --git a/docs/examples/workflows/dag_diamond_with_callable_script.md b/docs/examples/workflows/dag_diamond_with_callable_script.md index a3515c0d5..ace829d35 100644 --- a/docs/examples/workflows/dag_diamond_with_callable_script.md +++ b/docs/examples/workflows/dag_diamond_with_callable_script.md @@ -4,102 +4,104 @@ -## Hera -```python -from hera.workflows import ( - DAG, - Parameter, - Script, - Workflow, -) +=== "Hera" - -def my_print_script(message): - print(message) - - -def get_script(callable): - # note that we have the _option_ to set `inputs=Parameter(name="message")`, but Hera infers the `Parameter`s - # that are necessary based on the passed in callable! - return Script( - name=callable.__name__.replace("_", "-"), - source=callable, - add_cwd_to_sys_path=False, - image="python:alpine3.6", + ```python linenums="1" + from hera.workflows import ( + DAG, + Parameter, + Script, + Workflow, ) -with Workflow( - generate_name="dag-diamond-", - entrypoint="diamond", -) as w: - echo = get_script(my_print_script) - - with DAG(name="diamond"): - A = echo(name="A", arguments=[Parameter(name="message", value="A")]) - B = echo(name="B", arguments=[Parameter(name="message", value="B")]) - C = echo(name="C", arguments=[Parameter(name="message", value="C")]) - D = echo(name="D", arguments=[Parameter(name="message", value="D")]) - A >> [B, C] >> D -``` - -## YAML - -```yaml -apiVersion: argoproj.io/v1alpha1 -kind: Workflow -metadata: - generateName: dag-diamond- -spec: - entrypoint: diamond - templates: - - inputs: - parameters: - - name: message - name: my-print-script - script: - command: - - python - image: python:alpine3.6 - source: 'import json - - try: message = json.loads(r''''''{{inputs.parameters.message}}'''''') - - except: message = r''''''{{inputs.parameters.message}}'''''' - - + def my_print_script(message): print(message) - ' - - dag: - tasks: - - arguments: - parameters: - - name: message - value: A - name: A - template: my-print-script - - arguments: - parameters: - - name: message - value: B - depends: A - name: B - template: my-print-script - - arguments: - parameters: - - name: message - value: C - depends: A - name: C - template: my-print-script - - arguments: + + def get_script(callable): + # note that we have the _option_ to set `inputs=Parameter(name="message")`, but Hera infers the `Parameter`s + # that are necessary based on the passed in callable! + return Script( + name=callable.__name__.replace("_", "-"), + source=callable, + add_cwd_to_sys_path=False, + image="python:alpine3.6", + ) + + + with Workflow( + generate_name="dag-diamond-", + entrypoint="diamond", + ) as w: + echo = get_script(my_print_script) + + with DAG(name="diamond"): + A = echo(name="A", arguments=[Parameter(name="message", value="A")]) + B = echo(name="B", arguments=[Parameter(name="message", value="B")]) + C = echo(name="C", arguments=[Parameter(name="message", value="C")]) + D = echo(name="D", arguments=[Parameter(name="message", value="D")]) + A >> [B, C] >> D + ``` + +=== "YAML" + + ```yaml linenums="1" + apiVersion: argoproj.io/v1alpha1 + kind: Workflow + metadata: + generateName: dag-diamond- + spec: + entrypoint: diamond + templates: + - inputs: parameters: - name: message - value: D - depends: B && C - name: D - template: my-print-script - name: diamond -``` + name: my-print-script + script: + command: + - python + image: python:alpine3.6 + source: 'import json + + try: message = json.loads(r''''''{{inputs.parameters.message}}'''''') + + except: message = r''''''{{inputs.parameters.message}}'''''' + + + print(message) + + ' + - dag: + tasks: + - arguments: + parameters: + - name: message + value: A + name: A + template: my-print-script + - arguments: + parameters: + - name: message + value: B + depends: A + name: B + template: my-print-script + - arguments: + parameters: + - name: message + value: C + depends: A + name: C + template: my-print-script + - arguments: + parameters: + - name: message + value: D + depends: B && C + name: D + template: my-print-script + name: diamond + ``` + diff --git a/docs/examples/workflows/data.md b/docs/examples/workflows/data.md index c90beff6a..856b60fd9 100644 --- a/docs/examples/workflows/data.md +++ b/docs/examples/workflows/data.md @@ -4,46 +4,48 @@ -## Hera - -```python -from hera.expr import g, it -from hera.workflows import ( - Artifact, - Data, - S3Artifact, - Workflow, -) - -with Workflow(generate_name="data-") as w: - Data( - name="list-log-files", - source=S3Artifact(name="test-bucket", bucket="my-bucket"), - transformations=[g.data.filter(it.ends_with("main.log"))], # type: ignore - outputs=Artifact(name="file", path="/file"), + +=== "Hera" + + ```python linenums="1" + from hera.expr import g, it + from hera.workflows import ( + Artifact, + Data, + S3Artifact, + Workflow, ) -``` - -## YAML - -```yaml -apiVersion: argoproj.io/v1alpha1 -kind: Workflow -metadata: - generateName: data- -spec: - templates: - - data: - source: - artifactPaths: - name: test-bucket - s3: - bucket: my-bucket - transformation: - - expression: filter(data, {# endsWith 'main.log'}) - name: list-log-files - outputs: - artifacts: - - name: file - path: /file -``` + + with Workflow(generate_name="data-") as w: + Data( + name="list-log-files", + source=S3Artifact(name="test-bucket", bucket="my-bucket"), + transformations=[g.data.filter(it.ends_with("main.log"))], # type: ignore + outputs=Artifact(name="file", path="/file"), + ) + ``` + +=== "YAML" + + ```yaml linenums="1" + apiVersion: argoproj.io/v1alpha1 + kind: Workflow + metadata: + generateName: data- + spec: + templates: + - data: + source: + artifactPaths: + name: test-bucket + s3: + bucket: my-bucket + transformation: + - expression: filter(data, {# endsWith 'main.log'}) + name: list-log-files + outputs: + artifacts: + - name: file + path: /file + ``` + diff --git a/docs/examples/workflows/http_.md b/docs/examples/workflows/http_.md index 7a7547455..f9b7f1096 100644 --- a/docs/examples/workflows/http_.md +++ b/docs/examples/workflows/http_.md @@ -4,45 +4,47 @@ -## Hera - -```python -from hera.expr import g -from hera.workflows import HTTP, Parameter, Workflow - -with Workflow(generate_name="http-") as w: - HTTP( - name="http", - inputs=[Parameter(name="url")], - timeout_seconds=20, - url=f"{g.inputs.parameters.url:$}", - method="GET", - headers=[{"name": "x-header-name", "value": "test-value"}], - success_condition=str(g.response.body.contains("google")), # type: ignore - body="test body", - ) -``` - -## YAML - -```yaml -apiVersion: argoproj.io/v1alpha1 -kind: Workflow -metadata: - generateName: http- -spec: - templates: - - http: - body: test body - headers: - - name: x-header-name - value: test-value - method: GET - successCondition: response.body contains 'google' - timeoutSeconds: 20 - url: '{{inputs.parameters.url}}' - inputs: - parameters: - - name: url - name: http -``` + +=== "Hera" + + ```python linenums="1" + from hera.expr import g + from hera.workflows import HTTP, Parameter, Workflow + + with Workflow(generate_name="http-") as w: + HTTP( + name="http", + inputs=[Parameter(name="url")], + timeout_seconds=20, + url=f"{g.inputs.parameters.url:$}", + method="GET", + headers=[{"name": "x-header-name", "value": "test-value"}], + success_condition=str(g.response.body.contains("google")), # type: ignore + body="test body", + ) + ``` + +=== "YAML" + + ```yaml linenums="1" + apiVersion: argoproj.io/v1alpha1 + kind: Workflow + metadata: + generateName: http- + spec: + templates: + - http: + body: test body + headers: + - name: x-header-name + value: test-value + method: GET + successCondition: response.body contains 'google' + timeoutSeconds: 20 + url: '{{inputs.parameters.url}}' + inputs: + parameters: + - name: url + name: http + ``` + diff --git a/docs/examples/workflows/resource_flags.md b/docs/examples/workflows/resource_flags.md index 36a0d6932..c9eb7be43 100644 --- a/docs/examples/workflows/resource_flags.md +++ b/docs/examples/workflows/resource_flags.md @@ -4,76 +4,78 @@ -## Hera -```python -from hera.workflows import ( - Resource, - Step, - Steps, - Workflow, - models as m, -) +=== "Hera" -with Workflow( - generate_name="resource-validate-", - entrypoint="resource-validate-example", -) as w: - create_route = Resource( - name="create-route", - action="create", - manifest="apiVersion: route.openshift.io/v1\nkind: Route\nmetadata:\n name: host-route\n" - "spec:\n to:\n kind: Service\n name: service-name\n", + ```python linenums="1" + from hera.workflows import ( + Resource, + Step, + Steps, + Workflow, + models as m, ) - create_route_without_validation = Resource( - name="create-route-without-validation", - action="create", - flags=[ - "--validate=false", - ], - manifest="apiVersion: route.openshift.io/v1\nkind: Route\nmetadata:\n name: host-route\n" - "spec:\n to:\n kind: Service\n name: service-name\n", - ) + with Workflow( + generate_name="resource-validate-", + entrypoint="resource-validate-example", + ) as w: + create_route = Resource( + name="create-route", + action="create", + manifest="apiVersion: route.openshift.io/v1\nkind: Route\nmetadata:\n name: host-route\n" + "spec:\n to:\n kind: Service\n name: service-name\n", + ) - with Steps(name="resource-validate-example") as s: - Step(name="submit-resource", template=create_route.name, continue_on=m.ContinueOn(failed=True)) - Step( - name="submit-resource-without-validation", - template=create_route_without_validation.name, - when="{{steps.submit-resource.status}} == Failed", + create_route_without_validation = Resource( + name="create-route-without-validation", + action="create", + flags=[ + "--validate=false", + ], + manifest="apiVersion: route.openshift.io/v1\nkind: Route\nmetadata:\n name: host-route\n" + "spec:\n to:\n kind: Service\n name: service-name\n", ) -``` -## YAML + with Steps(name="resource-validate-example") as s: + Step(name="submit-resource", template=create_route.name, continue_on=m.ContinueOn(failed=True)) + Step( + name="submit-resource-without-validation", + template=create_route_without_validation.name, + when="{{steps.submit-resource.status}} == Failed", + ) + ``` + +=== "YAML" + + ```yaml linenums="1" + apiVersion: argoproj.io/v1alpha1 + kind: Workflow + metadata: + generateName: resource-validate- + spec: + entrypoint: resource-validate-example + templates: + - name: create-route + resource: + action: create + manifest: "apiVersion: route.openshift.io/v1\nkind: Route\nmetadata:\n name:\ + \ host-route\nspec:\n to:\n kind: Service\n name: service-name\n" + - name: create-route-without-validation + resource: + action: create + flags: + - --validate=false + manifest: "apiVersion: route.openshift.io/v1\nkind: Route\nmetadata:\n name:\ + \ host-route\nspec:\n to:\n kind: Service\n name: service-name\n" + - name: resource-validate-example + steps: + - - continueOn: + failed: true + name: submit-resource + template: create-route + - - name: submit-resource-without-validation + template: create-route-without-validation + when: '{{steps.submit-resource.status}} == Failed' + ``` -```yaml -apiVersion: argoproj.io/v1alpha1 -kind: Workflow -metadata: - generateName: resource-validate- -spec: - entrypoint: resource-validate-example - templates: - - name: create-route - resource: - action: create - manifest: "apiVersion: route.openshift.io/v1\nkind: Route\nmetadata:\n name:\ - \ host-route\nspec:\n to:\n kind: Service\n name: service-name\n" - - name: create-route-without-validation - resource: - action: create - flags: - - --validate=false - manifest: "apiVersion: route.openshift.io/v1\nkind: Route\nmetadata:\n name:\ - \ host-route\nspec:\n to:\n kind: Service\n name: service-name\n" - - name: resource-validate-example - steps: - - - continueOn: - failed: true - name: submit-resource - template: create-route - - - name: submit-resource-without-validation - template: create-route-without-validation - when: '{{steps.submit-resource.status}} == Failed' -``` diff --git a/docs/examples/workflows/steps_types.md b/docs/examples/workflows/steps_types.md index 324be0f84..6889f770b 100644 --- a/docs/examples/workflows/steps_types.md +++ b/docs/examples/workflows/steps_types.md @@ -4,192 +4,194 @@ -## Hera - -```python -from hera.workflows import ( - Container, - Parameter, - Step, - Steps, - Workflow, - models as m, -) - -my_step = Step( - name="manually-adding-my-step", - template="whalesay", - arguments=[Parameter(name="message", value="hello1")], -) - - -my_steps = [ - Step( - name="list-of-step-1", - template="whalesay", - arguments=[Parameter(name="message", value="hello1")], - ), - Step( - name="list-of-step-2", + +=== "Hera" + + ```python linenums="1" + from hera.workflows import ( + Container, + Parameter, + Step, + Steps, + Workflow, + models as m, + ) + + my_step = Step( + name="manually-adding-my-step", template="whalesay", arguments=[Parameter(name="message", value="hello1")], - ), -] - -with Workflow( - generate_name="steps-", - entrypoint="hello-hello-hello", -) as w: - whalesay = Container( - name="whalesay", - inputs=[Parameter(name="message")], - image="docker/whalesay", - command=["cowsay"], - args=["{{inputs.parameters.message}}"], ) - with Steps(name="hello-hello-hello") as s: - # Manually add a step defined elsewhere - s.sub_steps.append(my_step) - # Manually add a list of steps defined elsewhere as sequential steps - s.sub_steps.extend(my_steps) - - # Manually add a list of steps defined elsewhere as parallel steps - s.sub_steps.append(my_steps) - - # Add a step to s implicitly through init + my_steps = [ + Step( + name="list-of-step-1", + template="whalesay", + arguments=[Parameter(name="message", value="hello1")], + ), Step( - name="implicitly-adding-step-on-init", + name="list-of-step-2", template="whalesay", arguments=[Parameter(name="message", value="hello1")], + ), + ] + + with Workflow( + generate_name="steps-", + entrypoint="hello-hello-hello", + ) as w: + whalesay = Container( + name="whalesay", + inputs=[Parameter(name="message")], + image="docker/whalesay", + command=["cowsay"], + args=["{{inputs.parameters.message}}"], ) - # Manually add a model WorkflowStep to s - s.sub_steps.append( - m.WorkflowStep( - name="model-workflow-step", - template="whalesay", - arguments=m.Arguments(parameters=[Parameter(name="message", value="hello-model1")]), - ) - ) + with Steps(name="hello-hello-hello") as s: + # Manually add a step defined elsewhere + s.sub_steps.append(my_step) + + # Manually add a list of steps defined elsewhere as sequential steps + s.sub_steps.extend(my_steps) + + # Manually add a list of steps defined elsewhere as parallel steps + s.sub_steps.append(my_steps) - with s.parallel() as ps: - # Add a step to ps implicitly through init + # Add a step to s implicitly through init Step( - name="parallel-step-1", + name="implicitly-adding-step-on-init", template="whalesay", - arguments=[Parameter(name="message", value="hello2a")], + arguments=[Parameter(name="message", value="hello1")], ) - # Manually add a model WorkflowStep to ps - ps.sub_steps.append( + # Manually add a model WorkflowStep to s + s.sub_steps.append( m.WorkflowStep( - name="parallel-step-2-model-workflow-step", + name="model-workflow-step", template="whalesay", - arguments=m.Arguments(parameters=[Parameter(name="message", value="hello-model2b")]), + arguments=m.Arguments(parameters=[Parameter(name="message", value="hello-model1")]), ) ) - # Fully falling back to add a model Template containing a model WorkflowStep - w.templates.append( - m.Template( - name="my-model-template", - steps=[ - [ + with s.parallel() as ps: + # Add a step to ps implicitly through init + Step( + name="parallel-step-1", + template="whalesay", + arguments=[Parameter(name="message", value="hello2a")], + ) + + # Manually add a model WorkflowStep to ps + ps.sub_steps.append( m.WorkflowStep( - name="model-template-workflow-step", + name="parallel-step-2-model-workflow-step", template="whalesay", - arguments=m.Arguments(parameters=[Parameter(name="message", value="hello-model-template")]), + arguments=m.Arguments(parameters=[Parameter(name="message", value="hello-model2b")]), ) - ] - ], + ) + + # Fully falling back to add a model Template containing a model WorkflowStep + w.templates.append( + m.Template( + name="my-model-template", + steps=[ + [ + m.WorkflowStep( + name="model-template-workflow-step", + template="whalesay", + arguments=m.Arguments(parameters=[Parameter(name="message", value="hello-model-template")]), + ) + ] + ], + ) ) - ) -``` - -## YAML - -```yaml -apiVersion: argoproj.io/v1alpha1 -kind: Workflow -metadata: - generateName: steps- -spec: - entrypoint: hello-hello-hello - templates: - - container: - args: - - '{{inputs.parameters.message}}' - command: - - cowsay - image: docker/whalesay - inputs: - parameters: - - name: message - name: whalesay - - name: hello-hello-hello - steps: - - - arguments: - parameters: - - name: message - value: hello1 - name: manually-adding-my-step - template: whalesay - - - arguments: - parameters: - - name: message - value: hello1 - name: list-of-step-1 - template: whalesay - - - arguments: + ``` + +=== "YAML" + + ```yaml linenums="1" + apiVersion: argoproj.io/v1alpha1 + kind: Workflow + metadata: + generateName: steps- + spec: + entrypoint: hello-hello-hello + templates: + - container: + args: + - '{{inputs.parameters.message}}' + command: + - cowsay + image: docker/whalesay + inputs: parameters: - name: message - value: hello1 - name: list-of-step-2 - template: whalesay - - - arguments: - parameters: - - name: message - value: hello1 - name: list-of-step-1 - template: whalesay - - arguments: - parameters: - - name: message - value: hello1 - name: list-of-step-2 - template: whalesay - - - arguments: - parameters: - - name: message - value: hello1 - name: implicitly-adding-step-on-init - template: whalesay - - - arguments: - parameters: - - name: message - value: hello-model1 - name: model-workflow-step - template: whalesay - - - arguments: - parameters: - - name: message - value: hello2a - name: parallel-step-1 - template: whalesay - - arguments: - parameters: - - name: message - value: hello-model2b - name: parallel-step-2-model-workflow-step - template: whalesay - - name: my-model-template - steps: - - - arguments: - parameters: - - name: message - value: hello-model-template - name: model-template-workflow-step - template: whalesay -``` + name: whalesay + - name: hello-hello-hello + steps: + - - arguments: + parameters: + - name: message + value: hello1 + name: manually-adding-my-step + template: whalesay + - - arguments: + parameters: + - name: message + value: hello1 + name: list-of-step-1 + template: whalesay + - - arguments: + parameters: + - name: message + value: hello1 + name: list-of-step-2 + template: whalesay + - - arguments: + parameters: + - name: message + value: hello1 + name: list-of-step-1 + template: whalesay + - arguments: + parameters: + - name: message + value: hello1 + name: list-of-step-2 + template: whalesay + - - arguments: + parameters: + - name: message + value: hello1 + name: implicitly-adding-step-on-init + template: whalesay + - - arguments: + parameters: + - name: message + value: hello-model1 + name: model-workflow-step + template: whalesay + - - arguments: + parameters: + - name: message + value: hello2a + name: parallel-step-1 + template: whalesay + - arguments: + parameters: + - name: message + value: hello-model2b + name: parallel-step-2-model-workflow-step + template: whalesay + - name: my-model-template + steps: + - - arguments: + parameters: + - name: message + value: hello-model-template + name: model-template-workflow-step + template: whalesay + ``` + diff --git a/docs/examples/workflows/steps_with_callable_container.md b/docs/examples/workflows/steps_with_callable_container.md index f2f80d50c..373c6bf21 100644 --- a/docs/examples/workflows/steps_with_callable_container.md +++ b/docs/examples/workflows/steps_with_callable_container.md @@ -4,78 +4,80 @@ -## Hera -```python -from hera.workflows import Container, Parameter, Steps, Workflow +=== "Hera" -with Workflow( - generate_name="steps-", - entrypoint="hello-hello-hello", -) as w: - whalesay = Container( - name="whalesay", - inputs=[Parameter(name="message")], - image="docker/whalesay", - command=["cowsay"], - args=["{{inputs.parameters.message}}"], - ) + ```python linenums="1" + from hera.workflows import Container, Parameter, Steps, Workflow - with Steps(name="hello-hello-hello") as s: - whalesay( - name="hello1", - arguments=[Parameter(name="message", value="hello1")], + with Workflow( + generate_name="steps-", + entrypoint="hello-hello-hello", + ) as w: + whalesay = Container( + name="whalesay", + inputs=[Parameter(name="message")], + image="docker/whalesay", + command=["cowsay"], + args=["{{inputs.parameters.message}}"], ) - with s.parallel(): + with Steps(name="hello-hello-hello") as s: whalesay( - name="hello2a", - arguments=[Parameter(name="message", value="hello2a")], + name="hello1", + arguments=[Parameter(name="message", value="hello1")], ) - whalesay( - name="hello2b", - arguments=[Parameter(name="message", value="hello2b")], - ) -``` -## YAML + with s.parallel(): + whalesay( + name="hello2a", + arguments=[Parameter(name="message", value="hello2a")], + ) + whalesay( + name="hello2b", + arguments=[Parameter(name="message", value="hello2b")], + ) + ``` -```yaml -apiVersion: argoproj.io/v1alpha1 -kind: Workflow -metadata: - generateName: steps- -spec: - entrypoint: hello-hello-hello - templates: - - container: - args: - - '{{inputs.parameters.message}}' - command: - - cowsay - image: docker/whalesay - inputs: - parameters: - - name: message - name: whalesay - - name: hello-hello-hello - steps: - - - arguments: - parameters: - - name: message - value: hello1 - name: hello1 - template: whalesay - - - arguments: - parameters: - - name: message - value: hello2a - name: hello2a - template: whalesay - - arguments: +=== "YAML" + + ```yaml linenums="1" + apiVersion: argoproj.io/v1alpha1 + kind: Workflow + metadata: + generateName: steps- + spec: + entrypoint: hello-hello-hello + templates: + - container: + args: + - '{{inputs.parameters.message}}' + command: + - cowsay + image: docker/whalesay + inputs: parameters: - name: message - value: hello2b - name: hello2b - template: whalesay -``` + name: whalesay + - name: hello-hello-hello + steps: + - - arguments: + parameters: + - name: message + value: hello1 + name: hello1 + template: whalesay + - - arguments: + parameters: + - name: message + value: hello2a + name: hello2a + template: whalesay + - arguments: + parameters: + - name: message + value: hello2b + name: hello2b + template: whalesay + ``` + diff --git a/docs/examples/workflows/suspend.md b/docs/examples/workflows/suspend.md index 82913bec3..e7bb7b873 100644 --- a/docs/examples/workflows/suspend.md +++ b/docs/examples/workflows/suspend.md @@ -4,60 +4,62 @@ -## Hera - -```python -from hera.workflows import Parameter, Suspend, Workflow - -with Workflow(generate_name="suspend-") as w: - Suspend(name="suspend-without-duration") - Suspend(name="suspend-with-duration", duration=30) - Suspend( - name="suspend-with-intermediate-param-enum", - intermediate_parameters=[Parameter(name="approve", enum=["YES", "NO"], default="NO")], - ) - Suspend( - name="suspend-with-intermediate-param", - intermediate_parameters=[Parameter(name="approve")], - ) -``` - -## YAML - -```yaml -apiVersion: argoproj.io/v1alpha1 -kind: Workflow -metadata: - generateName: suspend- -spec: - templates: - - name: suspend-without-duration - suspend: {} - - name: suspend-with-duration - suspend: - duration: '30' - - inputs: - parameters: - - default: 'NO' - enum: - - 'YES' - - 'NO' - name: approve - name: suspend-with-intermediate-param-enum - outputs: - parameters: - - name: approve - valueFrom: - supplied: {} - suspend: {} - - inputs: - parameters: - - name: approve - name: suspend-with-intermediate-param - outputs: - parameters: - - name: approve - valueFrom: - supplied: {} - suspend: {} -``` + +=== "Hera" + + ```python linenums="1" + from hera.workflows import Parameter, Suspend, Workflow + + with Workflow(generate_name="suspend-") as w: + Suspend(name="suspend-without-duration") + Suspend(name="suspend-with-duration", duration=30) + Suspend( + name="suspend-with-intermediate-param-enum", + intermediate_parameters=[Parameter(name="approve", enum=["YES", "NO"], default="NO")], + ) + Suspend( + name="suspend-with-intermediate-param", + intermediate_parameters=[Parameter(name="approve")], + ) + ``` + +=== "YAML" + + ```yaml linenums="1" + apiVersion: argoproj.io/v1alpha1 + kind: Workflow + metadata: + generateName: suspend- + spec: + templates: + - name: suspend-without-duration + suspend: {} + - name: suspend-with-duration + suspend: + duration: '30' + - inputs: + parameters: + - default: 'NO' + enum: + - 'YES' + - 'NO' + name: approve + name: suspend-with-intermediate-param-enum + outputs: + parameters: + - name: approve + valueFrom: + supplied: {} + suspend: {} + - inputs: + parameters: + - name: approve + name: suspend-with-intermediate-param + outputs: + parameters: + - name: approve + valueFrom: + supplied: {} + suspend: {} + ``` + diff --git a/docs/examples/workflows/upstream/arguments_artifacts.md b/docs/examples/workflows/upstream/arguments_artifacts.md index d1ee3936c..213710de5 100644 --- a/docs/examples/workflows/upstream/arguments_artifacts.md +++ b/docs/examples/workflows/upstream/arguments_artifacts.md @@ -4,56 +4,58 @@ -## Hera - -```python -from hera.workflows import Artifact, Container, HTTPArtifact, Workflow - -with Workflow( - generate_name="arguments-artifacts-", - entrypoint="kubectl-input-artifact", - arguments=[ - HTTPArtifact( - name="kubectl", - url="https://storage.googleapis.com/kubernetes-release/release/v1.8.0/bin/linux/amd64/kubectl", - ), - ], -) as w: - Container( - name="kubectl-input-artifact", - image="debian:9.4", - command=["sh", "-c"], - args=["kubectl version"], - inputs=[Artifact(name="kubectl", path="/usr/local/bin/kubectl", mode=493)], - ) -``` - -## YAML - -```yaml -apiVersion: argoproj.io/v1alpha1 -kind: Workflow -metadata: - generateName: arguments-artifacts- -spec: - arguments: - artifacts: - - http: - url: https://storage.googleapis.com/kubernetes-release/release/v1.8.0/bin/linux/amd64/kubectl - name: kubectl - entrypoint: kubectl-input-artifact - templates: - - container: - args: - - kubectl version - command: - - sh - - -c - image: debian:9.4 - inputs: - artifacts: - - mode: 493 - name: kubectl - path: /usr/local/bin/kubectl - name: kubectl-input-artifact -``` + +=== "Hera" + + ```python linenums="1" + from hera.workflows import Artifact, Container, HTTPArtifact, Workflow + + with Workflow( + generate_name="arguments-artifacts-", + entrypoint="kubectl-input-artifact", + arguments=[ + HTTPArtifact( + name="kubectl", + url="https://storage.googleapis.com/kubernetes-release/release/v1.8.0/bin/linux/amd64/kubectl", + ), + ], + ) as w: + Container( + name="kubectl-input-artifact", + image="debian:9.4", + command=["sh", "-c"], + args=["kubectl version"], + inputs=[Artifact(name="kubectl", path="/usr/local/bin/kubectl", mode=493)], + ) + ``` + +=== "YAML" + + ```yaml linenums="1" + apiVersion: argoproj.io/v1alpha1 + kind: Workflow + metadata: + generateName: arguments-artifacts- + spec: + arguments: + artifacts: + - http: + url: https://storage.googleapis.com/kubernetes-release/release/v1.8.0/bin/linux/amd64/kubectl + name: kubectl + entrypoint: kubectl-input-artifact + templates: + - container: + args: + - kubectl version + command: + - sh + - -c + image: debian:9.4 + inputs: + artifacts: + - mode: 493 + name: kubectl + path: /usr/local/bin/kubectl + name: kubectl-input-artifact + ``` + diff --git a/docs/examples/workflows/upstream/artifact_disable_archive.md b/docs/examples/workflows/upstream/artifact_disable_archive.md index a4b352c18..68da75ef5 100644 --- a/docs/examples/workflows/upstream/artifact_disable_archive.md +++ b/docs/examples/workflows/upstream/artifact_disable_archive.md @@ -4,121 +4,123 @@ -## Hera -```python -from hera.workflows import ( - Artifact, - Container, - NoneArchiveStrategy, - Step, - Steps, - TarArchiveStrategy, - Workflow, -) +=== "Hera" -with Workflow(generate_name="artifact-disable-archive-", entrypoint="artifact-disable-archive") as w: - whalesay = Container( - name="whalesay", - image="docker/whalesay:latest", - command=["sh", "-c"], - args=["cowsay hello world | tee /tmp/hello_world.txt | tee /tmp/hello_world_nc.txt ; sleep 1"], - outputs=[ - Artifact(name="etc", path="/etc", archive=NoneArchiveStrategy()), - Artifact(name="hello-txt", path="/tmp/hello_world.txt", archive=NoneArchiveStrategy()), - Artifact( - name="hello-txt-nc", - path="/tmp/hello_world_nc.txt", - archive=TarArchiveStrategy(compression_level=0), - ), - ], + ```python linenums="1" + from hera.workflows import ( + Artifact, + Container, + NoneArchiveStrategy, + Step, + Steps, + TarArchiveStrategy, + Workflow, ) - print_message = Container( - name="print-message", - image="alpine:latest", - command=["sh", "-c"], - args=["cat /tmp/hello.txt && cat /tmp/hello_nc.txt && cd /tmp/etc && find ."], - inputs=[ - Artifact(name="etc", path="/tmp/etc"), - Artifact(name="hello-txt", path="/tmp/hello.txt"), - Artifact(name="hello-txt-nc", path="/tmp/hello_nc.txt"), - ], - ) - with Steps(name="artifact-disable-archive") as s: - Step(name="generate-artifact", template=whalesay) - Step( - name="consume-artifact", - template=print_message, - arguments=[ - Artifact(name="etc", from_="{{steps.generate-artifact.outputs.artifacts.etc}}"), - Artifact(name="hello-txt", from_="{{steps.generate-artifact.outputs.artifacts.hello-txt}}"), - Artifact(name="hello-txt-nc", from_="{{steps.generate-artifact.outputs.artifacts.hello-txt-nc}}"), + + with Workflow(generate_name="artifact-disable-archive-", entrypoint="artifact-disable-archive") as w: + whalesay = Container( + name="whalesay", + image="docker/whalesay:latest", + command=["sh", "-c"], + args=["cowsay hello world | tee /tmp/hello_world.txt | tee /tmp/hello_world_nc.txt ; sleep 1"], + outputs=[ + Artifact(name="etc", path="/etc", archive=NoneArchiveStrategy()), + Artifact(name="hello-txt", path="/tmp/hello_world.txt", archive=NoneArchiveStrategy()), + Artifact( + name="hello-txt-nc", + path="/tmp/hello_world_nc.txt", + archive=TarArchiveStrategy(compression_level=0), + ), + ], + ) + print_message = Container( + name="print-message", + image="alpine:latest", + command=["sh", "-c"], + args=["cat /tmp/hello.txt && cat /tmp/hello_nc.txt && cd /tmp/etc && find ."], + inputs=[ + Artifact(name="etc", path="/tmp/etc"), + Artifact(name="hello-txt", path="/tmp/hello.txt"), + Artifact(name="hello-txt-nc", path="/tmp/hello_nc.txt"), ], ) -``` + with Steps(name="artifact-disable-archive") as s: + Step(name="generate-artifact", template=whalesay) + Step( + name="consume-artifact", + template=print_message, + arguments=[ + Artifact(name="etc", from_="{{steps.generate-artifact.outputs.artifacts.etc}}"), + Artifact(name="hello-txt", from_="{{steps.generate-artifact.outputs.artifacts.hello-txt}}"), + Artifact(name="hello-txt-nc", from_="{{steps.generate-artifact.outputs.artifacts.hello-txt-nc}}"), + ], + ) + ``` -## YAML +=== "YAML" -```yaml -apiVersion: argoproj.io/v1alpha1 -kind: Workflow -metadata: - generateName: artifact-disable-archive- -spec: - entrypoint: artifact-disable-archive - templates: - - container: - args: - - cowsay hello world | tee /tmp/hello_world.txt | tee /tmp/hello_world_nc.txt - ; sleep 1 - command: - - sh - - -c - image: docker/whalesay:latest - name: whalesay - outputs: - artifacts: - - archive: - none: {} - name: etc - path: /etc - - archive: - none: {} - name: hello-txt - path: /tmp/hello_world.txt - - archive: - tar: - compressionLevel: 0 - name: hello-txt-nc - path: /tmp/hello_world_nc.txt - - container: - args: - - cat /tmp/hello.txt && cat /tmp/hello_nc.txt && cd /tmp/etc && find . - command: - - sh - - -c - image: alpine:latest - inputs: - artifacts: - - name: etc - path: /tmp/etc - - name: hello-txt - path: /tmp/hello.txt - - name: hello-txt-nc - path: /tmp/hello_nc.txt - name: print-message - - name: artifact-disable-archive - steps: - - - name: generate-artifact - template: whalesay - - - arguments: + ```yaml linenums="1" + apiVersion: argoproj.io/v1alpha1 + kind: Workflow + metadata: + generateName: artifact-disable-archive- + spec: + entrypoint: artifact-disable-archive + templates: + - container: + args: + - cowsay hello world | tee /tmp/hello_world.txt | tee /tmp/hello_world_nc.txt + ; sleep 1 + command: + - sh + - -c + image: docker/whalesay:latest + name: whalesay + outputs: artifacts: - - from: '{{steps.generate-artifact.outputs.artifacts.etc}}' + - archive: + none: {} name: etc - - from: '{{steps.generate-artifact.outputs.artifacts.hello-txt}}' + path: /etc + - archive: + none: {} name: hello-txt - - from: '{{steps.generate-artifact.outputs.artifacts.hello-txt-nc}}' + path: /tmp/hello_world.txt + - archive: + tar: + compressionLevel: 0 name: hello-txt-nc - name: consume-artifact - template: print-message -``` + path: /tmp/hello_world_nc.txt + - container: + args: + - cat /tmp/hello.txt && cat /tmp/hello_nc.txt && cd /tmp/etc && find . + command: + - sh + - -c + image: alpine:latest + inputs: + artifacts: + - name: etc + path: /tmp/etc + - name: hello-txt + path: /tmp/hello.txt + - name: hello-txt-nc + path: /tmp/hello_nc.txt + name: print-message + - name: artifact-disable-archive + steps: + - - name: generate-artifact + template: whalesay + - - arguments: + artifacts: + - from: '{{steps.generate-artifact.outputs.artifacts.etc}}' + name: etc + - from: '{{steps.generate-artifact.outputs.artifacts.hello-txt}}' + name: hello-txt + - from: '{{steps.generate-artifact.outputs.artifacts.hello-txt-nc}}' + name: hello-txt-nc + name: consume-artifact + template: print-message + ``` + diff --git a/docs/examples/workflows/upstream/artifact_gc_workflow.md b/docs/examples/workflows/upstream/artifact_gc_workflow.md index e9aaa35d4..e08692c37 100644 --- a/docs/examples/workflows/upstream/artifact_gc_workflow.md +++ b/docs/examples/workflows/upstream/artifact_gc_workflow.md @@ -4,74 +4,76 @@ -## Hera -```python -from hera.workflows import ( - Container, - S3Artifact, - Workflow, - models as m, -) +=== "Hera" -with Workflow( - generate_name="artifact-gc-", entrypoint="main", artifact_gc=m.ArtifactGC(strategy="OnWorkflowDeletion") -) as w: - main = Container( - name="main", - image="argoproj/argosay:v2", - command=["sh", "-c"], - args=['echo "hello world" > /tmp/on-completion.txt\necho "hello world" > /tmp/on-deletion.txt\n'], - outputs=[ - S3Artifact( - name="on-completion", - path="/tmp/on-completion.txt", - key="on-completion.txt", - artifact_gc=m.ArtifactGC(strategy="OnWorkflowCompletion"), - ), - S3Artifact( - name="on-deletion", - path="/tmp/on-deletion.txt", - key="on-deletion.txt", - ), - ], + ```python linenums="1" + from hera.workflows import ( + Container, + S3Artifact, + Workflow, + models as m, ) -``` -## YAML + with Workflow( + generate_name="artifact-gc-", entrypoint="main", artifact_gc=m.ArtifactGC(strategy="OnWorkflowDeletion") + ) as w: + main = Container( + name="main", + image="argoproj/argosay:v2", + command=["sh", "-c"], + args=['echo "hello world" > /tmp/on-completion.txt\necho "hello world" > /tmp/on-deletion.txt\n'], + outputs=[ + S3Artifact( + name="on-completion", + path="/tmp/on-completion.txt", + key="on-completion.txt", + artifact_gc=m.ArtifactGC(strategy="OnWorkflowCompletion"), + ), + S3Artifact( + name="on-deletion", + path="/tmp/on-deletion.txt", + key="on-deletion.txt", + ), + ], + ) + ``` -```yaml -apiVersion: argoproj.io/v1alpha1 -kind: Workflow -metadata: - generateName: artifact-gc- -spec: - artifactGC: - strategy: OnWorkflowDeletion - entrypoint: main - templates: - - container: - args: - - 'echo "hello world" > /tmp/on-completion.txt +=== "YAML" - echo "hello world" > /tmp/on-deletion.txt + ```yaml linenums="1" + apiVersion: argoproj.io/v1alpha1 + kind: Workflow + metadata: + generateName: artifact-gc- + spec: + artifactGC: + strategy: OnWorkflowDeletion + entrypoint: main + templates: + - container: + args: + - 'echo "hello world" > /tmp/on-completion.txt + + echo "hello world" > /tmp/on-deletion.txt + + ' + command: + - sh + - -c + image: argoproj/argosay:v2 + name: main + outputs: + artifacts: + - artifactGC: + strategy: OnWorkflowCompletion + name: on-completion + path: /tmp/on-completion.txt + s3: + key: on-completion.txt + - name: on-deletion + path: /tmp/on-deletion.txt + s3: + key: on-deletion.txt + ``` - ' - command: - - sh - - -c - image: argoproj/argosay:v2 - name: main - outputs: - artifacts: - - artifactGC: - strategy: OnWorkflowCompletion - name: on-completion - path: /tmp/on-completion.txt - s3: - key: on-completion.txt - - name: on-deletion - path: /tmp/on-deletion.txt - s3: - key: on-deletion.txt -``` diff --git a/docs/examples/workflows/upstream/artifact_passing.md b/docs/examples/workflows/upstream/artifact_passing.md index 2afc4dc9e..2013b977a 100644 --- a/docs/examples/workflows/upstream/artifact_passing.md +++ b/docs/examples/workflows/upstream/artifact_passing.md @@ -4,78 +4,80 @@ -## Hera -```python -from hera.workflows import Artifact, Container, Step, Steps, Workflow +=== "Hera" -with Workflow(generate_name="artifact-passing-", entrypoint="artifact-example") as w: - whalesay = Container( - name="whalesay", - image="docker/whalesay:latest", - command=["sh", "-c"], - args=["sleep 1; cowsay hello world | tee /tmp/hello_world.txt"], - outputs=[Artifact(name="hello-art", path="/tmp/hello_world.txt")], - ) - print_message = Container( - name="print-message", - image="alpine:latest", - command=["sh", "-c"], - args=["cat /tmp/message"], - inputs=[Artifact(name="message", path="/tmp/message")], - ) + ```python linenums="1" + from hera.workflows import Artifact, Container, Step, Steps, Workflow - with Steps(name="artifact-example") as s: - Step(name="generate-artifact", template=whalesay) - Step( - name="consume-artifact", - template=print_message, - arguments=[Artifact(name="message", from_="{{steps.generate-artifact.outputs.artifacts.hello-art}}")], + with Workflow(generate_name="artifact-passing-", entrypoint="artifact-example") as w: + whalesay = Container( + name="whalesay", + image="docker/whalesay:latest", + command=["sh", "-c"], + args=["sleep 1; cowsay hello world | tee /tmp/hello_world.txt"], + outputs=[Artifact(name="hello-art", path="/tmp/hello_world.txt")], ) -``` + print_message = Container( + name="print-message", + image="alpine:latest", + command=["sh", "-c"], + args=["cat /tmp/message"], + inputs=[Artifact(name="message", path="/tmp/message")], + ) + + with Steps(name="artifact-example") as s: + Step(name="generate-artifact", template=whalesay) + Step( + name="consume-artifact", + template=print_message, + arguments=[Artifact(name="message", from_="{{steps.generate-artifact.outputs.artifacts.hello-art}}")], + ) + ``` -## YAML +=== "YAML" -```yaml -apiVersion: argoproj.io/v1alpha1 -kind: Workflow -metadata: - generateName: artifact-passing- -spec: - entrypoint: artifact-example - templates: - - container: - args: - - sleep 1; cowsay hello world | tee /tmp/hello_world.txt - command: - - sh - - -c - image: docker/whalesay:latest - name: whalesay - outputs: - artifacts: - - name: hello-art - path: /tmp/hello_world.txt - - container: - args: - - cat /tmp/message - command: - - sh - - -c - image: alpine:latest - inputs: - artifacts: - - name: message - path: /tmp/message - name: print-message - - name: artifact-example - steps: - - - name: generate-artifact - template: whalesay - - - arguments: + ```yaml linenums="1" + apiVersion: argoproj.io/v1alpha1 + kind: Workflow + metadata: + generateName: artifact-passing- + spec: + entrypoint: artifact-example + templates: + - container: + args: + - sleep 1; cowsay hello world | tee /tmp/hello_world.txt + command: + - sh + - -c + image: docker/whalesay:latest + name: whalesay + outputs: artifacts: - - from: '{{steps.generate-artifact.outputs.artifacts.hello-art}}' - name: message - name: consume-artifact - template: print-message -``` + - name: hello-art + path: /tmp/hello_world.txt + - container: + args: + - cat /tmp/message + command: + - sh + - -c + image: alpine:latest + inputs: + artifacts: + - name: message + path: /tmp/message + name: print-message + - name: artifact-example + steps: + - - name: generate-artifact + template: whalesay + - - arguments: + artifacts: + - from: '{{steps.generate-artifact.outputs.artifacts.hello-art}}' + name: message + name: consume-artifact + template: print-message + ``` + diff --git a/docs/examples/workflows/upstream/artifact_passing_subpath.md b/docs/examples/workflows/upstream/artifact_passing_subpath.md index 0b9546b4c..70902e7ac 100644 --- a/docs/examples/workflows/upstream/artifact_passing_subpath.md +++ b/docs/examples/workflows/upstream/artifact_passing_subpath.md @@ -4,123 +4,125 @@ -## Hera -```python -from hera.workflows import ( - Artifact, - Container, - NoneArchiveStrategy, - Step, - Steps, - Workflow, -) +=== "Hera" -with Workflow(generate_name="artifact-passing-subpath-", entrypoint="artifact-example") as w: - whalesay = Container( - name="whalesay", - image="docker/whalesay:latest", - command=["sh", "-c"], - args=["sleep 1; cowsay hello world | tee /tmp/hello_world.txt"], - outputs=[Artifact(name="hello-art", path="/tmp/", archive=NoneArchiveStrategy())], + ```python linenums="1" + from hera.workflows import ( + Artifact, + Container, + NoneArchiveStrategy, + Step, + Steps, + Workflow, ) - print_message_dir = Container( - name="print-message-dir", - image="alpine:latest", - command=["sh", "-c"], - args=["ls /tmp/message"], - inputs=[Artifact(name="message", path="/tmp/message")], - ) - print_message = Container( - name="print-message", - image="alpine:latest", - command=["sh", "-c"], - args=["cat /tmp/message"], - inputs=[Artifact(name="message", path="/tmp/message")], - ) - with Steps(name="artifact-example") as s: - Step(name="generate-artifact", template=whalesay) - Step( - name="list-artifact", - template=print_message_dir, - arguments=[Artifact(name="message", from_="{{steps.generate-artifact.outputs.artifacts.hello-art}}")], + + with Workflow(generate_name="artifact-passing-subpath-", entrypoint="artifact-example") as w: + whalesay = Container( + name="whalesay", + image="docker/whalesay:latest", + command=["sh", "-c"], + args=["sleep 1; cowsay hello world | tee /tmp/hello_world.txt"], + outputs=[Artifact(name="hello-art", path="/tmp/", archive=NoneArchiveStrategy())], ) - Step( - name="consume-artifact", - template=print_message, - arguments=[ - Artifact( - name="message", - from_="{{steps.generate-artifact.outputs.artifacts.hello-art}}", - sub_path="hello_world.txt", - ) - ], + print_message_dir = Container( + name="print-message-dir", + image="alpine:latest", + command=["sh", "-c"], + args=["ls /tmp/message"], + inputs=[Artifact(name="message", path="/tmp/message")], ) -``` + print_message = Container( + name="print-message", + image="alpine:latest", + command=["sh", "-c"], + args=["cat /tmp/message"], + inputs=[Artifact(name="message", path="/tmp/message")], + ) + with Steps(name="artifact-example") as s: + Step(name="generate-artifact", template=whalesay) + Step( + name="list-artifact", + template=print_message_dir, + arguments=[Artifact(name="message", from_="{{steps.generate-artifact.outputs.artifacts.hello-art}}")], + ) + Step( + name="consume-artifact", + template=print_message, + arguments=[ + Artifact( + name="message", + from_="{{steps.generate-artifact.outputs.artifacts.hello-art}}", + sub_path="hello_world.txt", + ) + ], + ) + ``` -## YAML +=== "YAML" -```yaml -apiVersion: argoproj.io/v1alpha1 -kind: Workflow -metadata: - generateName: artifact-passing-subpath- -spec: - entrypoint: artifact-example - templates: - - container: - args: - - sleep 1; cowsay hello world | tee /tmp/hello_world.txt - command: - - sh - - -c - image: docker/whalesay:latest - name: whalesay - outputs: - artifacts: - - archive: - none: {} - name: hello-art - path: /tmp/ - - container: - args: - - ls /tmp/message - command: - - sh - - -c - image: alpine:latest - inputs: - artifacts: - - name: message - path: /tmp/message - name: print-message-dir - - container: - args: - - cat /tmp/message - command: - - sh - - -c - image: alpine:latest - inputs: - artifacts: - - name: message - path: /tmp/message - name: print-message - - name: artifact-example - steps: - - - name: generate-artifact - template: whalesay - - - arguments: + ```yaml linenums="1" + apiVersion: argoproj.io/v1alpha1 + kind: Workflow + metadata: + generateName: artifact-passing-subpath- + spec: + entrypoint: artifact-example + templates: + - container: + args: + - sleep 1; cowsay hello world | tee /tmp/hello_world.txt + command: + - sh + - -c + image: docker/whalesay:latest + name: whalesay + outputs: + artifacts: + - archive: + none: {} + name: hello-art + path: /tmp/ + - container: + args: + - ls /tmp/message + command: + - sh + - -c + image: alpine:latest + inputs: artifacts: - - from: '{{steps.generate-artifact.outputs.artifacts.hello-art}}' - name: message - name: list-artifact - template: print-message-dir - - - arguments: + - name: message + path: /tmp/message + name: print-message-dir + - container: + args: + - cat /tmp/message + command: + - sh + - -c + image: alpine:latest + inputs: artifacts: - - from: '{{steps.generate-artifact.outputs.artifacts.hello-art}}' - name: message - subPath: hello_world.txt - name: consume-artifact - template: print-message -``` + - name: message + path: /tmp/message + name: print-message + - name: artifact-example + steps: + - - name: generate-artifact + template: whalesay + - - arguments: + artifacts: + - from: '{{steps.generate-artifact.outputs.artifacts.hello-art}}' + name: message + name: list-artifact + template: print-message-dir + - - arguments: + artifacts: + - from: '{{steps.generate-artifact.outputs.artifacts.hello-art}}' + name: message + subPath: hello_world.txt + name: consume-artifact + template: print-message + ``` + diff --git a/docs/examples/workflows/upstream/artifact_path_placeholders.md b/docs/examples/workflows/upstream/artifact_path_placeholders.md index e53e7c528..011f2843e 100644 --- a/docs/examples/workflows/upstream/artifact_path_placeholders.md +++ b/docs/examples/workflows/upstream/artifact_path_placeholders.md @@ -4,91 +4,93 @@ -## Hera -```python -from hera.workflows import ( - Artifact, - Container, - Parameter, - RawArtifact, - Workflow, - models as m, -) +=== "Hera" -with Workflow( - generate_name="artifact-path-placeholders-", - entrypoint="head-lines", - arguments=[Parameter(name="lines-count", value=3), RawArtifact(name="text", data="1\n2\n3\n4\n5\n")], -) as w: - Container( - name="head-lines", - image="busybox", - command=[ - "sh", - "-c", - 'mkdir -p "$(dirname "{{outputs.artifacts.text.path}}")" "$(dirname "{{outputs.parameters.actual-lines-count.path}}")" ; head -n {{inputs.parameters.lines-count}} < "{{inputs.artifacts.text.path}}" | tee "{{outputs.artifacts.text.path}}" | wc -l > "{{outputs.parameters.actual-lines-count.path}}"', - ], - inputs=[ - Parameter(name="lines-count"), - Artifact(name="text", path="/inputs/text/data"), - ], - outputs=[ - Parameter(name="actual-lines-count", value_from=m.ValueFrom(path="/outputs/actual-lines-count/data")), - Artifact(name="text", path="/outputs/text/data"), - ], + ```python linenums="1" + from hera.workflows import ( + Artifact, + Container, + Parameter, + RawArtifact, + Workflow, + models as m, ) -``` -## YAML + with Workflow( + generate_name="artifact-path-placeholders-", + entrypoint="head-lines", + arguments=[Parameter(name="lines-count", value=3), RawArtifact(name="text", data="1\n2\n3\n4\n5\n")], + ) as w: + Container( + name="head-lines", + image="busybox", + command=[ + "sh", + "-c", + 'mkdir -p "$(dirname "{{outputs.artifacts.text.path}}")" "$(dirname "{{outputs.parameters.actual-lines-count.path}}")" ; head -n {{inputs.parameters.lines-count}} < "{{inputs.artifacts.text.path}}" | tee "{{outputs.artifacts.text.path}}" | wc -l > "{{outputs.parameters.actual-lines-count.path}}"', + ], + inputs=[ + Parameter(name="lines-count"), + Artifact(name="text", path="/inputs/text/data"), + ], + outputs=[ + Parameter(name="actual-lines-count", value_from=m.ValueFrom(path="/outputs/actual-lines-count/data")), + Artifact(name="text", path="/outputs/text/data"), + ], + ) + ``` -```yaml -apiVersion: argoproj.io/v1alpha1 -kind: Workflow -metadata: - generateName: artifact-path-placeholders- -spec: - arguments: - artifacts: - - name: text - raw: - data: '1 +=== "YAML" - 2 + ```yaml linenums="1" + apiVersion: argoproj.io/v1alpha1 + kind: Workflow + metadata: + generateName: artifact-path-placeholders- + spec: + arguments: + artifacts: + - name: text + raw: + data: '1 - 3 + 2 - 4 + 3 - 5 + 4 + + 5 + + ' + parameters: + - name: lines-count + value: '3' + entrypoint: head-lines + templates: + - container: + command: + - sh + - -c + - mkdir -p "$(dirname "{{outputs.artifacts.text.path}}")" "$(dirname "{{outputs.parameters.actual-lines-count.path}}")" + ; head -n {{inputs.parameters.lines-count}} < "{{inputs.artifacts.text.path}}" + | tee "{{outputs.artifacts.text.path}}" | wc -l > "{{outputs.parameters.actual-lines-count.path}}" + image: busybox + inputs: + artifacts: + - name: text + path: /inputs/text/data + parameters: + - name: lines-count + name: head-lines + outputs: + artifacts: + - name: text + path: /outputs/text/data + parameters: + - name: actual-lines-count + valueFrom: + path: /outputs/actual-lines-count/data + ``` - ' - parameters: - - name: lines-count - value: '3' - entrypoint: head-lines - templates: - - container: - command: - - sh - - -c - - mkdir -p "$(dirname "{{outputs.artifacts.text.path}}")" "$(dirname "{{outputs.parameters.actual-lines-count.path}}")" - ; head -n {{inputs.parameters.lines-count}} < "{{inputs.artifacts.text.path}}" - | tee "{{outputs.artifacts.text.path}}" | wc -l > "{{outputs.parameters.actual-lines-count.path}}" - image: busybox - inputs: - artifacts: - - name: text - path: /inputs/text/data - parameters: - - name: lines-count - name: head-lines - outputs: - artifacts: - - name: text - path: /outputs/text/data - parameters: - - name: actual-lines-count - valueFrom: - path: /outputs/actual-lines-count/data -``` diff --git a/docs/examples/workflows/upstream/artifact_repository_ref.md b/docs/examples/workflows/upstream/artifact_repository_ref.md index a41ad3c1e..ebe22ca5d 100644 --- a/docs/examples/workflows/upstream/artifact_repository_ref.md +++ b/docs/examples/workflows/upstream/artifact_repository_ref.md @@ -4,52 +4,54 @@ -## Hera - -```python -from hera.workflows import ( - Artifact, - Container, - Workflow, - models as m, -) - -with Workflow( - generate_name="artifactory-repository-ref-", - entrypoint="main", - artifact_repository_ref=m.ArtifactRepositoryRef(key="my-key"), -) as w: - Container( - name="main", - image="docker/whalesay:latest", - command=["sh", "-c"], - args=["cowsay hello world | tee /tmp/hello_world.txt"], - outputs=[Artifact(name="hello_world", path="/tmp/hello_world.txt")], + +=== "Hera" + + ```python linenums="1" + from hera.workflows import ( + Artifact, + Container, + Workflow, + models as m, ) -``` - -## YAML - -```yaml -apiVersion: argoproj.io/v1alpha1 -kind: Workflow -metadata: - generateName: artifactory-repository-ref- -spec: - artifactRepositoryRef: - key: my-key - entrypoint: main - templates: - - container: - args: - - cowsay hello world | tee /tmp/hello_world.txt - command: - - sh - - -c - image: docker/whalesay:latest - name: main - outputs: - artifacts: - - name: hello_world - path: /tmp/hello_world.txt -``` + + with Workflow( + generate_name="artifactory-repository-ref-", + entrypoint="main", + artifact_repository_ref=m.ArtifactRepositoryRef(key="my-key"), + ) as w: + Container( + name="main", + image="docker/whalesay:latest", + command=["sh", "-c"], + args=["cowsay hello world | tee /tmp/hello_world.txt"], + outputs=[Artifact(name="hello_world", path="/tmp/hello_world.txt")], + ) + ``` + +=== "YAML" + + ```yaml linenums="1" + apiVersion: argoproj.io/v1alpha1 + kind: Workflow + metadata: + generateName: artifactory-repository-ref- + spec: + artifactRepositoryRef: + key: my-key + entrypoint: main + templates: + - container: + args: + - cowsay hello world | tee /tmp/hello_world.txt + command: + - sh + - -c + image: docker/whalesay:latest + name: main + outputs: + artifacts: + - name: hello_world + path: /tmp/hello_world.txt + ``` + diff --git a/docs/examples/workflows/upstream/artifactory_artifact.md b/docs/examples/workflows/upstream/artifactory_artifact.md index 3182264c1..898a2f212 100644 --- a/docs/examples/workflows/upstream/artifactory_artifact.md +++ b/docs/examples/workflows/upstream/artifactory_artifact.md @@ -4,118 +4,120 @@ -## Hera -```python -from hera.workflows import ( - Artifact, - ArtifactoryArtifact, - Container, - Step, - Steps, - Workflow, - models as m, -) +=== "Hera" -with Workflow(generate_name="artifactory-artifact-", entrypoint="artifact-example") as w: - whalesay = Container( - name="whalesay", - image="docker/whalesay:latest", - command=["sh", "-c"], - args=["cowsay hello world | tee /tmp/hello_world.txt"], - outputs=[ - ArtifactoryArtifact( - name="hello-art", - path="/tmp/hello_world.txt", - url="http://artifactory:8081/artifactory/generic-local/hello_world.tgz", - username_secret=m.SecretKeySelector(name="my-artifactory-credentials", key="username"), - password_secret=m.SecretKeySelector(name="my-artifactory-credentials", key="password"), - ) - ], - ) - print_message = Container( - name="print-message", - image="alpine:latest", - command=["sh", "-c"], - args=["cat /tmp/message"], - inputs=[ - ArtifactoryArtifact( - name="message", - path="/tmp/message", - url="http://artifactory:8081/artifactory/generic-local/hello_world.tgz", - username_secret=m.SecretKeySelector(name="my-artifactory-credentials", key="username"), - password_secret=m.SecretKeySelector(name="my-artifactory-credentials", key="password"), - ) - ], + ```python linenums="1" + from hera.workflows import ( + Artifact, + ArtifactoryArtifact, + Container, + Step, + Steps, + Workflow, + models as m, ) - with Steps(name="artifact-example") as s: - Step(name="generate-artifact", template=whalesay) - Step( - name="consume-artifact", - template=print_message, - arguments=[Artifact(name="message", from_="{{steps.generate-artifact.outputs.artifacts.hello-art}}")], + with Workflow(generate_name="artifactory-artifact-", entrypoint="artifact-example") as w: + whalesay = Container( + name="whalesay", + image="docker/whalesay:latest", + command=["sh", "-c"], + args=["cowsay hello world | tee /tmp/hello_world.txt"], + outputs=[ + ArtifactoryArtifact( + name="hello-art", + path="/tmp/hello_world.txt", + url="http://artifactory:8081/artifactory/generic-local/hello_world.tgz", + username_secret=m.SecretKeySelector(name="my-artifactory-credentials", key="username"), + password_secret=m.SecretKeySelector(name="my-artifactory-credentials", key="password"), + ) + ], + ) + print_message = Container( + name="print-message", + image="alpine:latest", + command=["sh", "-c"], + args=["cat /tmp/message"], + inputs=[ + ArtifactoryArtifact( + name="message", + path="/tmp/message", + url="http://artifactory:8081/artifactory/generic-local/hello_world.tgz", + username_secret=m.SecretKeySelector(name="my-artifactory-credentials", key="username"), + password_secret=m.SecretKeySelector(name="my-artifactory-credentials", key="password"), + ) + ], ) -``` -## YAML + with Steps(name="artifact-example") as s: + Step(name="generate-artifact", template=whalesay) + Step( + name="consume-artifact", + template=print_message, + arguments=[Artifact(name="message", from_="{{steps.generate-artifact.outputs.artifacts.hello-art}}")], + ) + ``` + +=== "YAML" -```yaml -apiVersion: argoproj.io/v1alpha1 -kind: Workflow -metadata: - generateName: artifactory-artifact- -spec: - entrypoint: artifact-example - templates: - - container: - args: - - cowsay hello world | tee /tmp/hello_world.txt - command: - - sh - - -c - image: docker/whalesay:latest - name: whalesay - outputs: - artifacts: - - artifactory: - passwordSecret: - key: password - name: my-artifactory-credentials - url: http://artifactory:8081/artifactory/generic-local/hello_world.tgz - usernameSecret: - key: username - name: my-artifactory-credentials - name: hello-art - path: /tmp/hello_world.txt - - container: - args: - - cat /tmp/message - command: - - sh - - -c - image: alpine:latest - inputs: - artifacts: - - artifactory: - passwordSecret: - key: password - name: my-artifactory-credentials - url: http://artifactory:8081/artifactory/generic-local/hello_world.tgz - usernameSecret: - key: username - name: my-artifactory-credentials - name: message - path: /tmp/message - name: print-message - - name: artifact-example - steps: - - - name: generate-artifact - template: whalesay - - - arguments: + ```yaml linenums="1" + apiVersion: argoproj.io/v1alpha1 + kind: Workflow + metadata: + generateName: artifactory-artifact- + spec: + entrypoint: artifact-example + templates: + - container: + args: + - cowsay hello world | tee /tmp/hello_world.txt + command: + - sh + - -c + image: docker/whalesay:latest + name: whalesay + outputs: artifacts: - - from: '{{steps.generate-artifact.outputs.artifacts.hello-art}}' + - artifactory: + passwordSecret: + key: password + name: my-artifactory-credentials + url: http://artifactory:8081/artifactory/generic-local/hello_world.tgz + usernameSecret: + key: username + name: my-artifactory-credentials + name: hello-art + path: /tmp/hello_world.txt + - container: + args: + - cat /tmp/message + command: + - sh + - -c + image: alpine:latest + inputs: + artifacts: + - artifactory: + passwordSecret: + key: password + name: my-artifactory-credentials + url: http://artifactory:8081/artifactory/generic-local/hello_world.tgz + usernameSecret: + key: username + name: my-artifactory-credentials name: message - name: consume-artifact - template: print-message -``` + path: /tmp/message + name: print-message + - name: artifact-example + steps: + - - name: generate-artifact + template: whalesay + - - arguments: + artifacts: + - from: '{{steps.generate-artifact.outputs.artifacts.hello-art}}' + name: message + name: consume-artifact + template: print-message + ``` + diff --git a/docs/examples/workflows/upstream/ci_output_artifact.md b/docs/examples/workflows/upstream/ci_output_artifact.md index 7b501d0ba..19c0355f3 100644 --- a/docs/examples/workflows/upstream/ci_output_artifact.md +++ b/docs/examples/workflows/upstream/ci_output_artifact.md @@ -4,172 +4,174 @@ -## Hera -```python -from hera.workflows import ( - Artifact, - Container, - GitArtifact, - Parameter, - Step, - Steps, - Workflow, - models as m, -) +=== "Hera" -with Workflow( - generate_name="ci-output-artifact-", - entrypoint="ci-example", - volume_claim_templates=[ - m.PersistentVolumeClaim( - metadata=m.ObjectMeta(name="workdir"), - spec=m.PersistentVolumeClaimSpec( - access_modes=["ReadWriteOnce"], - resources=m.ResourceRequirements( - requests={ - "storage": m.Quantity(__root__="1Gi"), - } - ), - ), - ) - ], -) as w: - build_golang_example = Container( - name="build-golang-example", - image="golang:1.8", - command=["sh", "-c"], - args=[" cd /go/src/github.com/golang/example/hello && go build -v . "], - volume_mounts=[ - m.VolumeMount(name="workdir", mount_path="/go"), - ], - inputs=[ - GitArtifact( - name="code", - path="/go/src/github.com/golang/example", - repo="https://github.com/golang/example.git", - revision="cfe12d6", - ), - ], + ```python linenums="1" + from hera.workflows import ( + Artifact, + Container, + GitArtifact, + Parameter, + Step, + Steps, + Workflow, + models as m, ) - run_hello = Container( - name="run-hello", - image="{{inputs.parameters.os-image}}", - command=["sh", "-c"], - args=[ - " uname -a ; cat " "/etc/os-release ; " "/go/src/github.com/golang/example/hello/hello ", - ], - volume_mounts=[ - m.VolumeMount(name="workdir", mount_path="/go"), + with Workflow( + generate_name="ci-output-artifact-", + entrypoint="ci-example", + volume_claim_templates=[ + m.PersistentVolumeClaim( + metadata=m.ObjectMeta(name="workdir"), + spec=m.PersistentVolumeClaimSpec( + access_modes=["ReadWriteOnce"], + resources=m.ResourceRequirements( + requests={ + "storage": m.Quantity(__root__="1Gi"), + } + ), + ), + ) ], - inputs=[Parameter(name="os-image")], - ) + ) as w: + build_golang_example = Container( + name="build-golang-example", + image="golang:1.8", + command=["sh", "-c"], + args=[" cd /go/src/github.com/golang/example/hello && go build -v . "], + volume_mounts=[ + m.VolumeMount(name="workdir", mount_path="/go"), + ], + inputs=[ + GitArtifact( + name="code", + path="/go/src/github.com/golang/example", + repo="https://github.com/golang/example.git", + revision="cfe12d6", + ), + ], + ) - release_artifact = Container( - name="release-artifact", - image="alpine:3.8", - volume_mounts=[ - m.VolumeMount(name="workdir", mount_path="/go"), - ], - outputs=[ - Artifact(name="release", path="/go"), - ], - ) + run_hello = Container( + name="run-hello", + image="{{inputs.parameters.os-image}}", + command=["sh", "-c"], + args=[ + " uname -a ; cat " "/etc/os-release ; " "/go/src/github.com/golang/example/hello/hello ", + ], + volume_mounts=[ + m.VolumeMount(name="workdir", mount_path="/go"), + ], + inputs=[Parameter(name="os-image")], + ) - with Steps(name="ci-example"): - Step(name="build", template=build_golang_example) - Step( - name="test", - template=run_hello, - arguments=[Parameter(name="os-image", value="{{item.image}}:{{item.tag}}")], - with_items=[ - {"image": "debian", "tag": "9.1"}, - {"image": "alpine", "tag": "3.6"}, - {"image": "ubuntu", "tag": "17.10"}, + release_artifact = Container( + name="release-artifact", + image="alpine:3.8", + volume_mounts=[ + m.VolumeMount(name="workdir", mount_path="/go"), + ], + outputs=[ + Artifact(name="release", path="/go"), ], ) - Step(name="release", template=release_artifact) -``` -## YAML + with Steps(name="ci-example"): + Step(name="build", template=build_golang_example) + Step( + name="test", + template=run_hello, + arguments=[Parameter(name="os-image", value="{{item.image}}:{{item.tag}}")], + with_items=[ + {"image": "debian", "tag": "9.1"}, + {"image": "alpine", "tag": "3.6"}, + {"image": "ubuntu", "tag": "17.10"}, + ], + ) + Step(name="release", template=release_artifact) + ``` + +=== "YAML" -```yaml -apiVersion: argoproj.io/v1alpha1 -kind: Workflow -metadata: - generateName: ci-output-artifact- -spec: - entrypoint: ci-example - templates: - - container: - args: - - ' cd /go/src/github.com/golang/example/hello && go build -v . ' - command: - - sh - - -c - image: golang:1.8 - volumeMounts: - - mountPath: /go - name: workdir - inputs: - artifacts: - - git: - repo: https://github.com/golang/example.git - revision: cfe12d6 - name: code - path: /go/src/github.com/golang/example - name: build-golang-example - - container: - args: - - ' uname -a ; cat /etc/os-release ; /go/src/github.com/golang/example/hello/hello ' - command: - - sh - - -c - image: '{{inputs.parameters.os-image}}' - volumeMounts: - - mountPath: /go - name: workdir - inputs: - parameters: - - name: os-image - name: run-hello - - container: - image: alpine:3.8 - volumeMounts: - - mountPath: /go - name: workdir - name: release-artifact - outputs: - artifacts: - - name: release - path: /go - - name: ci-example - steps: - - - name: build - template: build-golang-example - - - arguments: + ```yaml linenums="1" + apiVersion: argoproj.io/v1alpha1 + kind: Workflow + metadata: + generateName: ci-output-artifact- + spec: + entrypoint: ci-example + templates: + - container: + args: + - ' cd /go/src/github.com/golang/example/hello && go build -v . ' + command: + - sh + - -c + image: golang:1.8 + volumeMounts: + - mountPath: /go + name: workdir + inputs: + artifacts: + - git: + repo: https://github.com/golang/example.git + revision: cfe12d6 + name: code + path: /go/src/github.com/golang/example + name: build-golang-example + - container: + args: + - ' uname -a ; cat /etc/os-release ; /go/src/github.com/golang/example/hello/hello ' + command: + - sh + - -c + image: '{{inputs.parameters.os-image}}' + volumeMounts: + - mountPath: /go + name: workdir + inputs: parameters: - name: os-image - value: '{{item.image}}:{{item.tag}}' - name: test - template: run-hello - withItems: - - image: debian - tag: '9.1' - - image: alpine - tag: '3.6' - - image: ubuntu - tag: '17.10' - - - name: release - template: release-artifact - volumeClaimTemplates: - - metadata: - name: workdir - spec: - accessModes: - - ReadWriteOnce - resources: - requests: - storage: 1Gi -``` + name: run-hello + - container: + image: alpine:3.8 + volumeMounts: + - mountPath: /go + name: workdir + name: release-artifact + outputs: + artifacts: + - name: release + path: /go + - name: ci-example + steps: + - - name: build + template: build-golang-example + - - arguments: + parameters: + - name: os-image + value: '{{item.image}}:{{item.tag}}' + name: test + template: run-hello + withItems: + - image: debian + tag: '9.1' + - image: alpine + tag: '3.6' + - image: ubuntu + tag: '17.10' + - - name: release + template: release-artifact + volumeClaimTemplates: + - metadata: + name: workdir + spec: + accessModes: + - ReadWriteOnce + resources: + requests: + storage: 1Gi + ``` + diff --git a/docs/examples/workflows/upstream/cluster_workflow_template__workflow_template_ref.md b/docs/examples/workflows/upstream/cluster_workflow_template__workflow_template_ref.md index d055436d3..9951045bb 100644 --- a/docs/examples/workflows/upstream/cluster_workflow_template__workflow_template_ref.md +++ b/docs/examples/workflows/upstream/cluster_workflow_template__workflow_template_ref.md @@ -4,29 +4,31 @@ -## Hera - -```python -from hera.workflows import Workflow -from hera.workflows.models import WorkflowTemplateRef - -wt_ref = WorkflowTemplateRef(name="cluster-workflow-template-submittable", cluster_scope=True) - -w = Workflow( - generate_name="cluster-workflow-template-hello-world-", - workflow_template_ref=wt_ref, -) -``` - -## YAML - -```yaml -apiVersion: argoproj.io/v1alpha1 -kind: Workflow -metadata: - generateName: cluster-workflow-template-hello-world- -spec: - workflowTemplateRef: - clusterScope: true - name: cluster-workflow-template-submittable -``` + +=== "Hera" + + ```python linenums="1" + from hera.workflows import Workflow + from hera.workflows.models import WorkflowTemplateRef + + wt_ref = WorkflowTemplateRef(name="cluster-workflow-template-submittable", cluster_scope=True) + + w = Workflow( + generate_name="cluster-workflow-template-hello-world-", + workflow_template_ref=wt_ref, + ) + ``` + +=== "YAML" + + ```yaml linenums="1" + apiVersion: argoproj.io/v1alpha1 + kind: Workflow + metadata: + generateName: cluster-workflow-template-hello-world- + spec: + workflowTemplateRef: + clusterScope: true + name: cluster-workflow-template-submittable + ``` + diff --git a/docs/examples/workflows/upstream/coinflip.md b/docs/examples/workflows/upstream/coinflip.md index 4085cb397..35cd2bcf4 100644 --- a/docs/examples/workflows/upstream/coinflip.md +++ b/docs/examples/workflows/upstream/coinflip.md @@ -4,100 +4,102 @@ -## Hera - -```python -from hera.workflows import Container, Steps, Workflow, script - - -@script(image="python:alpine3.6", command=["python"], add_cwd_to_sys_path=False) -def flip_coin() -> None: - import random - - result = "heads" if random.randint(0, 1) == 0 else "tails" - print(result) - - -with Workflow( - generate_name="coinflip-", - annotations={ - "workflows.argoproj.io/description": ( - "This is an example of coin flip defined as a sequence of conditional steps." - ), - }, - entrypoint="coinflip", -) as w: - heads = Container( - name="heads", - image="alpine:3.6", - command=["sh", "-c"], - args=['echo "it was heads"'], - ) - tails = Container( - name="tails", - image="alpine:3.6", - command=["sh", "-c"], - args=['echo "it was tails"'], - ) - - with Steps(name="coinflip") as s: - fc = flip_coin(name="flip-coin") - - with s.parallel(): - heads(when=f"{fc.result} == heads") - tails(when=f"{fc.result} == tails") -``` - -## YAML - -```yaml -apiVersion: argoproj.io/v1alpha1 -kind: Workflow -metadata: - annotations: - workflows.argoproj.io/description: This is an example of coin flip defined as - a sequence of conditional steps. - generateName: coinflip- -spec: - entrypoint: coinflip - templates: - - container: - args: - - echo "it was heads" - command: - - sh - - -c - image: alpine:3.6 - name: heads - - container: - args: - - echo "it was tails" - command: - - sh - - -c - image: alpine:3.6 - name: tails - - name: coinflip - steps: - - - name: flip-coin - template: flip-coin - - - name: heads - template: heads - when: '{{steps.flip-coin.outputs.result}} == heads' - - name: tails - template: tails - when: '{{steps.flip-coin.outputs.result}} == tails' - - name: flip-coin - script: - command: - - python - image: python:alpine3.6 - source: 'import random +=== "Hera" - result = "heads" if random.randint(0, 1) == 0 else "tails" + ```python linenums="1" + from hera.workflows import Container, Steps, Workflow, script + + + @script(image="python:alpine3.6", command=["python"], add_cwd_to_sys_path=False) + def flip_coin() -> None: + import random + result = "heads" if random.randint(0, 1) == 0 else "tails" print(result) - ' -``` + + with Workflow( + generate_name="coinflip-", + annotations={ + "workflows.argoproj.io/description": ( + "This is an example of coin flip defined as a sequence of conditional steps." + ), + }, + entrypoint="coinflip", + ) as w: + heads = Container( + name="heads", + image="alpine:3.6", + command=["sh", "-c"], + args=['echo "it was heads"'], + ) + tails = Container( + name="tails", + image="alpine:3.6", + command=["sh", "-c"], + args=['echo "it was tails"'], + ) + + with Steps(name="coinflip") as s: + fc = flip_coin(name="flip-coin") + + with s.parallel(): + heads(when=f"{fc.result} == heads") + tails(when=f"{fc.result} == tails") + ``` + +=== "YAML" + + ```yaml linenums="1" + apiVersion: argoproj.io/v1alpha1 + kind: Workflow + metadata: + annotations: + workflows.argoproj.io/description: This is an example of coin flip defined as + a sequence of conditional steps. + generateName: coinflip- + spec: + entrypoint: coinflip + templates: + - container: + args: + - echo "it was heads" + command: + - sh + - -c + image: alpine:3.6 + name: heads + - container: + args: + - echo "it was tails" + command: + - sh + - -c + image: alpine:3.6 + name: tails + - name: coinflip + steps: + - - name: flip-coin + template: flip-coin + - - name: heads + template: heads + when: '{{steps.flip-coin.outputs.result}} == heads' + - name: tails + template: tails + when: '{{steps.flip-coin.outputs.result}} == tails' + - name: flip-coin + script: + command: + - python + image: python:alpine3.6 + source: 'import random + + + result = "heads" if random.randint(0, 1) == 0 else "tails" + + print(result) + + ' + ``` + diff --git a/docs/examples/workflows/upstream/colored_logs.md b/docs/examples/workflows/upstream/colored_logs.md index 6ff772777..a06e5d553 100644 --- a/docs/examples/workflows/upstream/colored_logs.md +++ b/docs/examples/workflows/upstream/colored_logs.md @@ -4,61 +4,63 @@ -## Hera -```python -from hera.workflows import Env, Workflow, script +=== "Hera" + ```python linenums="1" + from hera.workflows import Env, Workflow, script -@script(image="python:3.7", add_cwd_to_sys_path=False, env=[Env(name="PYTHONUNBUFFERED", value="1")]) -def whalesay(): - import time # noqa: I001 - import random - messages = [ - "No Color", - "\x1b[30m%s\x1b[0m" % "FG Black", - "\x1b[32m%s\x1b[0m" % "FG Green", - "\x1b[34m%s\x1b[0m" % "FG Blue", - "\x1b[36m%s\x1b[0m" % "FG Cyan", - "\x1b[41m%s\x1b[0m" % "BG Red", - "\x1b[43m%s\x1b[0m" % "BG Yellow", - "\x1b[45m%s\x1b[0m" % "BG Magenta", - ] - for i in range(1, 100): - print(random.choice(messages)) - time.sleep(1) + @script(image="python:3.7", add_cwd_to_sys_path=False, env=[Env(name="PYTHONUNBUFFERED", value="1")]) + def whalesay(): + import time # noqa: I001 + import random + messages = [ + "No Color", + "\x1b[30m%s\x1b[0m" % "FG Black", + "\x1b[32m%s\x1b[0m" % "FG Green", + "\x1b[34m%s\x1b[0m" % "FG Blue", + "\x1b[36m%s\x1b[0m" % "FG Cyan", + "\x1b[41m%s\x1b[0m" % "BG Red", + "\x1b[43m%s\x1b[0m" % "BG Yellow", + "\x1b[45m%s\x1b[0m" % "BG Magenta", + ] + for i in range(1, 100): + print(random.choice(messages)) + time.sleep(1) -with Workflow(generate_name="colored-logs-", entrypoint="whalesay") as w: - whalesay(name="whalesay") -print(w.to_yaml()) -``` + with Workflow(generate_name="colored-logs-", entrypoint="whalesay") as w: + whalesay(name="whalesay") -## YAML + print(w.to_yaml()) + ``` + +=== "YAML" + + ```yaml linenums="1" + apiVersion: argoproj.io/v1alpha1 + kind: Workflow + metadata: + generateName: colored-logs- + spec: + entrypoint: whalesay + templates: + - name: whalesay + script: + command: + - python + env: + - name: PYTHONUNBUFFERED + value: '1' + image: python:3.7 + source: "import time # noqa: I001\nimport random\n\nmessages = [\n \"No\ + \ Color\",\n \"\\x1b[30m%s\\x1b[0m\" % \"FG Black\",\n \"\\x1b[32m%s\\\ + x1b[0m\" % \"FG Green\",\n \"\\x1b[34m%s\\x1b[0m\" % \"FG Blue\",\n \ + \ \"\\x1b[36m%s\\x1b[0m\" % \"FG Cyan\",\n \"\\x1b[41m%s\\x1b[0m\" % \"\ + BG Red\",\n \"\\x1b[43m%s\\x1b[0m\" % \"BG Yellow\",\n \"\\x1b[45m%s\\\ + x1b[0m\" % \"BG Magenta\",\n]\nfor i in range(1, 100):\n print(random.choice(messages))\n\ + \ time.sleep(1)\n" + ``` -```yaml -apiVersion: argoproj.io/v1alpha1 -kind: Workflow -metadata: - generateName: colored-logs- -spec: - entrypoint: whalesay - templates: - - name: whalesay - script: - command: - - python - env: - - name: PYTHONUNBUFFERED - value: '1' - image: python:3.7 - source: "import time # noqa: I001\nimport random\n\nmessages = [\n \"No\ - \ Color\",\n \"\\x1b[30m%s\\x1b[0m\" % \"FG Black\",\n \"\\x1b[32m%s\\\ - x1b[0m\" % \"FG Green\",\n \"\\x1b[34m%s\\x1b[0m\" % \"FG Blue\",\n \ - \ \"\\x1b[36m%s\\x1b[0m\" % \"FG Cyan\",\n \"\\x1b[41m%s\\x1b[0m\" % \"\ - BG Red\",\n \"\\x1b[43m%s\\x1b[0m\" % \"BG Yellow\",\n \"\\x1b[45m%s\\\ - x1b[0m\" % \"BG Magenta\",\n]\nfor i in range(1, 100):\n print(random.choice(messages))\n\ - \ time.sleep(1)\n" -``` diff --git a/docs/examples/workflows/upstream/conditional_artifacts.md b/docs/examples/workflows/upstream/conditional_artifacts.md index e20e29c5d..cdf3ded8a 100644 --- a/docs/examples/workflows/upstream/conditional_artifacts.md +++ b/docs/examples/workflows/upstream/conditional_artifacts.md @@ -4,146 +4,148 @@ -## Hera - -```python -from hera.workflows import Artifact, Script, Step, Steps, Workflow - - -def _flip_coin(): - import random - - print("heads" if random.randint(0, 1) == 0 else "tails") - - -def _heads(): - with open("result.txt", "w") as f: - f.write("it was heads") - - -def _tails(): - with open("result.txt", "w") as f: - f.write("it was tails") - - -with Workflow( - generate_name="conditional-artifacts-", - labels={ - "workflows.argoproj.io/test": "true", - }, - annotations={ - "workflows.argoproj.io/description": "Conditional aartifacts provide a way to choose the output " - "artifacts based on expression. " - "In this example the main template has two steps which will run " - "conditionall using `when` . Based on the `when` condition one of step" - ' will not execute. The main template\'s output artifact named "result" ' - "will be set to the executed step's output." - }, - entrypoint="main", -) as w: - flip_coin = Script( - name="flip-coin", - image="python:alpine3.6", - command=["python"], - source=_flip_coin, - add_cwd_to_sys_path=False, - ) - heads = Script( - name="heads", - image="python:alpine3.6", - command=["python"], - source=_heads, - outputs=[Artifact(name="result", path="/result.txt")], - add_cwd_to_sys_path=False, - ) - tails = Script( - name="tails", - image="python:alpine3.6", - command=["python"], - source=_tails, - outputs=[Artifact(name="result", path="/result.txt")], - add_cwd_to_sys_path=False, - ) - - with Steps( - name="main", - outputs=[ - Artifact( - name="result", - from_expression="steps['flip-coin'].outputs.result == 'heads' ? steps.heads.outputs.artifacts.result : steps.tails.outputs.artifacts.result", - ), - ], - ) as s: - Step(name="flip-coin", template=flip_coin) - with s.parallel(): - Step(name="heads", template=heads, when="{{steps.flip-coin.outputs.result}} == heads") - Step(name="tails", template=tails, when="{{steps.flip-coin.outputs.result}} == tails") -``` - -## YAML - -```yaml -apiVersion: argoproj.io/v1alpha1 -kind: Workflow -metadata: - annotations: - workflows.argoproj.io/description: Conditional aartifacts provide a way to choose - the output artifacts based on expression. In this example the main template - has two steps which will run conditionall using `when` . Based on the `when` - condition one of step will not execute. The main template's output artifact - named "result" will be set to the executed step's output. - generateName: conditional-artifacts- - labels: - workflows.argoproj.io/test: 'true' -spec: - entrypoint: main - templates: - - name: flip-coin - script: - command: - - python - image: python:alpine3.6 - source: 'import random +=== "Hera" + + ```python linenums="1" + from hera.workflows import Artifact, Script, Step, Steps, Workflow + + + def _flip_coin(): + import random print("heads" if random.randint(0, 1) == 0 else "tails") - ' - - name: heads - outputs: - artifacts: - - name: result - path: /result.txt - script: - command: - - python - image: python:alpine3.6 - source: "with open(\"result.txt\", \"w\") as f:\n f.write(\"it was heads\"\ - )\n" - - name: tails - outputs: - artifacts: - - name: result - path: /result.txt - script: - command: - - python - image: python:alpine3.6 - source: "with open(\"result.txt\", \"w\") as f:\n f.write(\"it was tails\"\ - )\n" - - name: main - outputs: - artifacts: - - fromExpression: 'steps[''flip-coin''].outputs.result == ''heads'' ? steps.heads.outputs.artifacts.result - : steps.tails.outputs.artifacts.result' - name: result - steps: - - - name: flip-coin - template: flip-coin - - - name: heads - template: heads - when: '{{steps.flip-coin.outputs.result}} == heads' + + def _heads(): + with open("result.txt", "w") as f: + f.write("it was heads") + + + def _tails(): + with open("result.txt", "w") as f: + f.write("it was tails") + + + with Workflow( + generate_name="conditional-artifacts-", + labels={ + "workflows.argoproj.io/test": "true", + }, + annotations={ + "workflows.argoproj.io/description": "Conditional aartifacts provide a way to choose the output " + "artifacts based on expression. " + "In this example the main template has two steps which will run " + "conditionall using `when` . Based on the `when` condition one of step" + ' will not execute. The main template\'s output artifact named "result" ' + "will be set to the executed step's output." + }, + entrypoint="main", + ) as w: + flip_coin = Script( + name="flip-coin", + image="python:alpine3.6", + command=["python"], + source=_flip_coin, + add_cwd_to_sys_path=False, + ) + heads = Script( + name="heads", + image="python:alpine3.6", + command=["python"], + source=_heads, + outputs=[Artifact(name="result", path="/result.txt")], + add_cwd_to_sys_path=False, + ) + tails = Script( + name="tails", + image="python:alpine3.6", + command=["python"], + source=_tails, + outputs=[Artifact(name="result", path="/result.txt")], + add_cwd_to_sys_path=False, + ) + + with Steps( + name="main", + outputs=[ + Artifact( + name="result", + from_expression="steps['flip-coin'].outputs.result == 'heads' ? steps.heads.outputs.artifacts.result : steps.tails.outputs.artifacts.result", + ), + ], + ) as s: + Step(name="flip-coin", template=flip_coin) + with s.parallel(): + Step(name="heads", template=heads, when="{{steps.flip-coin.outputs.result}} == heads") + Step(name="tails", template=tails, when="{{steps.flip-coin.outputs.result}} == tails") + ``` + +=== "YAML" + + ```yaml linenums="1" + apiVersion: argoproj.io/v1alpha1 + kind: Workflow + metadata: + annotations: + workflows.argoproj.io/description: Conditional aartifacts provide a way to choose + the output artifacts based on expression. In this example the main template + has two steps which will run conditionall using `when` . Based on the `when` + condition one of step will not execute. The main template's output artifact + named "result" will be set to the executed step's output. + generateName: conditional-artifacts- + labels: + workflows.argoproj.io/test: 'true' + spec: + entrypoint: main + templates: + - name: flip-coin + script: + command: + - python + image: python:alpine3.6 + source: 'import random + + + print("heads" if random.randint(0, 1) == 0 else "tails") + + ' + - name: heads + outputs: + artifacts: + - name: result + path: /result.txt + script: + command: + - python + image: python:alpine3.6 + source: "with open(\"result.txt\", \"w\") as f:\n f.write(\"it was heads\"\ + )\n" - name: tails - template: tails - when: '{{steps.flip-coin.outputs.result}} == tails' -``` + outputs: + artifacts: + - name: result + path: /result.txt + script: + command: + - python + image: python:alpine3.6 + source: "with open(\"result.txt\", \"w\") as f:\n f.write(\"it was tails\"\ + )\n" + - name: main + outputs: + artifacts: + - fromExpression: 'steps[''flip-coin''].outputs.result == ''heads'' ? steps.heads.outputs.artifacts.result + : steps.tails.outputs.artifacts.result' + name: result + steps: + - - name: flip-coin + template: flip-coin + - - name: heads + template: heads + when: '{{steps.flip-coin.outputs.result}} == heads' + - name: tails + template: tails + when: '{{steps.flip-coin.outputs.result}} == tails' + ``` + diff --git a/docs/examples/workflows/upstream/container_set_template__graph_workflow.md b/docs/examples/workflows/upstream/container_set_template__graph_workflow.md index 69ce0abc4..ff6b7da94 100644 --- a/docs/examples/workflows/upstream/container_set_template__graph_workflow.md +++ b/docs/examples/workflows/upstream/container_set_template__graph_workflow.md @@ -4,50 +4,52 @@ -## Hera - -```python -from hera.workflows.container_set import ContainerNode, ContainerSet -from hera.workflows.workflow import Workflow - -with Workflow( - generate_name="graph-", - entrypoint="main", -) as w: - with ContainerSet(name="main"): - a = ContainerNode(name="a", image="argoproj/argosay:v2") - b = ContainerNode(name="b", image="argoproj/argosay:v2") - c = ContainerNode(name="c", image="argoproj/argosay:v2") - d = ContainerNode(name="d", image="argoproj/argosay:v2") - a >> [b, c] >> d -``` - -## YAML - -```yaml -apiVersion: argoproj.io/v1alpha1 -kind: Workflow -metadata: - generateName: graph- -spec: - entrypoint: main - templates: - - containerSet: - containers: - - image: argoproj/argosay:v2 - name: a - - dependencies: - - a - image: argoproj/argosay:v2 - name: b - - dependencies: - - a - image: argoproj/argosay:v2 - name: c - - dependencies: - - b - - c - image: argoproj/argosay:v2 - name: d - name: main -``` + +=== "Hera" + + ```python linenums="1" + from hera.workflows.container_set import ContainerNode, ContainerSet + from hera.workflows.workflow import Workflow + + with Workflow( + generate_name="graph-", + entrypoint="main", + ) as w: + with ContainerSet(name="main"): + a = ContainerNode(name="a", image="argoproj/argosay:v2") + b = ContainerNode(name="b", image="argoproj/argosay:v2") + c = ContainerNode(name="c", image="argoproj/argosay:v2") + d = ContainerNode(name="d", image="argoproj/argosay:v2") + a >> [b, c] >> d + ``` + +=== "YAML" + + ```yaml linenums="1" + apiVersion: argoproj.io/v1alpha1 + kind: Workflow + metadata: + generateName: graph- + spec: + entrypoint: main + templates: + - containerSet: + containers: + - image: argoproj/argosay:v2 + name: a + - dependencies: + - a + image: argoproj/argosay:v2 + name: b + - dependencies: + - a + image: argoproj/argosay:v2 + name: c + - dependencies: + - b + - c + image: argoproj/argosay:v2 + name: d + name: main + ``` + diff --git a/docs/examples/workflows/upstream/container_set_template__outputs_result_workflow.md b/docs/examples/workflows/upstream/container_set_template__outputs_result_workflow.md index 7bd21a7de..4f7a84e80 100644 --- a/docs/examples/workflows/upstream/container_set_template__outputs_result_workflow.md +++ b/docs/examples/workflows/upstream/container_set_template__outputs_result_workflow.md @@ -4,95 +4,97 @@ -## Hera - -```python -from hera.expr import g -from hera.workflows import ( - DAG, - ContainerNode, - ContainerSet, - Parameter, - Script, - Task, - Workflow, - models as m, -) - - -def _check(): - assert "{{inputs.parameters.x}}" == "hi" - - -with Workflow( - generate_name="outputs-result-", - entrypoint="main", -) as w: - with ContainerSet(name="group") as group: - ContainerNode(name="main", image="python:alpine3.6", command=["python", "-c"], args=['print("hi")\n']) - - verify = Script( - source=_check, - image="python:alpine3.6", - command=["python"], - inputs=[Parameter(name="x")], - add_cwd_to_sys_path=False, - name="verify", + +=== "Hera" + + ```python linenums="1" + from hera.expr import g + from hera.workflows import ( + DAG, + ContainerNode, + ContainerSet, + Parameter, + Script, + Task, + Workflow, + models as m, ) - with DAG(name="main") as dag: - a = Task(name="a", template=group) - b = Task( - name="b", - arguments=m.Arguments(parameters=[Parameter(name="x", value=f"{g.tasks.a.outputs.result:$}")]), - template=verify, - dependencies=["a"], + + + def _check(): + assert "{{inputs.parameters.x}}" == "hi" + + + with Workflow( + generate_name="outputs-result-", + entrypoint="main", + ) as w: + with ContainerSet(name="group") as group: + ContainerNode(name="main", image="python:alpine3.6", command=["python", "-c"], args=['print("hi")\n']) + + verify = Script( + source=_check, + image="python:alpine3.6", + command=["python"], + inputs=[Parameter(name="x")], + add_cwd_to_sys_path=False, + name="verify", ) -``` - -## YAML - -```yaml -apiVersion: argoproj.io/v1alpha1 -kind: Workflow -metadata: - generateName: outputs-result- -spec: - entrypoint: main - templates: - - containerSet: - containers: - - args: - - 'print("hi") - - ' - command: - - python - - -c - image: python:alpine3.6 - name: main - name: group - - inputs: - parameters: - - name: x - name: verify - script: - command: - - python - image: python:alpine3.6 - source: 'assert "{{inputs.parameters.x}}" == "hi" - - ' - - dag: - tasks: - - name: a - template: group - - arguments: + with DAG(name="main") as dag: + a = Task(name="a", template=group) + b = Task( + name="b", + arguments=m.Arguments(parameters=[Parameter(name="x", value=f"{g.tasks.a.outputs.result:$}")]), + template=verify, + dependencies=["a"], + ) + ``` + +=== "YAML" + + ```yaml linenums="1" + apiVersion: argoproj.io/v1alpha1 + kind: Workflow + metadata: + generateName: outputs-result- + spec: + entrypoint: main + templates: + - containerSet: + containers: + - args: + - 'print("hi") + + ' + command: + - python + - -c + image: python:alpine3.6 + name: main + name: group + - inputs: parameters: - name: x - value: '{{tasks.a.outputs.result}}' - dependencies: - - a - name: b - template: verify - name: main -``` + name: verify + script: + command: + - python + image: python:alpine3.6 + source: 'assert "{{inputs.parameters.x}}" == "hi" + + ' + - dag: + tasks: + - name: a + template: group + - arguments: + parameters: + - name: x + value: '{{tasks.a.outputs.result}}' + dependencies: + - a + name: b + template: verify + name: main + ``` + diff --git a/docs/examples/workflows/upstream/container_set_template__parallel_workflow.md b/docs/examples/workflows/upstream/container_set_template__parallel_workflow.md index ef2d1cc9f..b0cd02669 100644 --- a/docs/examples/workflows/upstream/container_set_template__parallel_workflow.md +++ b/docs/examples/workflows/upstream/container_set_template__parallel_workflow.md @@ -4,35 +4,37 @@ -## Hera - -```python -from hera.workflows import ContainerNode, ContainerSet, Workflow - -with Workflow( - generate_name="parallel-", - entrypoint="main", -) as w: - with ContainerSet(name="main"): - ContainerNode(name="a", image="argoproj/argosay:v2") - ContainerNode(name="b", image="argoproj/argosay:v2") -``` - -## YAML - -```yaml -apiVersion: argoproj.io/v1alpha1 -kind: Workflow -metadata: - generateName: parallel- -spec: - entrypoint: main - templates: - - containerSet: - containers: - - image: argoproj/argosay:v2 - name: a - - image: argoproj/argosay:v2 - name: b - name: main -``` + +=== "Hera" + + ```python linenums="1" + from hera.workflows import ContainerNode, ContainerSet, Workflow + + with Workflow( + generate_name="parallel-", + entrypoint="main", + ) as w: + with ContainerSet(name="main"): + ContainerNode(name="a", image="argoproj/argosay:v2") + ContainerNode(name="b", image="argoproj/argosay:v2") + ``` + +=== "YAML" + + ```yaml linenums="1" + apiVersion: argoproj.io/v1alpha1 + kind: Workflow + metadata: + generateName: parallel- + spec: + entrypoint: main + templates: + - containerSet: + containers: + - image: argoproj/argosay:v2 + name: a + - image: argoproj/argosay:v2 + name: b + name: main + ``` + diff --git a/docs/examples/workflows/upstream/container_set_template__sequence_workflow.md b/docs/examples/workflows/upstream/container_set_template__sequence_workflow.md index f0ea29566..48f428efb 100644 --- a/docs/examples/workflows/upstream/container_set_template__sequence_workflow.md +++ b/docs/examples/workflows/upstream/container_set_template__sequence_workflow.md @@ -4,44 +4,46 @@ -## Hera - -```python -from hera.workflows import ContainerNode, ContainerSet, Workflow - -with Workflow( - generate_name="sequence-", - entrypoint="main", -) as w: - with ContainerSet(name="main"): - ( - ContainerNode(name="a", image="argoproj/argosay:v2") - >> ContainerNode(name="b", image="argoproj/argosay:v2") - >> ContainerNode(name="c", image="argoproj/argosay:v2") - ) -``` - -## YAML - -```yaml -apiVersion: argoproj.io/v1alpha1 -kind: Workflow -metadata: - generateName: sequence- -spec: - entrypoint: main - templates: - - containerSet: - containers: - - image: argoproj/argosay:v2 - name: a - - dependencies: - - a - image: argoproj/argosay:v2 - name: b - - dependencies: - - b - image: argoproj/argosay:v2 - name: c - name: main -``` + +=== "Hera" + + ```python linenums="1" + from hera.workflows import ContainerNode, ContainerSet, Workflow + + with Workflow( + generate_name="sequence-", + entrypoint="main", + ) as w: + with ContainerSet(name="main"): + ( + ContainerNode(name="a", image="argoproj/argosay:v2") + >> ContainerNode(name="b", image="argoproj/argosay:v2") + >> ContainerNode(name="c", image="argoproj/argosay:v2") + ) + ``` + +=== "YAML" + + ```yaml linenums="1" + apiVersion: argoproj.io/v1alpha1 + kind: Workflow + metadata: + generateName: sequence- + spec: + entrypoint: main + templates: + - containerSet: + containers: + - image: argoproj/argosay:v2 + name: a + - dependencies: + - a + image: argoproj/argosay:v2 + name: b + - dependencies: + - b + image: argoproj/argosay:v2 + name: c + name: main + ``` + diff --git a/docs/examples/workflows/upstream/container_set_template__workspace_workflow.md b/docs/examples/workflows/upstream/container_set_template__workspace_workflow.md index 95fc2d012..84580f1ee 100644 --- a/docs/examples/workflows/upstream/container_set_template__workspace_workflow.md +++ b/docs/examples/workflows/upstream/container_set_template__workspace_workflow.md @@ -4,69 +4,71 @@ -## Hera -```python -from hera.workflows import ContainerNode, ContainerSet, EmptyDirVolume, Parameter, Workflow -from hera.workflows.models import Artifact, ValueFrom, VolumeMount +=== "Hera" -with Workflow( - generate_name="workspace-", - entrypoint="main", -) as w: - with ContainerSet( - name="main", - volumes=[EmptyDirVolume(name="workspace", mount_path="/workspace")], - volume_mounts=[VolumeMount(name="workspace", mount_path="/workspace")], - outputs=[ - Parameter(name="out", value_from=ValueFrom(path="/workspace/out")), - Artifact(name="out", path="/workspace/out"), - ], - ): - ContainerNode( - name="a", - image="argoproj/argosay:v2", - args=["echo", "hi", "/workspace/out"], - ), - ContainerNode( + ```python linenums="1" + from hera.workflows import ContainerNode, ContainerSet, EmptyDirVolume, Parameter, Workflow + from hera.workflows.models import Artifact, ValueFrom, VolumeMount + + with Workflow( + generate_name="workspace-", + entrypoint="main", + ) as w: + with ContainerSet( name="main", - image="argoproj/argosay:v2", - ), -``` + volumes=[EmptyDirVolume(name="workspace", mount_path="/workspace")], + volume_mounts=[VolumeMount(name="workspace", mount_path="/workspace")], + outputs=[ + Parameter(name="out", value_from=ValueFrom(path="/workspace/out")), + Artifact(name="out", path="/workspace/out"), + ], + ): + ContainerNode( + name="a", + image="argoproj/argosay:v2", + args=["echo", "hi", "/workspace/out"], + ), + ContainerNode( + name="main", + image="argoproj/argosay:v2", + ), + ``` -## YAML +=== "YAML" -```yaml -apiVersion: argoproj.io/v1alpha1 -kind: Workflow -metadata: - generateName: workspace- -spec: - entrypoint: main - templates: - - containerSet: - containers: - - args: - - echo - - hi - - /workspace/out - image: argoproj/argosay:v2 - name: a - - image: argoproj/argosay:v2 + ```yaml linenums="1" + apiVersion: argoproj.io/v1alpha1 + kind: Workflow + metadata: + generateName: workspace- + spec: + entrypoint: main + templates: + - containerSet: + containers: + - args: + - echo + - hi + - /workspace/out + image: argoproj/argosay:v2 + name: a + - image: argoproj/argosay:v2 + name: main + volumeMounts: + - mountPath: /workspace + name: workspace name: main - volumeMounts: - - mountPath: /workspace - name: workspace - name: main - outputs: - artifacts: - - name: out - path: /workspace/out - parameters: - - name: out - valueFrom: - path: /workspace/out - volumes: - - emptyDir: {} - name: workspace -``` + outputs: + artifacts: + - name: out + path: /workspace/out + parameters: + - name: out + valueFrom: + path: /workspace/out + volumes: + - emptyDir: {} + name: workspace + ``` + diff --git a/docs/examples/workflows/upstream/cron_workflow.md b/docs/examples/workflows/upstream/cron_workflow.md index 5ac893e0d..b41c9e08a 100644 --- a/docs/examples/workflows/upstream/cron_workflow.md +++ b/docs/examples/workflows/upstream/cron_workflow.md @@ -4,53 +4,55 @@ -## Hera - -```python -from hera.workflows import Container, CronWorkflow - -with CronWorkflow( - name="hello-world", - entrypoint="whalesay", - schedule="* * * * *", - timezone="America/Los_Angeles", - starting_deadline_seconds=0, - concurrency_policy="Replace", - successful_jobs_history_limit=4, - failed_jobs_history_limit=4, - cron_suspend=False, -) as w: - whalesay = Container( - name="whalesay", - image="docker/whalesay:latest", - command=["cowsay"], - args=["🕓 hello world. Scheduled on: {{workflow.scheduledTime}}"], - ) -``` - -## YAML - -```yaml -apiVersion: argoproj.io/v1alpha1 -kind: CronWorkflow -metadata: - name: hello-world -spec: - concurrencyPolicy: Replace - failedJobsHistoryLimit: 4 - schedule: '* * * * *' - startingDeadlineSeconds: 0 - successfulJobsHistoryLimit: 4 - suspend: false - timezone: America/Los_Angeles - workflowSpec: - entrypoint: whalesay - templates: - - container: - args: - - "\U0001F553 hello world. Scheduled on: {{workflow.scheduledTime}}" - command: - - cowsay - image: docker/whalesay:latest - name: whalesay -``` + +=== "Hera" + + ```python linenums="1" + from hera.workflows import Container, CronWorkflow + + with CronWorkflow( + name="hello-world", + entrypoint="whalesay", + schedule="* * * * *", + timezone="America/Los_Angeles", + starting_deadline_seconds=0, + concurrency_policy="Replace", + successful_jobs_history_limit=4, + failed_jobs_history_limit=4, + cron_suspend=False, + ) as w: + whalesay = Container( + name="whalesay", + image="docker/whalesay:latest", + command=["cowsay"], + args=["🕓 hello world. Scheduled on: {{workflow.scheduledTime}}"], + ) + ``` + +=== "YAML" + + ```yaml linenums="1" + apiVersion: argoproj.io/v1alpha1 + kind: CronWorkflow + metadata: + name: hello-world + spec: + concurrencyPolicy: Replace + failedJobsHistoryLimit: 4 + schedule: '* * * * *' + startingDeadlineSeconds: 0 + successfulJobsHistoryLimit: 4 + suspend: false + timezone: America/Los_Angeles + workflowSpec: + entrypoint: whalesay + templates: + - container: + args: + - "\U0001F553 hello world. Scheduled on: {{workflow.scheduledTime}}" + command: + - cowsay + image: docker/whalesay:latest + name: whalesay + ``` + diff --git a/docs/examples/workflows/upstream/dag_conditional_parameters.md b/docs/examples/workflows/upstream/dag_conditional_parameters.md index 1ba752f6a..b60287a36 100644 --- a/docs/examples/workflows/upstream/dag_conditional_parameters.md +++ b/docs/examples/workflows/upstream/dag_conditional_parameters.md @@ -4,110 +4,112 @@ -## Hera - -```python -from hera.expr import g -from hera.workflows import DAG, Parameter, Script, Task, Workflow - - -def heads(): - print("heads") - - -def tails(): - print("tails") - - -def flip_coin(): - import random - - print("heads" if random.randint(0, 1) == 0 else "tails") - - -def get_script(callable): - return Script( - name=callable.__name__.replace("_", "-"), - source=callable, - add_cwd_to_sys_path=False, - image="python:alpine3.6", - ) - - -with Workflow( - generate_name="dag-conditional-parameter-", - entrypoint="main", -) as w: - heads_template = get_script(heads) - tails_template = get_script(tails) - flip_coin_template = get_script(flip_coin) - - with DAG(name="main") as main_dag: - flip_coin_task = Task(name="flip-coin", template=flip_coin_template) - heads_task = Task(name="heads", template=heads_template) - tails_task = Task(name="tails", template=tails_template) - heads_task.on_other_result(flip_coin_task, "heads") - tails_task.on_other_result(flip_coin_task, "tails") - - expression = g.tasks["flip-coin"].outputs.result == "heads" - expression = expression.check(g.tasks.heads.outputs.result, g.tasks.tails.outputs.result) # type: ignore - main_dag.outputs = [Parameter(name="stepresult", value_from={"expression": str(expression)})] -``` - -## YAML - -```yaml -apiVersion: argoproj.io/v1alpha1 -kind: Workflow -metadata: - generateName: dag-conditional-parameter- -spec: - entrypoint: main - templates: - - name: heads - script: - command: - - python - image: python:alpine3.6 - source: 'print("heads") - - ' - - name: tails - script: - command: - - python - image: python:alpine3.6 - source: 'print("tails") - - ' - - name: flip-coin - script: - command: - - python - image: python:alpine3.6 - source: 'import random +=== "Hera" + + ```python linenums="1" + from hera.expr import g + from hera.workflows import DAG, Parameter, Script, Task, Workflow + + + def heads(): + print("heads") + + + def tails(): + print("tails") + + + def flip_coin(): + import random print("heads" if random.randint(0, 1) == 0 else "tails") - ' - - dag: - tasks: + + def get_script(callable): + return Script( + name=callable.__name__.replace("_", "-"), + source=callable, + add_cwd_to_sys_path=False, + image="python:alpine3.6", + ) + + + with Workflow( + generate_name="dag-conditional-parameter-", + entrypoint="main", + ) as w: + heads_template = get_script(heads) + tails_template = get_script(tails) + flip_coin_template = get_script(flip_coin) + + with DAG(name="main") as main_dag: + flip_coin_task = Task(name="flip-coin", template=flip_coin_template) + heads_task = Task(name="heads", template=heads_template) + tails_task = Task(name="tails", template=tails_template) + heads_task.on_other_result(flip_coin_task, "heads") + tails_task.on_other_result(flip_coin_task, "tails") + + expression = g.tasks["flip-coin"].outputs.result == "heads" + expression = expression.check(g.tasks.heads.outputs.result, g.tasks.tails.outputs.result) # type: ignore + main_dag.outputs = [Parameter(name="stepresult", value_from={"expression": str(expression)})] + ``` + +=== "YAML" + + ```yaml linenums="1" + apiVersion: argoproj.io/v1alpha1 + kind: Workflow + metadata: + generateName: dag-conditional-parameter- + spec: + entrypoint: main + templates: + - name: heads + script: + command: + - python + image: python:alpine3.6 + source: 'print("heads") + + ' + - name: tails + script: + command: + - python + image: python:alpine3.6 + source: 'print("tails") + + ' - name: flip-coin - template: flip-coin - - depends: flip-coin - name: heads - template: heads - when: '{{tasks.flip-coin.outputs.result}} == heads' - - depends: flip-coin - name: tails - template: tails - when: '{{tasks.flip-coin.outputs.result}} == tails' - name: main - outputs: - parameters: - - name: stepresult - valueFrom: - expression: 'tasks[''flip-coin''].outputs.result == ''heads'' ? tasks.heads.outputs.result - : tasks.tails.outputs.result' -``` + script: + command: + - python + image: python:alpine3.6 + source: 'import random + + + print("heads" if random.randint(0, 1) == 0 else "tails") + + ' + - dag: + tasks: + - name: flip-coin + template: flip-coin + - depends: flip-coin + name: heads + template: heads + when: '{{tasks.flip-coin.outputs.result}} == heads' + - depends: flip-coin + name: tails + template: tails + when: '{{tasks.flip-coin.outputs.result}} == tails' + name: main + outputs: + parameters: + - name: stepresult + valueFrom: + expression: 'tasks[''flip-coin''].outputs.result == ''heads'' ? tasks.heads.outputs.result + : tasks.tails.outputs.result' + ``` + diff --git a/docs/examples/workflows/upstream/dag_diamond.md b/docs/examples/workflows/upstream/dag_diamond.md index 924b96ff4..c48757b01 100644 --- a/docs/examples/workflows/upstream/dag_diamond.md +++ b/docs/examples/workflows/upstream/dag_diamond.md @@ -4,76 +4,78 @@ -## Hera -```python -from hera.workflows import DAG, Container, Parameter, Workflow +=== "Hera" -with Workflow( - generate_name="dag-diamond-", - entrypoint="diamond", -) as w: - echo = Container( - name="echo", - image="alpine:3.7", - command=["echo", "{{inputs.parameters.message}}"], - inputs=[Parameter(name="message")], - ) - with DAG(name="diamond"): - A = echo(name="A", arguments={"message": "A"}) - B = echo(name="B", arguments={"message": "B"}) - C = echo(name="C", arguments={"message": "C"}) - D = echo(name="D", arguments={"message": "D"}) - A >> [B, C] >> D -``` + ```python linenums="1" + from hera.workflows import DAG, Container, Parameter, Workflow -## YAML + with Workflow( + generate_name="dag-diamond-", + entrypoint="diamond", + ) as w: + echo = Container( + name="echo", + image="alpine:3.7", + command=["echo", "{{inputs.parameters.message}}"], + inputs=[Parameter(name="message")], + ) + with DAG(name="diamond"): + A = echo(name="A", arguments={"message": "A"}) + B = echo(name="B", arguments={"message": "B"}) + C = echo(name="C", arguments={"message": "C"}) + D = echo(name="D", arguments={"message": "D"}) + A >> [B, C] >> D + ``` -```yaml -apiVersion: argoproj.io/v1alpha1 -kind: Workflow -metadata: - generateName: dag-diamond- -spec: - entrypoint: diamond - templates: - - container: - command: - - echo - - '{{inputs.parameters.message}}' - image: alpine:3.7 - inputs: - parameters: - - name: message - name: echo - - dag: - tasks: - - arguments: - parameters: - - name: message - value: A - name: A - template: echo - - arguments: - parameters: - - name: message - value: B - depends: A - name: B - template: echo - - arguments: - parameters: - - name: message - value: C - depends: A - name: C - template: echo - - arguments: +=== "YAML" + + ```yaml linenums="1" + apiVersion: argoproj.io/v1alpha1 + kind: Workflow + metadata: + generateName: dag-diamond- + spec: + entrypoint: diamond + templates: + - container: + command: + - echo + - '{{inputs.parameters.message}}' + image: alpine:3.7 + inputs: parameters: - name: message - value: D - depends: B && C - name: D - template: echo - name: diamond -``` + name: echo + - dag: + tasks: + - arguments: + parameters: + - name: message + value: A + name: A + template: echo + - arguments: + parameters: + - name: message + value: B + depends: A + name: B + template: echo + - arguments: + parameters: + - name: message + value: C + depends: A + name: C + template: echo + - arguments: + parameters: + - name: message + value: D + depends: B && C + name: D + template: echo + name: diamond + ``` + diff --git a/docs/examples/workflows/upstream/dag_inline_workflowtemplate.md b/docs/examples/workflows/upstream/dag_inline_workflowtemplate.md index d89f7ad1b..a46c66d12 100644 --- a/docs/examples/workflows/upstream/dag_inline_workflowtemplate.md +++ b/docs/examples/workflows/upstream/dag_inline_workflowtemplate.md @@ -4,44 +4,46 @@ -## Hera - -```python -from hera.workflows import DAG, Container, Task, WorkflowTemplate - -container = Container(image="argoproj/argosay:v2") - -with WorkflowTemplate( - name="dag-inline", - entrypoint="main", - annotations={ - "workflows.argoproj.io/description": ("This example demonstrates running a DAG with inline templates."), - "workflows.argoproj.io/version": ">= 3.2.0", - }, -) as w: - with DAG(name="main"): - Task(name="a", inline=container) -``` - -## YAML - -```yaml -apiVersion: argoproj.io/v1alpha1 -kind: WorkflowTemplate -metadata: - annotations: - workflows.argoproj.io/description: This example demonstrates running a DAG with - inline templates. - workflows.argoproj.io/version: '>= 3.2.0' - name: dag-inline -spec: - entrypoint: main - templates: - - dag: - tasks: - - inline: - container: - image: argoproj/argosay:v2 - name: a - name: main -``` + +=== "Hera" + + ```python linenums="1" + from hera.workflows import DAG, Container, Task, WorkflowTemplate + + container = Container(image="argoproj/argosay:v2") + + with WorkflowTemplate( + name="dag-inline", + entrypoint="main", + annotations={ + "workflows.argoproj.io/description": ("This example demonstrates running a DAG with inline templates."), + "workflows.argoproj.io/version": ">= 3.2.0", + }, + ) as w: + with DAG(name="main"): + Task(name="a", inline=container) + ``` + +=== "YAML" + + ```yaml linenums="1" + apiVersion: argoproj.io/v1alpha1 + kind: WorkflowTemplate + metadata: + annotations: + workflows.argoproj.io/description: This example demonstrates running a DAG with + inline templates. + workflows.argoproj.io/version: '>= 3.2.0' + name: dag-inline + spec: + entrypoint: main + templates: + - dag: + tasks: + - inline: + container: + image: argoproj/argosay:v2 + name: a + name: main + ``` + diff --git a/docs/examples/workflows/upstream/exit_handler_with_artifacts.md b/docs/examples/workflows/upstream/exit_handler_with_artifacts.md index 073e5e1c3..122b1691f 100644 --- a/docs/examples/workflows/upstream/exit_handler_with_artifacts.md +++ b/docs/examples/workflows/upstream/exit_handler_with_artifacts.md @@ -49,117 +49,119 @@ spec: command: [sh, -c] args: ["cat /tmp/message"] -## Hera -```python -from hera.workflows import ( - Artifact, - Container, - Script, - Step, - Steps, - Workflow, - models as m, -) +=== "Hera" + ```python linenums="1" + from hera.workflows import ( + Artifact, + Container, + Script, + Step, + Steps, + Workflow, + models as m, + ) -def _output(): - with open("result.txt", "w") as f: - f.write("Welcome") + def _output(): + with open("result.txt", "w") as f: + f.write("Welcome") -with Workflow( - generate_name="exit-handler-with-artifacts-", - entrypoint="main", - labels={"workflows.argoproj.io/test": "true"}, - annotations={ - "workflows.argoproj.io/description": "onExitTemplate enables workflow to pass the arguments " - "(parameters/Artifacts) to exit handler template.", - "workflows.argoproj.io/version": ">= 3.1.0", - }, -) as w: - output = Script( - name="output", - image="python:alpine3.6", - command=["python"], - source=_output, - outputs=[Artifact(name="result", path="/result.txt")], - add_cwd_to_sys_path=False, - ) - exit_ = Container( - name="exit", - image="python:alpine3.6", - command=["sh", "-c"], - args=["cat /tmp/message"], - inputs=[Artifact(name="message", path="/tmp/message")], - ) - with Steps(name="main"): - Step( - name="step-1", - template=output, - hooks={ - "exit": m.LifecycleHook( - template="exit", - arguments=m.Arguments( - artifacts=[ - m.Artifact( - name="message", - from_="{{steps.step-1.outputs.artifacts.result}}", - ) - ], - ), - ) - }, + + with Workflow( + generate_name="exit-handler-with-artifacts-", + entrypoint="main", + labels={"workflows.argoproj.io/test": "true"}, + annotations={ + "workflows.argoproj.io/description": "onExitTemplate enables workflow to pass the arguments " + "(parameters/Artifacts) to exit handler template.", + "workflows.argoproj.io/version": ">= 3.1.0", + }, + ) as w: + output = Script( + name="output", + image="python:alpine3.6", + command=["python"], + source=_output, + outputs=[Artifact(name="result", path="/result.txt")], + add_cwd_to_sys_path=False, + ) + exit_ = Container( + name="exit", + image="python:alpine3.6", + command=["sh", "-c"], + args=["cat /tmp/message"], + inputs=[Artifact(name="message", path="/tmp/message")], ) -``` + with Steps(name="main"): + Step( + name="step-1", + template=output, + hooks={ + "exit": m.LifecycleHook( + template="exit", + arguments=m.Arguments( + artifacts=[ + m.Artifact( + name="message", + from_="{{steps.step-1.outputs.artifacts.result}}", + ) + ], + ), + ) + }, + ) + ``` -## YAML +=== "YAML" + + ```yaml linenums="1" + apiVersion: argoproj.io/v1alpha1 + kind: Workflow + metadata: + annotations: + workflows.argoproj.io/description: onExitTemplate enables workflow to pass the + arguments (parameters/Artifacts) to exit handler template. + workflows.argoproj.io/version: '>= 3.1.0' + generateName: exit-handler-with-artifacts- + labels: + workflows.argoproj.io/test: 'true' + spec: + entrypoint: main + templates: + - name: output + outputs: + artifacts: + - name: result + path: /result.txt + script: + command: + - python + image: python:alpine3.6 + source: "with open(\"result.txt\", \"w\") as f:\n f.write(\"Welcome\")\n" + - container: + args: + - cat /tmp/message + command: + - sh + - -c + image: python:alpine3.6 + inputs: + artifacts: + - name: message + path: /tmp/message + name: exit + - name: main + steps: + - - hooks: + exit: + arguments: + artifacts: + - from: '{{steps.step-1.outputs.artifacts.result}}' + name: message + template: exit + name: step-1 + template: output + ``` -```yaml -apiVersion: argoproj.io/v1alpha1 -kind: Workflow -metadata: - annotations: - workflows.argoproj.io/description: onExitTemplate enables workflow to pass the - arguments (parameters/Artifacts) to exit handler template. - workflows.argoproj.io/version: '>= 3.1.0' - generateName: exit-handler-with-artifacts- - labels: - workflows.argoproj.io/test: 'true' -spec: - entrypoint: main - templates: - - name: output - outputs: - artifacts: - - name: result - path: /result.txt - script: - command: - - python - image: python:alpine3.6 - source: "with open(\"result.txt\", \"w\") as f:\n f.write(\"Welcome\")\n" - - container: - args: - - cat /tmp/message - command: - - sh - - -c - image: python:alpine3.6 - inputs: - artifacts: - - name: message - path: /tmp/message - name: exit - - name: main - steps: - - - hooks: - exit: - arguments: - artifacts: - - from: '{{steps.step-1.outputs.artifacts.result}}' - name: message - template: exit - name: step-1 - template: output -``` diff --git a/docs/examples/workflows/upstream/hdfs_artifact.md b/docs/examples/workflows/upstream/hdfs_artifact.md index b2d6fae86..3141e1c7e 100644 --- a/docs/examples/workflows/upstream/hdfs_artifact.md +++ b/docs/examples/workflows/upstream/hdfs_artifact.md @@ -4,123 +4,125 @@ -## Hera -```python -from hera.workflows import ( - Artifact, - Container, - HDFSArtifact, - Step, - Steps, - Workflow, -) +=== "Hera" -with Workflow(generate_name="hdfs-artifact-", entrypoint="artifact-example") as w: - whalesay = Container( - name="whalesay", - command=["sh", "-c"], - args=["cowsay hello world | tee /tmp/hello_world.txt"], - image="docker/whalesay:latest", - outputs=[ - HDFSArtifact( - name="hello-art", - path="/tmp/hello_world.txt", - addresses=[ - "my-hdfs-namenode-0.my-hdfs-namenode.default.svc.cluster.local:8020", - "my-hdfs-namenode-1.my-hdfs-namenode.default.svc.cluster.local:8020", - ], - hdfs_path="/tmp/argo/foo", - hdfs_user="root", - force=True, - ) - ], - ) - print_message = Container( - name="print-message", - image="alpine:latest", - command=["sh", "-c"], - args=["cat /tmp/message"], - inputs=[ - HDFSArtifact( - name="message", - path="/tmp/message", - addresses=[ - "my-hdfs-namenode-0.my-hdfs-namenode.default.svc.cluster.local:8020", - "my-hdfs-namenode-1.my-hdfs-namenode.default.svc.cluster.local:8020", - ], - hdfs_path="/tmp/argo/foo", - hdfs_user="root", - force=True, - ) - ], + ```python linenums="1" + from hera.workflows import ( + Artifact, + Container, + HDFSArtifact, + Step, + Steps, + Workflow, ) - with Steps(name="artifact-example") as s: - Step(name="generate-artifact", template=whalesay) - Step( - name="consume-artifact", - template=print_message, - arguments=[Artifact(name="message", from_="{{steps.generate-artifact.outputs.artifacts.hello-art}}")], + with Workflow(generate_name="hdfs-artifact-", entrypoint="artifact-example") as w: + whalesay = Container( + name="whalesay", + command=["sh", "-c"], + args=["cowsay hello world | tee /tmp/hello_world.txt"], + image="docker/whalesay:latest", + outputs=[ + HDFSArtifact( + name="hello-art", + path="/tmp/hello_world.txt", + addresses=[ + "my-hdfs-namenode-0.my-hdfs-namenode.default.svc.cluster.local:8020", + "my-hdfs-namenode-1.my-hdfs-namenode.default.svc.cluster.local:8020", + ], + hdfs_path="/tmp/argo/foo", + hdfs_user="root", + force=True, + ) + ], + ) + print_message = Container( + name="print-message", + image="alpine:latest", + command=["sh", "-c"], + args=["cat /tmp/message"], + inputs=[ + HDFSArtifact( + name="message", + path="/tmp/message", + addresses=[ + "my-hdfs-namenode-0.my-hdfs-namenode.default.svc.cluster.local:8020", + "my-hdfs-namenode-1.my-hdfs-namenode.default.svc.cluster.local:8020", + ], + hdfs_path="/tmp/argo/foo", + hdfs_user="root", + force=True, + ) + ], ) -``` -## YAML + with Steps(name="artifact-example") as s: + Step(name="generate-artifact", template=whalesay) + Step( + name="consume-artifact", + template=print_message, + arguments=[Artifact(name="message", from_="{{steps.generate-artifact.outputs.artifacts.hello-art}}")], + ) + ``` + +=== "YAML" -```yaml -apiVersion: argoproj.io/v1alpha1 -kind: Workflow -metadata: - generateName: hdfs-artifact- -spec: - entrypoint: artifact-example - templates: - - container: - args: - - cowsay hello world | tee /tmp/hello_world.txt - command: - - sh - - -c - image: docker/whalesay:latest - name: whalesay - outputs: - artifacts: - - hdfs: - addresses: - - my-hdfs-namenode-0.my-hdfs-namenode.default.svc.cluster.local:8020 - - my-hdfs-namenode-1.my-hdfs-namenode.default.svc.cluster.local:8020 - force: true - hdfsUser: root - path: /tmp/argo/foo - name: hello-art - path: /tmp/hello_world.txt - - container: - args: - - cat /tmp/message - command: - - sh - - -c - image: alpine:latest - inputs: - artifacts: - - hdfs: - addresses: - - my-hdfs-namenode-0.my-hdfs-namenode.default.svc.cluster.local:8020 - - my-hdfs-namenode-1.my-hdfs-namenode.default.svc.cluster.local:8020 - force: true - hdfsUser: root - path: /tmp/argo/foo - name: message - path: /tmp/message - name: print-message - - name: artifact-example - steps: - - - name: generate-artifact - template: whalesay - - - arguments: + ```yaml linenums="1" + apiVersion: argoproj.io/v1alpha1 + kind: Workflow + metadata: + generateName: hdfs-artifact- + spec: + entrypoint: artifact-example + templates: + - container: + args: + - cowsay hello world | tee /tmp/hello_world.txt + command: + - sh + - -c + image: docker/whalesay:latest + name: whalesay + outputs: artifacts: - - from: '{{steps.generate-artifact.outputs.artifacts.hello-art}}' + - hdfs: + addresses: + - my-hdfs-namenode-0.my-hdfs-namenode.default.svc.cluster.local:8020 + - my-hdfs-namenode-1.my-hdfs-namenode.default.svc.cluster.local:8020 + force: true + hdfsUser: root + path: /tmp/argo/foo + name: hello-art + path: /tmp/hello_world.txt + - container: + args: + - cat /tmp/message + command: + - sh + - -c + image: alpine:latest + inputs: + artifacts: + - hdfs: + addresses: + - my-hdfs-namenode-0.my-hdfs-namenode.default.svc.cluster.local:8020 + - my-hdfs-namenode-1.my-hdfs-namenode.default.svc.cluster.local:8020 + force: true + hdfsUser: root + path: /tmp/argo/foo name: message - name: consume-artifact - template: print-message -``` + path: /tmp/message + name: print-message + - name: artifact-example + steps: + - - name: generate-artifact + template: whalesay + - - arguments: + artifacts: + - from: '{{steps.generate-artifact.outputs.artifacts.hello-art}}' + name: message + name: consume-artifact + template: print-message + ``` + diff --git a/docs/examples/workflows/upstream/input_artifact_azure.md b/docs/examples/workflows/upstream/input_artifact_azure.md index 8ad35a4f3..a9b404948 100644 --- a/docs/examples/workflows/upstream/input_artifact_azure.md +++ b/docs/examples/workflows/upstream/input_artifact_azure.md @@ -4,67 +4,69 @@ -## Hera -```python -from hera.workflows import ( - AzureArtifact, - Container, - Workflow, - models as m, -) +=== "Hera" -# the example is accidentally named input-artifact-s3-... upstream, keeping here for testing/consistency. Note that -# the Azure artifact is set correctly -with Workflow(generate_name="input-artifact-s3-", entrypoint="input-artifact-s3-example") as w: - Container( - name="input-artifact-s3-example", - image="debian:latest", - command=["sh", "-c"], - args=["ls -l /my-artifact"], - inputs=[ - AzureArtifact( - name="my-art", - path="/my-artifact", - endpoint="https://myazurestorageaccountname.blob.core.windows.net", - container="my-container", - blob="path/in/container", - account_key_secret=m.SecretKeySelector( - name="my-azure-credentials", - key="accountKey", - ), - ) - ], + ```python linenums="1" + from hera.workflows import ( + AzureArtifact, + Container, + Workflow, + models as m, ) -``` -## YAML + # the example is accidentally named input-artifact-s3-... upstream, keeping here for testing/consistency. Note that + # the Azure artifact is set correctly + with Workflow(generate_name="input-artifact-s3-", entrypoint="input-artifact-s3-example") as w: + Container( + name="input-artifact-s3-example", + image="debian:latest", + command=["sh", "-c"], + args=["ls -l /my-artifact"], + inputs=[ + AzureArtifact( + name="my-art", + path="/my-artifact", + endpoint="https://myazurestorageaccountname.blob.core.windows.net", + container="my-container", + blob="path/in/container", + account_key_secret=m.SecretKeySelector( + name="my-azure-credentials", + key="accountKey", + ), + ) + ], + ) + ``` + +=== "YAML" + + ```yaml linenums="1" + apiVersion: argoproj.io/v1alpha1 + kind: Workflow + metadata: + generateName: input-artifact-s3- + spec: + entrypoint: input-artifact-s3-example + templates: + - container: + args: + - ls -l /my-artifact + command: + - sh + - -c + image: debian:latest + inputs: + artifacts: + - azure: + accountKeySecret: + key: accountKey + name: my-azure-credentials + blob: path/in/container + container: my-container + endpoint: https://myazurestorageaccountname.blob.core.windows.net + name: my-art + path: /my-artifact + name: input-artifact-s3-example + ``` -```yaml -apiVersion: argoproj.io/v1alpha1 -kind: Workflow -metadata: - generateName: input-artifact-s3- -spec: - entrypoint: input-artifact-s3-example - templates: - - container: - args: - - ls -l /my-artifact - command: - - sh - - -c - image: debian:latest - inputs: - artifacts: - - azure: - accountKeySecret: - key: accountKey - name: my-azure-credentials - blob: path/in/container - container: my-container - endpoint: https://myazurestorageaccountname.blob.core.windows.net - name: my-art - path: /my-artifact - name: input-artifact-s3-example -``` diff --git a/docs/examples/workflows/upstream/input_artifact_gcs.md b/docs/examples/workflows/upstream/input_artifact_gcs.md index 896f07030..d9d05ce38 100644 --- a/docs/examples/workflows/upstream/input_artifact_gcs.md +++ b/docs/examples/workflows/upstream/input_artifact_gcs.md @@ -4,63 +4,65 @@ -## Hera -```python -from hera.workflows import ( - Container, - GCSArtifact, - Workflow, - models as m, -) +=== "Hera" -with Workflow(generate_name="input-artifact-gcs-", entrypoint="input-artifact-gcs-example") as w: - Container( - name="input-artifact-gcs-example", - image="debian:latest", - command=["sh", "-c"], - args=["ls -l /my-artifact"], - inputs=[ - GCSArtifact( - name="my-art", - path="/my-artifact", - bucket="my-bucket-name", - key="path/in/bucket", - service_account_key_secret=m.SecretKeySelector( - name="my-gcs-credentials", - key="serviceAccountKey", - ), - ), - ], + ```python linenums="1" + from hera.workflows import ( + Container, + GCSArtifact, + Workflow, + models as m, ) -``` -## YAML + with Workflow(generate_name="input-artifact-gcs-", entrypoint="input-artifact-gcs-example") as w: + Container( + name="input-artifact-gcs-example", + image="debian:latest", + command=["sh", "-c"], + args=["ls -l /my-artifact"], + inputs=[ + GCSArtifact( + name="my-art", + path="/my-artifact", + bucket="my-bucket-name", + key="path/in/bucket", + service_account_key_secret=m.SecretKeySelector( + name="my-gcs-credentials", + key="serviceAccountKey", + ), + ), + ], + ) + ``` + +=== "YAML" + + ```yaml linenums="1" + apiVersion: argoproj.io/v1alpha1 + kind: Workflow + metadata: + generateName: input-artifact-gcs- + spec: + entrypoint: input-artifact-gcs-example + templates: + - container: + args: + - ls -l /my-artifact + command: + - sh + - -c + image: debian:latest + inputs: + artifacts: + - gcs: + bucket: my-bucket-name + key: path/in/bucket + serviceAccountKeySecret: + key: serviceAccountKey + name: my-gcs-credentials + name: my-art + path: /my-artifact + name: input-artifact-gcs-example + ``` -```yaml -apiVersion: argoproj.io/v1alpha1 -kind: Workflow -metadata: - generateName: input-artifact-gcs- -spec: - entrypoint: input-artifact-gcs-example - templates: - - container: - args: - - ls -l /my-artifact - command: - - sh - - -c - image: debian:latest - inputs: - artifacts: - - gcs: - bucket: my-bucket-name - key: path/in/bucket - serviceAccountKeySecret: - key: serviceAccountKey - name: my-gcs-credentials - name: my-art - path: /my-artifact - name: input-artifact-gcs-example -``` diff --git a/docs/examples/workflows/upstream/input_artifact_git.md b/docs/examples/workflows/upstream/input_artifact_git.md index 303d8ef12..ed874d97f 100644 --- a/docs/examples/workflows/upstream/input_artifact_git.md +++ b/docs/examples/workflows/upstream/input_artifact_git.md @@ -4,57 +4,59 @@ -## Hera - -```python -from hera.workflows import ( - Container, - GitArtifact, - Workflow, -) - -with Workflow(generate_name="input-artifact-git-", entrypoint="git-clone") as w: - Container( - name="git-clone", - image="golang:1.10", - command=["sh", "-c"], - args=["git status && ls && cat VERSION"], - working_dir="/src", - inputs=[ - GitArtifact( - name="argo-source", - path="/src", - repo="https://github.com/argoproj/argo-workflows.git", - revision="v2.1.1", - ), - ], + +=== "Hera" + + ```python linenums="1" + from hera.workflows import ( + Container, + GitArtifact, + Workflow, ) -``` - -## YAML - -```yaml -apiVersion: argoproj.io/v1alpha1 -kind: Workflow -metadata: - generateName: input-artifact-git- -spec: - entrypoint: git-clone - templates: - - container: - args: - - git status && ls && cat VERSION - command: - - sh - - -c - image: golang:1.10 - workingDir: /src - inputs: - artifacts: - - git: - repo: https://github.com/argoproj/argo-workflows.git - revision: v2.1.1 - name: argo-source - path: /src - name: git-clone -``` + + with Workflow(generate_name="input-artifact-git-", entrypoint="git-clone") as w: + Container( + name="git-clone", + image="golang:1.10", + command=["sh", "-c"], + args=["git status && ls && cat VERSION"], + working_dir="/src", + inputs=[ + GitArtifact( + name="argo-source", + path="/src", + repo="https://github.com/argoproj/argo-workflows.git", + revision="v2.1.1", + ), + ], + ) + ``` + +=== "YAML" + + ```yaml linenums="1" + apiVersion: argoproj.io/v1alpha1 + kind: Workflow + metadata: + generateName: input-artifact-git- + spec: + entrypoint: git-clone + templates: + - container: + args: + - git status && ls && cat VERSION + command: + - sh + - -c + image: golang:1.10 + workingDir: /src + inputs: + artifacts: + - git: + repo: https://github.com/argoproj/argo-workflows.git + revision: v2.1.1 + name: argo-source + path: /src + name: git-clone + ``` + diff --git a/docs/examples/workflows/upstream/input_artifact_http.md b/docs/examples/workflows/upstream/input_artifact_http.md index 16db49819..5b13a2bdb 100644 --- a/docs/examples/workflows/upstream/input_artifact_http.md +++ b/docs/examples/workflows/upstream/input_artifact_http.md @@ -4,51 +4,53 @@ -## Hera - -```python -from hera.workflows import Container, HTTPArtifact, Workflow - -with Workflow(generate_name="input-artifact-http-", entrypoint="http-artifact-example") as w: - Container( - name="http-artifact-example", - image="debian:9.4", - command=["sh", "-c"], - args=["kubectl version"], - inputs=[ - HTTPArtifact( - name="kubectl", - path="/bin/kubectl", - mode=493, - url="https://storage.googleapis.com/kubernetes-release/release/v1.8.0/bin/linux/amd64/kubectl", - ), - ], - ) -``` - -## YAML - -```yaml -apiVersion: argoproj.io/v1alpha1 -kind: Workflow -metadata: - generateName: input-artifact-http- -spec: - entrypoint: http-artifact-example - templates: - - container: - args: - - kubectl version - command: - - sh - - -c - image: debian:9.4 - inputs: - artifacts: - - http: - url: https://storage.googleapis.com/kubernetes-release/release/v1.8.0/bin/linux/amd64/kubectl - mode: 493 - name: kubectl - path: /bin/kubectl - name: http-artifact-example -``` + +=== "Hera" + + ```python linenums="1" + from hera.workflows import Container, HTTPArtifact, Workflow + + with Workflow(generate_name="input-artifact-http-", entrypoint="http-artifact-example") as w: + Container( + name="http-artifact-example", + image="debian:9.4", + command=["sh", "-c"], + args=["kubectl version"], + inputs=[ + HTTPArtifact( + name="kubectl", + path="/bin/kubectl", + mode=493, + url="https://storage.googleapis.com/kubernetes-release/release/v1.8.0/bin/linux/amd64/kubectl", + ), + ], + ) + ``` + +=== "YAML" + + ```yaml linenums="1" + apiVersion: argoproj.io/v1alpha1 + kind: Workflow + metadata: + generateName: input-artifact-http- + spec: + entrypoint: http-artifact-example + templates: + - container: + args: + - kubectl version + command: + - sh + - -c + image: debian:9.4 + inputs: + artifacts: + - http: + url: https://storage.googleapis.com/kubernetes-release/release/v1.8.0/bin/linux/amd64/kubectl + mode: 493 + name: kubectl + path: /bin/kubectl + name: http-artifact-example + ``` + diff --git a/docs/examples/workflows/upstream/input_artifact_oss.md b/docs/examples/workflows/upstream/input_artifact_oss.md index 855a0791b..ade12884c 100644 --- a/docs/examples/workflows/upstream/input_artifact_oss.md +++ b/docs/examples/workflows/upstream/input_artifact_oss.md @@ -4,72 +4,74 @@ -## Hera -```python -from hera.workflows import ( - Container, - OSSArtifact, - Workflow, - models as m, -) +=== "Hera" -with Workflow(generate_name="input-artifact-oss-", entrypoint="input-artifact-oss-example") as w: - Container( - name="input-artifact-oss-example", - image="debian:latest", - command=["sh", "-c"], - args=["ls -l /my-artifact"], - inputs=[ - OSSArtifact( - name="my-art", - path="/my-artifact", - endpoint="http://oss-cn-hangzhou-zmf.aliyuncs.com", - bucket="test-bucket-name", - key="test/mydirectory/", - access_key_secret=m.SecretKeySelector( - name="my-oss-credentials", - key="accessKey", - ), - secret_key_secret=m.SecretKeySelector( - name="my-oss-credentials", - key="secretKey", - ), - ) - ], + ```python linenums="1" + from hera.workflows import ( + Container, + OSSArtifact, + Workflow, + models as m, ) -``` -## YAML + with Workflow(generate_name="input-artifact-oss-", entrypoint="input-artifact-oss-example") as w: + Container( + name="input-artifact-oss-example", + image="debian:latest", + command=["sh", "-c"], + args=["ls -l /my-artifact"], + inputs=[ + OSSArtifact( + name="my-art", + path="/my-artifact", + endpoint="http://oss-cn-hangzhou-zmf.aliyuncs.com", + bucket="test-bucket-name", + key="test/mydirectory/", + access_key_secret=m.SecretKeySelector( + name="my-oss-credentials", + key="accessKey", + ), + secret_key_secret=m.SecretKeySelector( + name="my-oss-credentials", + key="secretKey", + ), + ) + ], + ) + ``` + +=== "YAML" + + ```yaml linenums="1" + apiVersion: argoproj.io/v1alpha1 + kind: Workflow + metadata: + generateName: input-artifact-oss- + spec: + entrypoint: input-artifact-oss-example + templates: + - container: + args: + - ls -l /my-artifact + command: + - sh + - -c + image: debian:latest + inputs: + artifacts: + - name: my-art + oss: + accessKeySecret: + key: accessKey + name: my-oss-credentials + bucket: test-bucket-name + endpoint: http://oss-cn-hangzhou-zmf.aliyuncs.com + key: test/mydirectory/ + secretKeySecret: + key: secretKey + name: my-oss-credentials + path: /my-artifact + name: input-artifact-oss-example + ``` -```yaml -apiVersion: argoproj.io/v1alpha1 -kind: Workflow -metadata: - generateName: input-artifact-oss- -spec: - entrypoint: input-artifact-oss-example - templates: - - container: - args: - - ls -l /my-artifact - command: - - sh - - -c - image: debian:latest - inputs: - artifacts: - - name: my-art - oss: - accessKeySecret: - key: accessKey - name: my-oss-credentials - bucket: test-bucket-name - endpoint: http://oss-cn-hangzhou-zmf.aliyuncs.com - key: test/mydirectory/ - secretKeySecret: - key: secretKey - name: my-oss-credentials - path: /my-artifact - name: input-artifact-oss-example -``` diff --git a/docs/examples/workflows/upstream/input_artifact_raw.md b/docs/examples/workflows/upstream/input_artifact_raw.md index fc3e4c043..b01e7a105 100644 --- a/docs/examples/workflows/upstream/input_artifact_raw.md +++ b/docs/examples/workflows/upstream/input_artifact_raw.md @@ -4,55 +4,57 @@ -## Hera - -```python -from hera.workflows import Container, RawArtifact, Workflow - -with Workflow(generate_name="input-artifact-raw-", entrypoint="raw-contents") as w: - Container( - name="raw-contents", - image="alpine:latest", - command=["sh", "-c"], - args=["cat /tmp/file"], - inputs=[ - RawArtifact( - name="myfile", - path="/tmp/file", - data="this is\nthe raw file\ncontents\n", - ) - ], - ) -``` - -## YAML - -```yaml -apiVersion: argoproj.io/v1alpha1 -kind: Workflow -metadata: - generateName: input-artifact-raw- -spec: - entrypoint: raw-contents - templates: - - container: - args: - - cat /tmp/file - command: - - sh - - -c - image: alpine:latest - inputs: - artifacts: - - name: myfile - path: /tmp/file - raw: - data: 'this is - - the raw file - - contents - - ' - name: raw-contents -``` + +=== "Hera" + + ```python linenums="1" + from hera.workflows import Container, RawArtifact, Workflow + + with Workflow(generate_name="input-artifact-raw-", entrypoint="raw-contents") as w: + Container( + name="raw-contents", + image="alpine:latest", + command=["sh", "-c"], + args=["cat /tmp/file"], + inputs=[ + RawArtifact( + name="myfile", + path="/tmp/file", + data="this is\nthe raw file\ncontents\n", + ) + ], + ) + ``` + +=== "YAML" + + ```yaml linenums="1" + apiVersion: argoproj.io/v1alpha1 + kind: Workflow + metadata: + generateName: input-artifact-raw- + spec: + entrypoint: raw-contents + templates: + - container: + args: + - cat /tmp/file + command: + - sh + - -c + image: alpine:latest + inputs: + artifacts: + - name: myfile + path: /tmp/file + raw: + data: 'this is + + the raw file + + contents + + ' + name: raw-contents + ``` + diff --git a/docs/examples/workflows/upstream/input_artifact_s3.md b/docs/examples/workflows/upstream/input_artifact_s3.md index 7e28f2bdb..a81f43411 100644 --- a/docs/examples/workflows/upstream/input_artifact_s3.md +++ b/docs/examples/workflows/upstream/input_artifact_s3.md @@ -4,74 +4,76 @@ -## Hera -```python -from hera.workflows import ( - Container, - S3Artifact, - Workflow, - models as m, -) +=== "Hera" -with Workflow(generate_name="input-artifact-s3-", entrypoint="input-artifact-s3-example") as w: - Container( - name="input-artifact-s3-example", - image="debian:latest", - command=["sh", "-c"], - args=["ls -l /my-artifact"], - inputs=[ - S3Artifact( - name="my-art", - path="/my-artifact", - endpoint="s3.amazonaws.com", - bucket="my-bucket-name", - key="path/in/bucket", - region="us-west-2", - access_key_secret=m.SecretKeySelector( - name="my-s3-credentials", - key="accessKey", - ), - secret_key_secret=m.SecretKeySelector( - name="my-s3-credentials", - key="secretKey", - ), - ), - ], + ```python linenums="1" + from hera.workflows import ( + Container, + S3Artifact, + Workflow, + models as m, ) -``` -## YAML + with Workflow(generate_name="input-artifact-s3-", entrypoint="input-artifact-s3-example") as w: + Container( + name="input-artifact-s3-example", + image="debian:latest", + command=["sh", "-c"], + args=["ls -l /my-artifact"], + inputs=[ + S3Artifact( + name="my-art", + path="/my-artifact", + endpoint="s3.amazonaws.com", + bucket="my-bucket-name", + key="path/in/bucket", + region="us-west-2", + access_key_secret=m.SecretKeySelector( + name="my-s3-credentials", + key="accessKey", + ), + secret_key_secret=m.SecretKeySelector( + name="my-s3-credentials", + key="secretKey", + ), + ), + ], + ) + ``` + +=== "YAML" + + ```yaml linenums="1" + apiVersion: argoproj.io/v1alpha1 + kind: Workflow + metadata: + generateName: input-artifact-s3- + spec: + entrypoint: input-artifact-s3-example + templates: + - container: + args: + - ls -l /my-artifact + command: + - sh + - -c + image: debian:latest + inputs: + artifacts: + - name: my-art + path: /my-artifact + s3: + accessKeySecret: + key: accessKey + name: my-s3-credentials + bucket: my-bucket-name + endpoint: s3.amazonaws.com + key: path/in/bucket + region: us-west-2 + secretKeySecret: + key: secretKey + name: my-s3-credentials + name: input-artifact-s3-example + ``` -```yaml -apiVersion: argoproj.io/v1alpha1 -kind: Workflow -metadata: - generateName: input-artifact-s3- -spec: - entrypoint: input-artifact-s3-example - templates: - - container: - args: - - ls -l /my-artifact - command: - - sh - - -c - image: debian:latest - inputs: - artifacts: - - name: my-art - path: /my-artifact - s3: - accessKeySecret: - key: accessKey - name: my-s3-credentials - bucket: my-bucket-name - endpoint: s3.amazonaws.com - key: path/in/bucket - region: us-west-2 - secretKeySecret: - key: secretKey - name: my-s3-credentials - name: input-artifact-s3-example -``` diff --git a/docs/examples/workflows/upstream/k8s_resource_log_selector.md b/docs/examples/workflows/upstream/k8s_resource_log_selector.md index 3caac8add..1924a15d0 100644 --- a/docs/examples/workflows/upstream/k8s_resource_log_selector.md +++ b/docs/examples/workflows/upstream/k8s_resource_log_selector.md @@ -4,78 +4,80 @@ -## Hera -```python -from hera.workflows import Resource, Workflow +=== "Hera" -with Workflow(generate_name="k8s-jobs-log-selector-", entrypoint="tf-jobtmpl") as w: - tf_jobtmpl = Resource( - name="tf-jobtmpl", - action="create", - success_condition="status.replicaStatuses.Worker.succeeded = 2", - failure_condition="status.replicaStatuses.Worker.failed > 0", - manifest=r"""apiVersion: kubeflow.org/v1 -kind: TFJob -metadata: - name: tfjob-examples -spec: - tfReplicaSpecs: - Worker: - replicas: 2 - restartPolicy: Never - template: - metadata: - # We add this label to the pods created by TFJob custom resource to inform Argo Workflows - # that we want to include the logs from the created pods. Once the pods are created with this - # label, you can then use `argo logs -c tensorflow` to the logs from this particular container. - # Note that `workflow.name` is a supported global variable provided by Argo Workflows. - # - # The Kubeflow training controller will take this CRD and automatically created worker pods with - # labels, such as `job-role` and `replica-index`. If you'd like to query logs for pods with - # specific labels, you can specify the label selector explicitly via `argo logs -l `. - # For example, you can use `argo logs -c tensorflow -l replica-index=0` to see the first worker pod's logs. - labels: - workflows.argoproj.io/workflow: {{workflow.name}} - spec: - containers: - - name: tensorflow - image: "Placeholder for TensorFlow distributed training image" -""", - ) -``` + ```python linenums="1" + from hera.workflows import Resource, Workflow -## YAML + with Workflow(generate_name="k8s-jobs-log-selector-", entrypoint="tf-jobtmpl") as w: + tf_jobtmpl = Resource( + name="tf-jobtmpl", + action="create", + success_condition="status.replicaStatuses.Worker.succeeded = 2", + failure_condition="status.replicaStatuses.Worker.failed > 0", + manifest=r"""apiVersion: kubeflow.org/v1 + kind: TFJob + metadata: + name: tfjob-examples + spec: + tfReplicaSpecs: + Worker: + replicas: 2 + restartPolicy: Never + template: + metadata: + # We add this label to the pods created by TFJob custom resource to inform Argo Workflows + # that we want to include the logs from the created pods. Once the pods are created with this + # label, you can then use `argo logs -c tensorflow` to the logs from this particular container. + # Note that `workflow.name` is a supported global variable provided by Argo Workflows. + # + # The Kubeflow training controller will take this CRD and automatically created worker pods with + # labels, such as `job-role` and `replica-index`. If you'd like to query logs for pods with + # specific labels, you can specify the label selector explicitly via `argo logs -l `. + # For example, you can use `argo logs -c tensorflow -l replica-index=0` to see the first worker pod's logs. + labels: + workflows.argoproj.io/workflow: {{workflow.name}} + spec: + containers: + - name: tensorflow + image: "Placeholder for TensorFlow distributed training image" + """, + ) + ``` + +=== "YAML" + + ```yaml linenums="1" + apiVersion: argoproj.io/v1alpha1 + kind: Workflow + metadata: + generateName: k8s-jobs-log-selector- + spec: + entrypoint: tf-jobtmpl + templates: + - name: tf-jobtmpl + resource: + action: create + failureCondition: status.replicaStatuses.Worker.failed > 0 + manifest: "apiVersion: kubeflow.org/v1\nkind: TFJob\nmetadata:\n name: tfjob-examples\n\ + spec:\n tfReplicaSpecs:\n Worker:\n replicas: 2\n restartPolicy:\ + \ Never\n template:\n metadata:\n # We add this label\ + \ to the pods created by TFJob custom resource to inform Argo Workflows\n\ + \ # that we want to include the logs from the created pods. Once\ + \ the pods are created with this\n # label, you can then use `argo\ + \ logs -c tensorflow` to the logs from this particular container.\n \ + \ # Note that `workflow.name` is a supported global variable provided\ + \ by Argo Workflows.\n #\n # The Kubeflow training controller\ + \ will take this CRD and automatically created worker pods with\n \ + \ # labels, such as `job-role` and `replica-index`. If you'd like to query\ + \ logs for pods with\n # specific labels, you can specify the label\ + \ selector explicitly via `argo logs -l `.\n \ + \ # For example, you can use `argo logs -c tensorflow -l replica-index=0`\ + \ to see the first worker pod's logs.\n labels:\n workflows.argoproj.io/workflow:\ + \ {{workflow.name}}\n spec:\n containers:\n \ + \ - name: tensorflow\n image: \"Placeholder for TensorFlow distributed\ + \ training image\"\n" + successCondition: status.replicaStatuses.Worker.succeeded = 2 + ``` -```yaml -apiVersion: argoproj.io/v1alpha1 -kind: Workflow -metadata: - generateName: k8s-jobs-log-selector- -spec: - entrypoint: tf-jobtmpl - templates: - - name: tf-jobtmpl - resource: - action: create - failureCondition: status.replicaStatuses.Worker.failed > 0 - manifest: "apiVersion: kubeflow.org/v1\nkind: TFJob\nmetadata:\n name: tfjob-examples\n\ - spec:\n tfReplicaSpecs:\n Worker:\n replicas: 2\n restartPolicy:\ - \ Never\n template:\n metadata:\n # We add this label\ - \ to the pods created by TFJob custom resource to inform Argo Workflows\n\ - \ # that we want to include the logs from the created pods. Once\ - \ the pods are created with this\n # label, you can then use `argo\ - \ logs -c tensorflow` to the logs from this particular container.\n \ - \ # Note that `workflow.name` is a supported global variable provided\ - \ by Argo Workflows.\n #\n # The Kubeflow training controller\ - \ will take this CRD and automatically created worker pods with\n \ - \ # labels, such as `job-role` and `replica-index`. If you'd like to query\ - \ logs for pods with\n # specific labels, you can specify the label\ - \ selector explicitly via `argo logs -l `.\n \ - \ # For example, you can use `argo logs -c tensorflow -l replica-index=0`\ - \ to see the first worker pod's logs.\n labels:\n workflows.argoproj.io/workflow:\ - \ {{workflow.name}}\n spec:\n containers:\n \ - \ - name: tensorflow\n image: \"Placeholder for TensorFlow distributed\ - \ training image\"\n" - successCondition: status.replicaStatuses.Worker.succeeded = 2 -``` diff --git a/docs/examples/workflows/upstream/key_only_artifact.md b/docs/examples/workflows/upstream/key_only_artifact.md index 7ec6ef2a2..a60a62a04 100644 --- a/docs/examples/workflows/upstream/key_only_artifact.md +++ b/docs/examples/workflows/upstream/key_only_artifact.md @@ -4,82 +4,84 @@ -## Hera -```python -from hera.workflows import DAG, Container, S3Artifact, Task, Workflow +=== "Hera" -with Workflow(generate_name="key-only-artifacts-", entrypoint="main") as w: - generate = Container( - name="generate", - image="argoproj/argosay:v2", - args=["echo", "hello", "/mnt/file"], - outputs=[ - S3Artifact( - name="file", - path="/mnt/file", - key="my-file", - ), - ], - ) - consume = Container( - name="consume", - image="argoproj/argosay:v2", - args=["cat", "/tmp/file"], - inputs=[ - S3Artifact( - name="file", - path="/tmp/file", - key="my-file", - ) - ], - ) + ```python linenums="1" + from hera.workflows import DAG, Container, S3Artifact, Task, Workflow - with DAG(name="main"): - Task(name="generate", template=generate) >> Task(name="consume", template=consume) -``` + with Workflow(generate_name="key-only-artifacts-", entrypoint="main") as w: + generate = Container( + name="generate", + image="argoproj/argosay:v2", + args=["echo", "hello", "/mnt/file"], + outputs=[ + S3Artifact( + name="file", + path="/mnt/file", + key="my-file", + ), + ], + ) + consume = Container( + name="consume", + image="argoproj/argosay:v2", + args=["cat", "/tmp/file"], + inputs=[ + S3Artifact( + name="file", + path="/tmp/file", + key="my-file", + ) + ], + ) -## YAML + with DAG(name="main"): + Task(name="generate", template=generate) >> Task(name="consume", template=consume) + ``` -```yaml -apiVersion: argoproj.io/v1alpha1 -kind: Workflow -metadata: - generateName: key-only-artifacts- -spec: - entrypoint: main - templates: - - container: - args: - - echo - - hello - - /mnt/file - image: argoproj/argosay:v2 - name: generate - outputs: - artifacts: - - name: file - path: /mnt/file - s3: - key: my-file - - container: - args: - - cat - - /tmp/file - image: argoproj/argosay:v2 - inputs: - artifacts: - - name: file - path: /tmp/file - s3: - key: my-file - name: consume - - dag: - tasks: - - name: generate - template: generate - - depends: generate +=== "YAML" + + ```yaml linenums="1" + apiVersion: argoproj.io/v1alpha1 + kind: Workflow + metadata: + generateName: key-only-artifacts- + spec: + entrypoint: main + templates: + - container: + args: + - echo + - hello + - /mnt/file + image: argoproj/argosay:v2 + name: generate + outputs: + artifacts: + - name: file + path: /mnt/file + s3: + key: my-file + - container: + args: + - cat + - /tmp/file + image: argoproj/argosay:v2 + inputs: + artifacts: + - name: file + path: /tmp/file + s3: + key: my-file name: consume - template: consume - name: main -``` + - dag: + tasks: + - name: generate + template: generate + - depends: generate + name: consume + template: consume + name: main + ``` + diff --git a/docs/examples/workflows/upstream/loops.md b/docs/examples/workflows/upstream/loops.md index 1dc9efa67..849241e44 100644 --- a/docs/examples/workflows/upstream/loops.md +++ b/docs/examples/workflows/upstream/loops.md @@ -4,57 +4,59 @@ -## Hera - -```python -from hera.workflows import Container, Parameter, Steps, Workflow - -with Workflow(generate_name="loops-", entrypoint="loop-example") as w: - whalesay = Container( - name="whalesay", - inputs=Parameter(name="message"), - image="docker/whalesay:latest", - command=["cowsay"], - args=["{{inputs.parameters.message}}"], - ) - - with Steps(name="loop-example"): - whalesay( - name="print-message", - arguments={"message": "{{item}}"}, - with_items=["hello world", "goodbye world"], + +=== "Hera" + + ```python linenums="1" + from hera.workflows import Container, Parameter, Steps, Workflow + + with Workflow(generate_name="loops-", entrypoint="loop-example") as w: + whalesay = Container( + name="whalesay", + inputs=Parameter(name="message"), + image="docker/whalesay:latest", + command=["cowsay"], + args=["{{inputs.parameters.message}}"], ) -``` - -## YAML - -```yaml -apiVersion: argoproj.io/v1alpha1 -kind: Workflow -metadata: - generateName: loops- -spec: - entrypoint: loop-example - templates: - - container: - args: - - '{{inputs.parameters.message}}' - command: - - cowsay - image: docker/whalesay:latest - inputs: - parameters: - - name: message - name: whalesay - - name: loop-example - steps: - - - arguments: + + with Steps(name="loop-example"): + whalesay( + name="print-message", + arguments={"message": "{{item}}"}, + with_items=["hello world", "goodbye world"], + ) + ``` + +=== "YAML" + + ```yaml linenums="1" + apiVersion: argoproj.io/v1alpha1 + kind: Workflow + metadata: + generateName: loops- + spec: + entrypoint: loop-example + templates: + - container: + args: + - '{{inputs.parameters.message}}' + command: + - cowsay + image: docker/whalesay:latest + inputs: parameters: - name: message - value: '{{item}}' - name: print-message - template: whalesay - withItems: - - hello world - - goodbye world -``` + name: whalesay + - name: loop-example + steps: + - - arguments: + parameters: + - name: message + value: '{{item}}' + name: print-message + template: whalesay + withItems: + - hello world + - goodbye world + ``` + diff --git a/docs/examples/workflows/upstream/loops_dag.md b/docs/examples/workflows/upstream/loops_dag.md index b06fa6338..baf9909c8 100644 --- a/docs/examples/workflows/upstream/loops_dag.md +++ b/docs/examples/workflows/upstream/loops_dag.md @@ -4,74 +4,76 @@ -## Hera -```python -from hera.workflows import DAG, Container, Parameter, Workflow +=== "Hera" -with Workflow( - generate_name="loops-dag-", - entrypoint="loops-dag", -) as w: - echo = Container( - name="whalesay", - image="docker/whalesay:latest", - command=["cowsay"], - args=["{{inputs.parameters.message}}"], - inputs=[Parameter(name="message")], - ) - with DAG(name="loops-dag"): - A = echo(name="A", arguments={"message": "A"}) - B = echo(name="B", arguments={"message": "{{item}}"}, with_items=["foo", "bar", "baz"]) - C = echo(name="C", arguments={"message": "C"}) - A >> B >> C -``` + ```python linenums="1" + from hera.workflows import DAG, Container, Parameter, Workflow -## YAML + with Workflow( + generate_name="loops-dag-", + entrypoint="loops-dag", + ) as w: + echo = Container( + name="whalesay", + image="docker/whalesay:latest", + command=["cowsay"], + args=["{{inputs.parameters.message}}"], + inputs=[Parameter(name="message")], + ) + with DAG(name="loops-dag"): + A = echo(name="A", arguments={"message": "A"}) + B = echo(name="B", arguments={"message": "{{item}}"}, with_items=["foo", "bar", "baz"]) + C = echo(name="C", arguments={"message": "C"}) + A >> B >> C + ``` -```yaml -apiVersion: argoproj.io/v1alpha1 -kind: Workflow -metadata: - generateName: loops-dag- -spec: - entrypoint: loops-dag - templates: - - container: - args: - - '{{inputs.parameters.message}}' - command: - - cowsay - image: docker/whalesay:latest - inputs: - parameters: - - name: message - name: whalesay - - dag: - tasks: - - arguments: - parameters: - - name: message - value: A - name: A - template: whalesay - - arguments: - parameters: - - name: message - value: '{{item}}' - depends: A - name: B - template: whalesay - withItems: - - foo - - bar - - baz - - arguments: +=== "YAML" + + ```yaml linenums="1" + apiVersion: argoproj.io/v1alpha1 + kind: Workflow + metadata: + generateName: loops-dag- + spec: + entrypoint: loops-dag + templates: + - container: + args: + - '{{inputs.parameters.message}}' + command: + - cowsay + image: docker/whalesay:latest + inputs: parameters: - name: message - value: C - depends: B - name: C - template: whalesay - name: loops-dag -``` + name: whalesay + - dag: + tasks: + - arguments: + parameters: + - name: message + value: A + name: A + template: whalesay + - arguments: + parameters: + - name: message + value: '{{item}}' + depends: A + name: B + template: whalesay + withItems: + - foo + - bar + - baz + - arguments: + parameters: + - name: message + value: C + depends: B + name: C + template: whalesay + name: loops-dag + ``` + diff --git a/docs/examples/workflows/upstream/loops_maps.md b/docs/examples/workflows/upstream/loops_maps.md index 62f620147..fe45753ed 100644 --- a/docs/examples/workflows/upstream/loops_maps.md +++ b/docs/examples/workflows/upstream/loops_maps.md @@ -4,77 +4,79 @@ -## Hera -```python -from hera.workflows import Container, Parameter, Steps, Workflow +=== "Hera" -with Workflow( - generate_name="loops-maps-", - entrypoint="loop-map-example", -) as w: - cat_os_release = Container( - name="cat-os-release", - inputs=[Parameter(name="image"), Parameter(name="tag")], - image="{{inputs.parameters.image}}:{{inputs.parameters.tag}}", - command=["cat"], - args=["/etc/os-release"], - ) + ```python linenums="1" + from hera.workflows import Container, Parameter, Steps, Workflow - with Steps(name="loop-map-example") as loop_map_example: - cat_os_release( - name="test-linux", - arguments=[ - Parameter(name="image", value="{{item.image}}"), - Parameter(name="tag", value="{{item.tag}}"), - ], - with_items=[ - {"image": "debian", "tag": "9.1"}, - {"image": "debian", "tag": "8.9"}, - {"image": "alpine", "tag": "3.6"}, - {"image": "ubuntu", "tag": "17.10"}, - ], + with Workflow( + generate_name="loops-maps-", + entrypoint="loop-map-example", + ) as w: + cat_os_release = Container( + name="cat-os-release", + inputs=[Parameter(name="image"), Parameter(name="tag")], + image="{{inputs.parameters.image}}:{{inputs.parameters.tag}}", + command=["cat"], + args=["/etc/os-release"], ) -``` -## YAML + with Steps(name="loop-map-example") as loop_map_example: + cat_os_release( + name="test-linux", + arguments=[ + Parameter(name="image", value="{{item.image}}"), + Parameter(name="tag", value="{{item.tag}}"), + ], + with_items=[ + {"image": "debian", "tag": "9.1"}, + {"image": "debian", "tag": "8.9"}, + {"image": "alpine", "tag": "3.6"}, + {"image": "ubuntu", "tag": "17.10"}, + ], + ) + ``` -```yaml -apiVersion: argoproj.io/v1alpha1 -kind: Workflow -metadata: - generateName: loops-maps- -spec: - entrypoint: loop-map-example - templates: - - container: - args: - - /etc/os-release - command: - - cat - image: '{{inputs.parameters.image}}:{{inputs.parameters.tag}}' - inputs: - parameters: - - name: image - - name: tag - name: cat-os-release - - name: loop-map-example - steps: - - - arguments: +=== "YAML" + + ```yaml linenums="1" + apiVersion: argoproj.io/v1alpha1 + kind: Workflow + metadata: + generateName: loops-maps- + spec: + entrypoint: loop-map-example + templates: + - container: + args: + - /etc/os-release + command: + - cat + image: '{{inputs.parameters.image}}:{{inputs.parameters.tag}}' + inputs: parameters: - name: image - value: '{{item.image}}' - name: tag - value: '{{item.tag}}' - name: test-linux - template: cat-os-release - withItems: - - image: debian - tag: '9.1' - - image: debian - tag: '8.9' - - image: alpine - tag: '3.6' - - image: ubuntu - tag: '17.10' -``` + name: cat-os-release + - name: loop-map-example + steps: + - - arguments: + parameters: + - name: image + value: '{{item.image}}' + - name: tag + value: '{{item.tag}}' + name: test-linux + template: cat-os-release + withItems: + - image: debian + tag: '9.1' + - image: debian + tag: '8.9' + - image: alpine + tag: '3.6' + - image: ubuntu + tag: '17.10' + ``` + diff --git a/docs/examples/workflows/upstream/loops_param_result.md b/docs/examples/workflows/upstream/loops_param_result.md index aa1247c28..265935dab 100644 --- a/docs/examples/workflows/upstream/loops_param_result.md +++ b/docs/examples/workflows/upstream/loops_param_result.md @@ -4,87 +4,89 @@ -## Hera - -```python -from hera.workflows import Container, Parameter, Steps, Workflow, script - - -@script(image="python:alpine3.6", command=["python"], add_cwd_to_sys_path=False) -def gen_number_list(): - import json - import sys - - json.dump([i for i in range(20, 31)], sys.stdout) - - -with Workflow( - generate_name="loops-param-result-", - entrypoint="loop-param-result-example", -) as w: - sleep_n_sec = Container( - name="sleep-n-sec", - inputs=Parameter(name="seconds"), - image="alpine:latest", - command=["sh", "-c"], - args=[ - "echo sleeping for {{inputs.parameters.seconds}} seconds; sleep {{inputs.parameters.seconds}}; echo done" - ], - ) - - with Steps(name="loop-param-result-example"): - g = gen_number_list(name="generate") - sleep_n_sec( - name="sleep", - arguments=Parameter(name="seconds", value="{{item}}"), - with_param=g.result, - ) -``` - -## YAML - -```yaml -apiVersion: argoproj.io/v1alpha1 -kind: Workflow -metadata: - generateName: loops-param-result- -spec: - entrypoint: loop-param-result-example - templates: - - container: - args: - - echo sleeping for {{inputs.parameters.seconds}} seconds; sleep {{inputs.parameters.seconds}}; - echo done - command: - - sh - - -c - image: alpine:latest - inputs: - parameters: - - name: seconds - name: sleep-n-sec - - name: loop-param-result-example - steps: - - - name: generate - template: gen-number-list - - - arguments: - parameters: - - name: seconds - value: '{{item}}' - name: sleep - template: sleep-n-sec - withParam: '{{steps.generate.outputs.result}}' - - name: gen-number-list - script: - command: - - python - image: python:alpine3.6 - source: 'import json - import sys +=== "Hera" + ```python linenums="1" + from hera.workflows import Container, Parameter, Steps, Workflow, script + + + @script(image="python:alpine3.6", command=["python"], add_cwd_to_sys_path=False) + def gen_number_list(): + import json + import sys json.dump([i for i in range(20, 31)], sys.stdout) - ' -``` + + with Workflow( + generate_name="loops-param-result-", + entrypoint="loop-param-result-example", + ) as w: + sleep_n_sec = Container( + name="sleep-n-sec", + inputs=Parameter(name="seconds"), + image="alpine:latest", + command=["sh", "-c"], + args=[ + "echo sleeping for {{inputs.parameters.seconds}} seconds; sleep {{inputs.parameters.seconds}}; echo done" + ], + ) + + with Steps(name="loop-param-result-example"): + g = gen_number_list(name="generate") + sleep_n_sec( + name="sleep", + arguments=Parameter(name="seconds", value="{{item}}"), + with_param=g.result, + ) + ``` + +=== "YAML" + + ```yaml linenums="1" + apiVersion: argoproj.io/v1alpha1 + kind: Workflow + metadata: + generateName: loops-param-result- + spec: + entrypoint: loop-param-result-example + templates: + - container: + args: + - echo sleeping for {{inputs.parameters.seconds}} seconds; sleep {{inputs.parameters.seconds}}; + echo done + command: + - sh + - -c + image: alpine:latest + inputs: + parameters: + - name: seconds + name: sleep-n-sec + - name: loop-param-result-example + steps: + - - name: generate + template: gen-number-list + - - arguments: + parameters: + - name: seconds + value: '{{item}}' + name: sleep + template: sleep-n-sec + withParam: '{{steps.generate.outputs.result}}' + - name: gen-number-list + script: + command: + - python + image: python:alpine3.6 + source: 'import json + + import sys + + + json.dump([i for i in range(20, 31)], sys.stdout) + + ' + ``` + diff --git a/docs/examples/workflows/upstream/output_artifact_azure.md b/docs/examples/workflows/upstream/output_artifact_azure.md index e62eb4c53..69a550582 100644 --- a/docs/examples/workflows/upstream/output_artifact_azure.md +++ b/docs/examples/workflows/upstream/output_artifact_azure.md @@ -4,62 +4,64 @@ -## Hera -```python -from hera.workflows import ( - AzureArtifact, - Container, - Workflow, - models as m, -) +=== "Hera" -with Workflow(generate_name="output-artifact-s3-", entrypoint="whalesay") as w: - Container( - name="whalesay", - image="docker/whalesay:latest", - command=["sh", "-c"], - args=["cowsay hello world | tee /tmp/hello_world.txt"], - outputs=[ - AzureArtifact( - name="message", - path="/tmp", - endpoint="https://myazurestorageaccountname.blob.core.windows.net", - container="my-container", - blob="path/in/container/hello_world.txt.tgz", - account_key_secret=m.SecretKeySelector(name="my-azure-credentials", key="accountKey"), - ) - ], + ```python linenums="1" + from hera.workflows import ( + AzureArtifact, + Container, + Workflow, + models as m, ) -``` -## YAML + with Workflow(generate_name="output-artifact-s3-", entrypoint="whalesay") as w: + Container( + name="whalesay", + image="docker/whalesay:latest", + command=["sh", "-c"], + args=["cowsay hello world | tee /tmp/hello_world.txt"], + outputs=[ + AzureArtifact( + name="message", + path="/tmp", + endpoint="https://myazurestorageaccountname.blob.core.windows.net", + container="my-container", + blob="path/in/container/hello_world.txt.tgz", + account_key_secret=m.SecretKeySelector(name="my-azure-credentials", key="accountKey"), + ) + ], + ) + ``` + +=== "YAML" + + ```yaml linenums="1" + apiVersion: argoproj.io/v1alpha1 + kind: Workflow + metadata: + generateName: output-artifact-s3- + spec: + entrypoint: whalesay + templates: + - container: + args: + - cowsay hello world | tee /tmp/hello_world.txt + command: + - sh + - -c + image: docker/whalesay:latest + name: whalesay + outputs: + artifacts: + - azure: + accountKeySecret: + key: accountKey + name: my-azure-credentials + blob: path/in/container/hello_world.txt.tgz + container: my-container + endpoint: https://myazurestorageaccountname.blob.core.windows.net + name: message + path: /tmp + ``` -```yaml -apiVersion: argoproj.io/v1alpha1 -kind: Workflow -metadata: - generateName: output-artifact-s3- -spec: - entrypoint: whalesay - templates: - - container: - args: - - cowsay hello world | tee /tmp/hello_world.txt - command: - - sh - - -c - image: docker/whalesay:latest - name: whalesay - outputs: - artifacts: - - azure: - accountKeySecret: - key: accountKey - name: my-azure-credentials - blob: path/in/container/hello_world.txt.tgz - container: my-container - endpoint: https://myazurestorageaccountname.blob.core.windows.net - name: message - path: /tmp -``` diff --git a/docs/examples/workflows/upstream/output_artifact_gcs.md b/docs/examples/workflows/upstream/output_artifact_gcs.md index 57899ae81..bea5efed2 100644 --- a/docs/examples/workflows/upstream/output_artifact_gcs.md +++ b/docs/examples/workflows/upstream/output_artifact_gcs.md @@ -4,60 +4,62 @@ -## Hera - -```python -from hera.workflows import ( - Container, - GCSArtifact, - Workflow, - models as m, -) - -with Workflow(generate_name="output-artifact-gcs-", entrypoint="whalesay") as w: - Container( - name="whalesay", - image="docker/whalesay:latest", - command=["sh", "-c"], - args=["cowsay hello world | tee /tmp/hello_world.txt"], - outputs=[ - GCSArtifact( - name="message", - path="/tmp", - bucket="my-bucket", - key="path/in/bucket/hello_world.txt.tgz", - service_account_key_secret=m.SecretKeySelector(name="my-gcs-credentials", key="serviceAccountKey"), - ) - ], + +=== "Hera" + + ```python linenums="1" + from hera.workflows import ( + Container, + GCSArtifact, + Workflow, + models as m, ) -``` - -## YAML - -```yaml -apiVersion: argoproj.io/v1alpha1 -kind: Workflow -metadata: - generateName: output-artifact-gcs- -spec: - entrypoint: whalesay - templates: - - container: - args: - - cowsay hello world | tee /tmp/hello_world.txt - command: - - sh - - -c - image: docker/whalesay:latest - name: whalesay - outputs: - artifacts: - - gcs: - bucket: my-bucket - key: path/in/bucket/hello_world.txt.tgz - serviceAccountKeySecret: - key: serviceAccountKey - name: my-gcs-credentials - name: message - path: /tmp -``` + + with Workflow(generate_name="output-artifact-gcs-", entrypoint="whalesay") as w: + Container( + name="whalesay", + image="docker/whalesay:latest", + command=["sh", "-c"], + args=["cowsay hello world | tee /tmp/hello_world.txt"], + outputs=[ + GCSArtifact( + name="message", + path="/tmp", + bucket="my-bucket", + key="path/in/bucket/hello_world.txt.tgz", + service_account_key_secret=m.SecretKeySelector(name="my-gcs-credentials", key="serviceAccountKey"), + ) + ], + ) + ``` + +=== "YAML" + + ```yaml linenums="1" + apiVersion: argoproj.io/v1alpha1 + kind: Workflow + metadata: + generateName: output-artifact-gcs- + spec: + entrypoint: whalesay + templates: + - container: + args: + - cowsay hello world | tee /tmp/hello_world.txt + command: + - sh + - -c + image: docker/whalesay:latest + name: whalesay + outputs: + artifacts: + - gcs: + bucket: my-bucket + key: path/in/bucket/hello_world.txt.tgz + serviceAccountKeySecret: + key: serviceAccountKey + name: my-gcs-credentials + name: message + path: /tmp + ``` + diff --git a/docs/examples/workflows/upstream/output_artifact_s3.md b/docs/examples/workflows/upstream/output_artifact_s3.md index e1aad425b..33c4d8b5b 100644 --- a/docs/examples/workflows/upstream/output_artifact_s3.md +++ b/docs/examples/workflows/upstream/output_artifact_s3.md @@ -4,74 +4,76 @@ -## Hera -```python -from hera.workflows import ( - Container, - S3Artifact, - Workflow, - models as m, -) +=== "Hera" -with Workflow(generate_name="output-artifact-s3-", entrypoint="whalesay") as w: - Container( - name="whalesay", - image="docker/whalesay:latest", - command=["sh", "-c"], - args=["cowsay hello world | tee /tmp/hello_world.txt"], - outputs=[ - S3Artifact( - name="message", - path="/tmp", - endpoint="s3.amazonaws.com", - bucket="my-bucket", - region="us-west-2", - key="path/in/bucket/hello_world.txt.tgz", - access_key_secret=m.SecretKeySelector( - name="my-s3-credentials", - key="accessKey", - ), - secret_key_secret=m.SecretKeySelector( - name="my-s3-credentials", - key="secretKey", - ), - ) - ], + ```python linenums="1" + from hera.workflows import ( + Container, + S3Artifact, + Workflow, + models as m, ) -``` -## YAML + with Workflow(generate_name="output-artifact-s3-", entrypoint="whalesay") as w: + Container( + name="whalesay", + image="docker/whalesay:latest", + command=["sh", "-c"], + args=["cowsay hello world | tee /tmp/hello_world.txt"], + outputs=[ + S3Artifact( + name="message", + path="/tmp", + endpoint="s3.amazonaws.com", + bucket="my-bucket", + region="us-west-2", + key="path/in/bucket/hello_world.txt.tgz", + access_key_secret=m.SecretKeySelector( + name="my-s3-credentials", + key="accessKey", + ), + secret_key_secret=m.SecretKeySelector( + name="my-s3-credentials", + key="secretKey", + ), + ) + ], + ) + ``` + +=== "YAML" + + ```yaml linenums="1" + apiVersion: argoproj.io/v1alpha1 + kind: Workflow + metadata: + generateName: output-artifact-s3- + spec: + entrypoint: whalesay + templates: + - container: + args: + - cowsay hello world | tee /tmp/hello_world.txt + command: + - sh + - -c + image: docker/whalesay:latest + name: whalesay + outputs: + artifacts: + - name: message + path: /tmp + s3: + accessKeySecret: + key: accessKey + name: my-s3-credentials + bucket: my-bucket + endpoint: s3.amazonaws.com + key: path/in/bucket/hello_world.txt.tgz + region: us-west-2 + secretKeySecret: + key: secretKey + name: my-s3-credentials + ``` -```yaml -apiVersion: argoproj.io/v1alpha1 -kind: Workflow -metadata: - generateName: output-artifact-s3- -spec: - entrypoint: whalesay - templates: - - container: - args: - - cowsay hello world | tee /tmp/hello_world.txt - command: - - sh - - -c - image: docker/whalesay:latest - name: whalesay - outputs: - artifacts: - - name: message - path: /tmp - s3: - accessKeySecret: - key: accessKey - name: my-s3-credentials - bucket: my-bucket - endpoint: s3.amazonaws.com - key: path/in/bucket/hello_world.txt.tgz - region: us-west-2 - secretKeySecret: - key: secretKey - name: my-s3-credentials -``` diff --git a/docs/examples/workflows/upstream/parallelism_limit.md b/docs/examples/workflows/upstream/parallelism_limit.md index 1c9191ac9..9e803fb61 100644 --- a/docs/examples/workflows/upstream/parallelism_limit.md +++ b/docs/examples/workflows/upstream/parallelism_limit.md @@ -4,57 +4,59 @@ -## Hera - -```python -from hera.workflows import Container, Steps, Workflow - -with Workflow( - generate_name="parallelism-limit-", - entrypoint="parallelism-limit", - parallelism=2, -) as w: - sleep = Container( - name="sleep", - image="alpine:latest", - command=["sh", "-c", "sleep 10"], - ) - - with Steps(name="parallelism-limit") as steps: - sleep(with_items=["this", "workflow", "should", "take", "at", "least", 60, "seconds", "to", "complete"]) -``` - -## YAML - -```yaml -apiVersion: argoproj.io/v1alpha1 -kind: Workflow -metadata: - generateName: parallelism-limit- -spec: - entrypoint: parallelism-limit - parallelism: 2 - templates: - - container: - command: - - sh - - -c - - sleep 10 - image: alpine:latest - name: sleep - - name: parallelism-limit - steps: - - - name: sleep - template: sleep - withItems: - - this - - workflow - - should - - take - - at - - least - - 60 - - seconds - - to - - complete -``` + +=== "Hera" + + ```python linenums="1" + from hera.workflows import Container, Steps, Workflow + + with Workflow( + generate_name="parallelism-limit-", + entrypoint="parallelism-limit", + parallelism=2, + ) as w: + sleep = Container( + name="sleep", + image="alpine:latest", + command=["sh", "-c", "sleep 10"], + ) + + with Steps(name="parallelism-limit") as steps: + sleep(with_items=["this", "workflow", "should", "take", "at", "least", 60, "seconds", "to", "complete"]) + ``` + +=== "YAML" + + ```yaml linenums="1" + apiVersion: argoproj.io/v1alpha1 + kind: Workflow + metadata: + generateName: parallelism-limit- + spec: + entrypoint: parallelism-limit + parallelism: 2 + templates: + - container: + command: + - sh + - -c + - sleep 10 + image: alpine:latest + name: sleep + - name: parallelism-limit + steps: + - - name: sleep + template: sleep + withItems: + - this + - workflow + - should + - take + - at + - least + - 60 + - seconds + - to + - complete + ``` + diff --git a/docs/examples/workflows/upstream/parallelism_nested.md b/docs/examples/workflows/upstream/parallelism_nested.md index 6f36cda3f..ba9a89e12 100644 --- a/docs/examples/workflows/upstream/parallelism_nested.md +++ b/docs/examples/workflows/upstream/parallelism_nested.md @@ -4,116 +4,118 @@ -## Hera -```python -from hera.workflows import Container, Parameter, Step, Steps, Workflow +=== "Hera" -with Workflow( - generate_name="parallelism-nested-", - entrypoint="parallel-worker", - arguments=[ - Parameter(name="seq-list", value='["a","b","c","d"]\n'), - Parameter(name="parallel-list", value="[1,2,3,4]\n"), - ], -) as w: - one_job = Container( - name="one-job", - image="alpine", - command=["/bin/sh", "-c"], - args=["echo {{inputs.parameters.parallel-id}} {{inputs.parameters.seq-id}}; sleep 10"], - inputs=[Parameter(name="seq-id"), Parameter(name="parallel-id")], - ) + ```python linenums="1" + from hera.workflows import Container, Parameter, Step, Steps, Workflow - with Steps( - name="seq-worker", parallelism=1, inputs=[Parameter(name="seq-list"), Parameter(name="parallel-id")] - ) as seq_worker: - with seq_worker.parallel(): - one_job( - name="seq-step", + with Workflow( + generate_name="parallelism-nested-", + entrypoint="parallel-worker", + arguments=[ + Parameter(name="seq-list", value='["a","b","c","d"]\n'), + Parameter(name="parallel-list", value="[1,2,3,4]\n"), + ], + ) as w: + one_job = Container( + name="one-job", + image="alpine", + command=["/bin/sh", "-c"], + args=["echo {{inputs.parameters.parallel-id}} {{inputs.parameters.seq-id}}; sleep 10"], + inputs=[Parameter(name="seq-id"), Parameter(name="parallel-id")], + ) + + with Steps( + name="seq-worker", parallelism=1, inputs=[Parameter(name="seq-list"), Parameter(name="parallel-id")] + ) as seq_worker: + with seq_worker.parallel(): + one_job( + name="seq-step", + arguments=[ + Parameter(name="parallel-id", value="{{inputs.parameters.parallel-id}}"), + Parameter(name="seq-id", value="{{item}}"), + ], + with_param="{{inputs.parameters.seq-list}}", + ) + + with Steps( + name="parallel-worker", inputs=[Parameter(name="seq-list"), Parameter(name="parallel-list")] + ) as parallel_worker: + Step( + name="parallel-worker", + template=seq_worker, arguments=[ - Parameter(name="parallel-id", value="{{inputs.parameters.parallel-id}}"), - Parameter(name="seq-id", value="{{item}}"), + Parameter(name="seq-list", value="{{inputs.parameters.seq-list}}"), + Parameter(name="parallel-id", value="{{item}}"), ], - with_param="{{inputs.parameters.seq-list}}", + with_param="{{inputs.parameters.parallel-list}}", ) + ``` - with Steps( - name="parallel-worker", inputs=[Parameter(name="seq-list"), Parameter(name="parallel-list")] - ) as parallel_worker: - Step( - name="parallel-worker", - template=seq_worker, - arguments=[ - Parameter(name="seq-list", value="{{inputs.parameters.seq-list}}"), - Parameter(name="parallel-id", value="{{item}}"), - ], - with_param="{{inputs.parameters.parallel-list}}", - ) -``` - -## YAML +=== "YAML" -```yaml -apiVersion: argoproj.io/v1alpha1 -kind: Workflow -metadata: - generateName: parallelism-nested- -spec: - arguments: - parameters: - - name: seq-list - value: '["a","b","c","d"] + ```yaml linenums="1" + apiVersion: argoproj.io/v1alpha1 + kind: Workflow + metadata: + generateName: parallelism-nested- + spec: + arguments: + parameters: + - name: seq-list + value: '["a","b","c","d"] - ' - - name: parallel-list - value: '[1,2,3,4] + ' + - name: parallel-list + value: '[1,2,3,4] - ' - entrypoint: parallel-worker - templates: - - container: - args: - - echo {{inputs.parameters.parallel-id}} {{inputs.parameters.seq-id}}; sleep - 10 - command: - - /bin/sh - - -c - image: alpine - inputs: - parameters: - - name: seq-id - - name: parallel-id - name: one-job - - inputs: - parameters: - - name: seq-list - - name: parallel-id - name: seq-worker - parallelism: 1 - steps: - - - arguments: + ' + entrypoint: parallel-worker + templates: + - container: + args: + - echo {{inputs.parameters.parallel-id}} {{inputs.parameters.seq-id}}; sleep + 10 + command: + - /bin/sh + - -c + image: alpine + inputs: parameters: - - name: parallel-id - value: '{{inputs.parameters.parallel-id}}' - name: seq-id - value: '{{item}}' - name: seq-step - template: one-job - withParam: '{{inputs.parameters.seq-list}}' - - inputs: - parameters: - - name: seq-list - - name: parallel-list - name: parallel-worker - steps: - - - arguments: + - name: parallel-id + name: one-job + - inputs: parameters: - name: seq-list - value: '{{inputs.parameters.seq-list}}' - name: parallel-id - value: '{{item}}' + name: seq-worker + parallelism: 1 + steps: + - - arguments: + parameters: + - name: parallel-id + value: '{{inputs.parameters.parallel-id}}' + - name: seq-id + value: '{{item}}' + name: seq-step + template: one-job + withParam: '{{inputs.parameters.seq-list}}' + - inputs: + parameters: + - name: seq-list + - name: parallel-list name: parallel-worker - template: seq-worker - withParam: '{{inputs.parameters.parallel-list}}' -``` + steps: + - - arguments: + parameters: + - name: seq-list + value: '{{inputs.parameters.seq-list}}' + - name: parallel-id + value: '{{item}}' + name: parallel-worker + template: seq-worker + withParam: '{{inputs.parameters.parallel-list}}' + ``` + diff --git a/docs/examples/workflows/upstream/resource_delete_with_flags.md b/docs/examples/workflows/upstream/resource_delete_with_flags.md index 2d7a0135d..ae8515b42 100644 --- a/docs/examples/workflows/upstream/resource_delete_with_flags.md +++ b/docs/examples/workflows/upstream/resource_delete_with_flags.md @@ -4,89 +4,91 @@ -## Hera -```python -from hera.workflows import ( - Parameter, - Resource, - Step, - Steps, - Workflow, - models as m, -) +=== "Hera" -with Workflow( - generate_name="resource-delete-with-flags-", - entrypoint="main", -) as w: - create_configmap = Resource( - name="create-configmap", - action="create", - manifest="""apiVersion: v1 -kind: ConfigMap -metadata: - name: resource-delete-with-flags - labels: - cleanup: "true" -data: - key: value -""", + ```python linenums="1" + from hera.workflows import ( + Parameter, + Resource, + Step, + Steps, + Workflow, + models as m, ) - delete_resource = Resource( - name="delete-resource", - action="delete", - flags=["configmap", "--selector", "{{inputs.parameters.selector}}"], - inputs=m.Inputs( - parameters=[Parameter(name="selector")], - ), - ) + with Workflow( + generate_name="resource-delete-with-flags-", + entrypoint="main", + ) as w: + create_configmap = Resource( + name="create-configmap", + action="create", + manifest="""apiVersion: v1 + kind: ConfigMap + metadata: + name: resource-delete-with-flags + labels: + cleanup: "true" + data: + key: value + """, + ) - with Steps(name="main") as s: - Step(name="submit-resource", template=create_configmap.name) - Step( + delete_resource = Resource( name="delete-resource", - template=delete_resource.name, - arguments=[ - Parameter(name="selector", value="cleanup=true"), - ], + action="delete", + flags=["configmap", "--selector", "{{inputs.parameters.selector}}"], + inputs=m.Inputs( + parameters=[Parameter(name="selector")], + ), ) -``` -## YAML + with Steps(name="main") as s: + Step(name="submit-resource", template=create_configmap.name) + Step( + name="delete-resource", + template=delete_resource.name, + arguments=[ + Parameter(name="selector", value="cleanup=true"), + ], + ) + ``` -```yaml -apiVersion: argoproj.io/v1alpha1 -kind: Workflow -metadata: - generateName: resource-delete-with-flags- -spec: - entrypoint: main - templates: - - name: create-configmap - resource: - action: create - manifest: "apiVersion: v1\nkind: ConfigMap\nmetadata:\n name: resource-delete-with-flags\n\ - \ labels:\n cleanup: \"true\"\ndata:\n key: value\n" - - inputs: - parameters: - - name: selector - name: delete-resource - resource: - action: delete - flags: - - configmap - - --selector - - '{{inputs.parameters.selector}}' - - name: main - steps: - - - name: submit-resource - template: create-configmap - - - arguments: +=== "YAML" + + ```yaml linenums="1" + apiVersion: argoproj.io/v1alpha1 + kind: Workflow + metadata: + generateName: resource-delete-with-flags- + spec: + entrypoint: main + templates: + - name: create-configmap + resource: + action: create + manifest: "apiVersion: v1\nkind: ConfigMap\nmetadata:\n name: resource-delete-with-flags\n\ + \ labels:\n cleanup: \"true\"\ndata:\n key: value\n" + - inputs: parameters: - name: selector - value: cleanup=true name: delete-resource - template: delete-resource -``` + resource: + action: delete + flags: + - configmap + - --selector + - '{{inputs.parameters.selector}}' + - name: main + steps: + - - name: submit-resource + template: create-configmap + - - arguments: + parameters: + - name: selector + value: cleanup=true + name: delete-resource + template: delete-resource + ``` + diff --git a/docs/examples/workflows/upstream/steps.md b/docs/examples/workflows/upstream/steps.md index ef34153c6..17dd13893 100644 --- a/docs/examples/workflows/upstream/steps.md +++ b/docs/examples/workflows/upstream/steps.md @@ -4,81 +4,83 @@ -## Hera -```python -from hera.workflows import Container, Parameter, Step, Steps, Workflow +=== "Hera" -with Workflow( - generate_name="steps-", - entrypoint="hello-hello-hello", -) as w: - whalesay = Container( - name="whalesay", - inputs=[Parameter(name="message")], - image="docker/whalesay", - command=["cowsay"], - args=["{{inputs.parameters.message}}"], - ) + ```python linenums="1" + from hera.workflows import Container, Parameter, Step, Steps, Workflow - with Steps(name="hello-hello-hello") as s: - Step( - name="hello1", - template="whalesay", - arguments=[Parameter(name="message", value="hello1")], + with Workflow( + generate_name="steps-", + entrypoint="hello-hello-hello", + ) as w: + whalesay = Container( + name="whalesay", + inputs=[Parameter(name="message")], + image="docker/whalesay", + command=["cowsay"], + args=["{{inputs.parameters.message}}"], ) - with s.parallel(): + with Steps(name="hello-hello-hello") as s: Step( - name="hello2a", + name="hello1", template="whalesay", - arguments=[Parameter(name="message", value="hello2a")], + arguments=[Parameter(name="message", value="hello1")], ) - Step( - name="hello2b", - template="whalesay", - arguments=[Parameter(name="message", value="hello2b")], - ) -``` -## YAML + with s.parallel(): + Step( + name="hello2a", + template="whalesay", + arguments=[Parameter(name="message", value="hello2a")], + ) + Step( + name="hello2b", + template="whalesay", + arguments=[Parameter(name="message", value="hello2b")], + ) + ``` -```yaml -apiVersion: argoproj.io/v1alpha1 -kind: Workflow -metadata: - generateName: steps- -spec: - entrypoint: hello-hello-hello - templates: - - container: - args: - - '{{inputs.parameters.message}}' - command: - - cowsay - image: docker/whalesay - inputs: - parameters: - - name: message - name: whalesay - - name: hello-hello-hello - steps: - - - arguments: - parameters: - - name: message - value: hello1 - name: hello1 - template: whalesay - - - arguments: - parameters: - - name: message - value: hello2a - name: hello2a - template: whalesay - - arguments: +=== "YAML" + + ```yaml linenums="1" + apiVersion: argoproj.io/v1alpha1 + kind: Workflow + metadata: + generateName: steps- + spec: + entrypoint: hello-hello-hello + templates: + - container: + args: + - '{{inputs.parameters.message}}' + command: + - cowsay + image: docker/whalesay + inputs: parameters: - name: message - value: hello2b - name: hello2b - template: whalesay -``` + name: whalesay + - name: hello-hello-hello + steps: + - - arguments: + parameters: + - name: message + value: hello1 + name: hello1 + template: whalesay + - - arguments: + parameters: + - name: message + value: hello2a + name: hello2a + template: whalesay + - arguments: + parameters: + - name: message + value: hello2b + name: hello2b + template: whalesay + ``` + diff --git a/docs/examples/workflows/upstream/steps_inline_workflow.md b/docs/examples/workflows/upstream/steps_inline_workflow.md index 4dcb061b5..b0feb95e5 100644 --- a/docs/examples/workflows/upstream/steps_inline_workflow.md +++ b/docs/examples/workflows/upstream/steps_inline_workflow.md @@ -4,43 +4,45 @@ -## Hera - -```python -from hera.workflows import Container, Step, Steps, Workflow - -container = Container(image="argoproj/argosay:v2") - -with Workflow( - generate_name="steps-inline-", - entrypoint="main", - annotations={ - "workflows.argoproj.io/description": ("This workflow demonstrates running a steps with inline templates."), - "workflows.argoproj.io/version": ">= 3.2.0", - }, -) as w: - with Steps(name="main"): - Step(name="a", inline=container) -``` - -## YAML - -```yaml -apiVersion: argoproj.io/v1alpha1 -kind: Workflow -metadata: - annotations: - workflows.argoproj.io/description: This workflow demonstrates running a steps - with inline templates. - workflows.argoproj.io/version: '>= 3.2.0' - generateName: steps-inline- -spec: - entrypoint: main - templates: - - name: main - steps: - - - inline: - container: - image: argoproj/argosay:v2 - name: a -``` + +=== "Hera" + + ```python linenums="1" + from hera.workflows import Container, Step, Steps, Workflow + + container = Container(image="argoproj/argosay:v2") + + with Workflow( + generate_name="steps-inline-", + entrypoint="main", + annotations={ + "workflows.argoproj.io/description": ("This workflow demonstrates running a steps with inline templates."), + "workflows.argoproj.io/version": ">= 3.2.0", + }, + ) as w: + with Steps(name="main"): + Step(name="a", inline=container) + ``` + +=== "YAML" + + ```yaml linenums="1" + apiVersion: argoproj.io/v1alpha1 + kind: Workflow + metadata: + annotations: + workflows.argoproj.io/description: This workflow demonstrates running a steps + with inline templates. + workflows.argoproj.io/version: '>= 3.2.0' + generateName: steps-inline- + spec: + entrypoint: main + templates: + - name: main + steps: + - - inline: + container: + image: argoproj/argosay:v2 + name: a + ``` + diff --git a/docs/examples/workflows/upstream/volumes_emptydir.md b/docs/examples/workflows/upstream/volumes_emptydir.md index 037cd841e..001e8495d 100644 --- a/docs/examples/workflows/upstream/volumes_emptydir.md +++ b/docs/examples/workflows/upstream/volumes_emptydir.md @@ -4,57 +4,59 @@ -## Hera - -```python -from hera.workflows import ( - Container, - Workflow, - models as m, -) - -with Workflow( - generate_name="volumes-emptydir-", - entrypoint="volumes-emptydir-example", - volumes=[m.Volume(name="workdir", empty_dir=m.EmptyDirVolumeSource())], -) as w: - empty_dir = Container( - name="volumes-emptydir-example", - image="debian:latest", - command=["/bin/bash", "-c"], - args=[ - ( - " vol_found=`mount | grep /mnt/vol` && " - + 'if [[ -n $vol_found ]]; then echo "Volume mounted and found"; else echo "Not found"; fi ' - ) - ], - volume_mounts=[m.VolumeMount(name="workdir", mount_path="/mnt/vol")], + +=== "Hera" + + ```python linenums="1" + from hera.workflows import ( + Container, + Workflow, + models as m, ) -``` - -## YAML - -```yaml -apiVersion: argoproj.io/v1alpha1 -kind: Workflow -metadata: - generateName: volumes-emptydir- -spec: - entrypoint: volumes-emptydir-example - templates: - - container: - args: - - ' vol_found=`mount | grep /mnt/vol` && if [[ -n $vol_found ]]; then echo "Volume - mounted and found"; else echo "Not found"; fi ' - command: - - /bin/bash - - -c - image: debian:latest - volumeMounts: - - mountPath: /mnt/vol + + with Workflow( + generate_name="volumes-emptydir-", + entrypoint="volumes-emptydir-example", + volumes=[m.Volume(name="workdir", empty_dir=m.EmptyDirVolumeSource())], + ) as w: + empty_dir = Container( + name="volumes-emptydir-example", + image="debian:latest", + command=["/bin/bash", "-c"], + args=[ + ( + " vol_found=`mount | grep /mnt/vol` && " + + 'if [[ -n $vol_found ]]; then echo "Volume mounted and found"; else echo "Not found"; fi ' + ) + ], + volume_mounts=[m.VolumeMount(name="workdir", mount_path="/mnt/vol")], + ) + ``` + +=== "YAML" + + ```yaml linenums="1" + apiVersion: argoproj.io/v1alpha1 + kind: Workflow + metadata: + generateName: volumes-emptydir- + spec: + entrypoint: volumes-emptydir-example + templates: + - container: + args: + - ' vol_found=`mount | grep /mnt/vol` && if [[ -n $vol_found ]]; then echo "Volume + mounted and found"; else echo "Not found"; fi ' + command: + - /bin/bash + - -c + image: debian:latest + volumeMounts: + - mountPath: /mnt/vol + name: workdir + name: volumes-emptydir-example + volumes: + - emptyDir: {} name: workdir - name: volumes-emptydir-example - volumes: - - emptyDir: {} - name: workdir -``` + ``` + diff --git a/docs/examples/workflows/upstream/volumes_existing.md b/docs/examples/workflows/upstream/volumes_existing.md index b6888e4d8..b7cd99ca1 100644 --- a/docs/examples/workflows/upstream/volumes_existing.md +++ b/docs/examples/workflows/upstream/volumes_existing.md @@ -4,85 +4,87 @@ -## Hera -```python -from typing import List +=== "Hera" -from hera.workflows import ( - Container, - Steps, - Workflow, - models as m, -) + ```python linenums="1" + from typing import List - -def _get_container(name: str, args: List[str]) -> Container: - """Creates container (alpine:latest) with a mounted volume""" - return Container( - name=name, - image="alpine:latest", - command=["sh", "-c"], - args=args, - volume_mounts=[ - m.VolumeMount(name="workdir", mount_path="/mnt/vol"), - ], + from hera.workflows import ( + Container, + Steps, + Workflow, + models as m, ) -with Workflow( - generate_name="volumes-existing-", - entrypoint="volumes-existing-example", - volumes=[m.Volume(name="workdir", persistent_volume_claim={"claim_name": "my-existing-volume"})], -) as w: - append_to_log = _get_container("append-to-accesslog", ["echo accessed at: $(date) | tee -a /mnt/vol/accesslog"]) - print_log = _get_container("print-accesslog", ["echo 'Volume access log:'; cat /mnt/vol/accesslog"]) + def _get_container(name: str, args: List[str]) -> Container: + """Creates container (alpine:latest) with a mounted volume""" + return Container( + name=name, + image="alpine:latest", + command=["sh", "-c"], + args=args, + volume_mounts=[ + m.VolumeMount(name="workdir", mount_path="/mnt/vol"), + ], + ) + + + with Workflow( + generate_name="volumes-existing-", + entrypoint="volumes-existing-example", + volumes=[m.Volume(name="workdir", persistent_volume_claim={"claim_name": "my-existing-volume"})], + ) as w: + append_to_log = _get_container("append-to-accesslog", ["echo accessed at: $(date) | tee -a /mnt/vol/accesslog"]) + print_log = _get_container("print-accesslog", ["echo 'Volume access log:'; cat /mnt/vol/accesslog"]) + + with Steps(name="volumes-existing-example") as s: + append_to_log(name="generate") + print_log(name="print") + ``` - with Steps(name="volumes-existing-example") as s: - append_to_log(name="generate") - print_log(name="print") -``` +=== "YAML" -## YAML + ```yaml linenums="1" + apiVersion: argoproj.io/v1alpha1 + kind: Workflow + metadata: + generateName: volumes-existing- + spec: + entrypoint: volumes-existing-example + templates: + - container: + args: + - 'echo accessed at: $(date) | tee -a /mnt/vol/accesslog' + command: + - sh + - -c + image: alpine:latest + volumeMounts: + - mountPath: /mnt/vol + name: workdir + name: append-to-accesslog + - container: + args: + - echo 'Volume access log:'; cat /mnt/vol/accesslog + command: + - sh + - -c + image: alpine:latest + volumeMounts: + - mountPath: /mnt/vol + name: workdir + name: print-accesslog + - name: volumes-existing-example + steps: + - - name: generate + template: append-to-accesslog + - - name: print + template: print-accesslog + volumes: + - name: workdir + persistentVolumeClaim: + claimName: my-existing-volume + ``` -```yaml -apiVersion: argoproj.io/v1alpha1 -kind: Workflow -metadata: - generateName: volumes-existing- -spec: - entrypoint: volumes-existing-example - templates: - - container: - args: - - 'echo accessed at: $(date) | tee -a /mnt/vol/accesslog' - command: - - sh - - -c - image: alpine:latest - volumeMounts: - - mountPath: /mnt/vol - name: workdir - name: append-to-accesslog - - container: - args: - - echo 'Volume access log:'; cat /mnt/vol/accesslog - command: - - sh - - -c - image: alpine:latest - volumeMounts: - - mountPath: /mnt/vol - name: workdir - name: print-accesslog - - name: volumes-existing-example - steps: - - - name: generate - template: append-to-accesslog - - - name: print - template: print-accesslog - volumes: - - name: workdir - persistentVolumeClaim: - claimName: my-existing-volume -``` diff --git a/docs/examples/workflows/upstream/volumes_pvc.md b/docs/examples/workflows/upstream/volumes_pvc.md index edddcb5f2..cbbebaf78 100644 --- a/docs/examples/workflows/upstream/volumes_pvc.md +++ b/docs/examples/workflows/upstream/volumes_pvc.md @@ -4,107 +4,109 @@ -## Hera -```python -from typing import List +=== "Hera" -from hera.workflows import ( - Container, - Steps, - Workflow, - models as m, -) + ```python linenums="1" + from typing import List - -def _get_container(name: str, image: str, args: List[str]) -> Container: - """Creates container with a mounted volume""" - return Container( - name=name, - image=image, - command=["sh", "-c"], - args=args, - volume_mounts=[ - m.VolumeMount(name="workdir", mount_path="/mnt/vol"), - ], + from hera.workflows import ( + Container, + Steps, + Workflow, + models as m, ) -with Workflow( - generate_name="volumes-pvc-", - entrypoint="volumes-pvc-example", - volume_claim_templates=[ - m.PersistentVolumeClaim( - metadata=m.ObjectMeta(name="workdir"), - spec=m.PersistentVolumeClaimSpec( - access_modes=["ReadWriteOnce"], - resources=m.ResourceRequirements( - requests={"storage": m.Quantity(__root__="1Gi")}, + def _get_container(name: str, image: str, args: List[str]) -> Container: + """Creates container with a mounted volume""" + return Container( + name=name, + image=image, + command=["sh", "-c"], + args=args, + volume_mounts=[ + m.VolumeMount(name="workdir", mount_path="/mnt/vol"), + ], + ) + + + with Workflow( + generate_name="volumes-pvc-", + entrypoint="volumes-pvc-example", + volume_claim_templates=[ + m.PersistentVolumeClaim( + metadata=m.ObjectMeta(name="workdir"), + spec=m.PersistentVolumeClaimSpec( + access_modes=["ReadWriteOnce"], + resources=m.ResourceRequirements( + requests={"storage": m.Quantity(__root__="1Gi")}, + ), ), - ), + ) + ], + ) as w: + whalesay = _get_container( + "whalesay", + "docker/whalesay:latest", + ["echo generating message in volume; cowsay hello world | tee /mnt/vol/hello_world.txt"], ) - ], -) as w: - whalesay = _get_container( - "whalesay", - "docker/whalesay:latest", - ["echo generating message in volume; cowsay hello world | tee /mnt/vol/hello_world.txt"], - ) - print_message = _get_container( - "print-message", - "alpine:latest", - ["echo getting message from volume; find /mnt/vol; cat /mnt/vol/hello_world.txt"], - ) - with Steps(name="volumes-pvc-example") as s: - whalesay(name="generate") - print_message(name="print") -``` + print_message = _get_container( + "print-message", + "alpine:latest", + ["echo getting message from volume; find /mnt/vol; cat /mnt/vol/hello_world.txt"], + ) + with Steps(name="volumes-pvc-example") as s: + whalesay(name="generate") + print_message(name="print") + ``` -## YAML +=== "YAML" -```yaml -apiVersion: argoproj.io/v1alpha1 -kind: Workflow -metadata: - generateName: volumes-pvc- -spec: - entrypoint: volumes-pvc-example - templates: - - container: - args: - - echo generating message in volume; cowsay hello world | tee /mnt/vol/hello_world.txt - command: - - sh - - -c - image: docker/whalesay:latest - volumeMounts: - - mountPath: /mnt/vol - name: workdir - name: whalesay - - container: - args: - - echo getting message from volume; find /mnt/vol; cat /mnt/vol/hello_world.txt - command: - - sh - - -c - image: alpine:latest - volumeMounts: - - mountPath: /mnt/vol - name: workdir - name: print-message - - name: volumes-pvc-example - steps: - - - name: generate - template: whalesay - - - name: print - template: print-message - volumeClaimTemplates: - - metadata: - name: workdir + ```yaml linenums="1" + apiVersion: argoproj.io/v1alpha1 + kind: Workflow + metadata: + generateName: volumes-pvc- spec: - accessModes: - - ReadWriteOnce - resources: - requests: - storage: 1Gi -``` + entrypoint: volumes-pvc-example + templates: + - container: + args: + - echo generating message in volume; cowsay hello world | tee /mnt/vol/hello_world.txt + command: + - sh + - -c + image: docker/whalesay:latest + volumeMounts: + - mountPath: /mnt/vol + name: workdir + name: whalesay + - container: + args: + - echo getting message from volume; find /mnt/vol; cat /mnt/vol/hello_world.txt + command: + - sh + - -c + image: alpine:latest + volumeMounts: + - mountPath: /mnt/vol + name: workdir + name: print-message + - name: volumes-pvc-example + steps: + - - name: generate + template: whalesay + - - name: print + template: print-message + volumeClaimTemplates: + - metadata: + name: workdir + spec: + accessModes: + - ReadWriteOnce + resources: + requests: + storage: 1Gi + ``` + diff --git a/docs/examples/workflows/upstream/webhdfs_input_output_artifacts.md b/docs/examples/workflows/upstream/webhdfs_input_output_artifacts.md index 8af32bc7b..b47e89198 100644 --- a/docs/examples/workflows/upstream/webhdfs_input_output_artifacts.md +++ b/docs/examples/workflows/upstream/webhdfs_input_output_artifacts.md @@ -4,131 +4,133 @@ -## Hera -```python -from hera.workflows import ( - Container, - HTTPArtifact, - Workflow, - models as m, -) +=== "Hera" -with Workflow( - generate_name="input-output-artifact-webhdfs-", - entrypoint="input-output-artifact-webhdfs-example", -) as w: - Container( - name="input-output-artifact-webhdfs-example", - image="debian:latest", - command=["sh", "-c"], - args=["cat /my-artifact"], - inputs=[ - HTTPArtifact( - name="my-art", - path="/my-artifact", - url="https://mywebhdfsprovider.com/webhdfs/v1/file.txt?op=OPEN", - auth=m.HTTPAuth( - oauth2=m.OAuth2Auth( - client_id_secret=m.SecretKeySelector(name="oauth-sec", key="clientID"), - client_secret_secret=m.SecretKeySelector(name="oauth-sec", key="clientSecret"), - token_url_secret=m.SecretKeySelector( - name="oauth-sec", - key="tokenURL", + ```python linenums="1" + from hera.workflows import ( + Container, + HTTPArtifact, + Workflow, + models as m, + ) + + with Workflow( + generate_name="input-output-artifact-webhdfs-", + entrypoint="input-output-artifact-webhdfs-example", + ) as w: + Container( + name="input-output-artifact-webhdfs-example", + image="debian:latest", + command=["sh", "-c"], + args=["cat /my-artifact"], + inputs=[ + HTTPArtifact( + name="my-art", + path="/my-artifact", + url="https://mywebhdfsprovider.com/webhdfs/v1/file.txt?op=OPEN", + auth=m.HTTPAuth( + oauth2=m.OAuth2Auth( + client_id_secret=m.SecretKeySelector(name="oauth-sec", key="clientID"), + client_secret_secret=m.SecretKeySelector(name="oauth-sec", key="clientSecret"), + token_url_secret=m.SecretKeySelector( + name="oauth-sec", + key="tokenURL", + ), + scopes=["some", "scopes"], + endpoint_params=[ + m.OAuth2EndpointParam(key="customkey", value="customvalue"), + ], ), - scopes=["some", "scopes"], - endpoint_params=[ - m.OAuth2EndpointParam(key="customkey", value="customvalue"), - ], ), - ), - headers=[ - m.Header(name="CustomHeader", value="CustomValue"), - ], - ) - ], - outputs=[ - HTTPArtifact( - name="my-art2", - path="/my-artifact", - url="https://mywebhdfsprovider.com/webhdfs/v1/file.txt?op=CREATE&overwrite=true", - auth=m.HTTPAuth( - client_cert=m.ClientCertAuth( - client_cert_secret=m.SecretKeySelector( - name="cert-sec", - key="certificate.pem", - ), - client_key_secret=m.SecretKeySelector( - name="cert-sec", - key="key.pem", - ), - ) - ), - headers=[m.Header(name="CustomHeader", value="CustomValue")], - ) - ], - ) -``` + headers=[ + m.Header(name="CustomHeader", value="CustomValue"), + ], + ) + ], + outputs=[ + HTTPArtifact( + name="my-art2", + path="/my-artifact", + url="https://mywebhdfsprovider.com/webhdfs/v1/file.txt?op=CREATE&overwrite=true", + auth=m.HTTPAuth( + client_cert=m.ClientCertAuth( + client_cert_secret=m.SecretKeySelector( + name="cert-sec", + key="certificate.pem", + ), + client_key_secret=m.SecretKeySelector( + name="cert-sec", + key="key.pem", + ), + ) + ), + headers=[m.Header(name="CustomHeader", value="CustomValue")], + ) + ], + ) + ``` + +=== "YAML" -## YAML + ```yaml linenums="1" + apiVersion: argoproj.io/v1alpha1 + kind: Workflow + metadata: + generateName: input-output-artifact-webhdfs- + spec: + entrypoint: input-output-artifact-webhdfs-example + templates: + - container: + args: + - cat /my-artifact + command: + - sh + - -c + image: debian:latest + inputs: + artifacts: + - http: + auth: + oauth2: + clientIDSecret: + key: clientID + name: oauth-sec + clientSecretSecret: + key: clientSecret + name: oauth-sec + endpointParams: + - key: customkey + value: customvalue + scopes: + - some + - scopes + tokenURLSecret: + key: tokenURL + name: oauth-sec + headers: + - name: CustomHeader + value: CustomValue + url: https://mywebhdfsprovider.com/webhdfs/v1/file.txt?op=OPEN + name: my-art + path: /my-artifact + name: input-output-artifact-webhdfs-example + outputs: + artifacts: + - http: + auth: + clientCert: + clientCertSecret: + key: certificate.pem + name: cert-sec + clientKeySecret: + key: key.pem + name: cert-sec + headers: + - name: CustomHeader + value: CustomValue + url: https://mywebhdfsprovider.com/webhdfs/v1/file.txt?op=CREATE&overwrite=true + name: my-art2 + path: /my-artifact + ``` -```yaml -apiVersion: argoproj.io/v1alpha1 -kind: Workflow -metadata: - generateName: input-output-artifact-webhdfs- -spec: - entrypoint: input-output-artifact-webhdfs-example - templates: - - container: - args: - - cat /my-artifact - command: - - sh - - -c - image: debian:latest - inputs: - artifacts: - - http: - auth: - oauth2: - clientIDSecret: - key: clientID - name: oauth-sec - clientSecretSecret: - key: clientSecret - name: oauth-sec - endpointParams: - - key: customkey - value: customvalue - scopes: - - some - - scopes - tokenURLSecret: - key: tokenURL - name: oauth-sec - headers: - - name: CustomHeader - value: CustomValue - url: https://mywebhdfsprovider.com/webhdfs/v1/file.txt?op=OPEN - name: my-art - path: /my-artifact - name: input-output-artifact-webhdfs-example - outputs: - artifacts: - - http: - auth: - clientCert: - clientCertSecret: - key: certificate.pem - name: cert-sec - clientKeySecret: - key: key.pem - name: cert-sec - headers: - - name: CustomHeader - value: CustomValue - url: https://mywebhdfsprovider.com/webhdfs/v1/file.txt?op=CREATE&overwrite=true - name: my-art2 - path: /my-artifact -``` diff --git a/docs/examples/workflows/upstream/workflow_template__dag.md b/docs/examples/workflows/upstream/workflow_template__dag.md index a05fb6f1a..b06b7c8f6 100644 --- a/docs/examples/workflows/upstream/workflow_template__dag.md +++ b/docs/examples/workflows/upstream/workflow_template__dag.md @@ -4,69 +4,71 @@ -## Hera -```python -from hera.workflows import DAG, Task, Workflow -from hera.workflows.models import TemplateRef +=== "Hera" -with Workflow( - generate_name="workflow-template-dag-diamond-", - entrypoint="diamond", -) as w: - whalesay_template_ref = TemplateRef(name="workflow-template-whalesay-template", template="whalesay-template") - inner_template_ref = TemplateRef(name="workflow-template-inner-dag", template="inner-diamond") - with DAG(name="diamond"): - A = Task(name="A", template_ref=whalesay_template_ref, arguments={"message": "A"}) - B = Task(name="B", template_ref=whalesay_template_ref, arguments={"message": "B"}) - C = Task(name="C", template_ref=inner_template_ref) - D = Task(name="D", template_ref=whalesay_template_ref, arguments={"message": "D"}) + ```python linenums="1" + from hera.workflows import DAG, Task, Workflow + from hera.workflows.models import TemplateRef - A >> [B, C] >> D -``` + with Workflow( + generate_name="workflow-template-dag-diamond-", + entrypoint="diamond", + ) as w: + whalesay_template_ref = TemplateRef(name="workflow-template-whalesay-template", template="whalesay-template") + inner_template_ref = TemplateRef(name="workflow-template-inner-dag", template="inner-diamond") + with DAG(name="diamond"): + A = Task(name="A", template_ref=whalesay_template_ref, arguments={"message": "A"}) + B = Task(name="B", template_ref=whalesay_template_ref, arguments={"message": "B"}) + C = Task(name="C", template_ref=inner_template_ref) + D = Task(name="D", template_ref=whalesay_template_ref, arguments={"message": "D"}) -## YAML + A >> [B, C] >> D + ``` + +=== "YAML" + + ```yaml linenums="1" + apiVersion: argoproj.io/v1alpha1 + kind: Workflow + metadata: + generateName: workflow-template-dag-diamond- + spec: + entrypoint: diamond + templates: + - dag: + tasks: + - arguments: + parameters: + - name: message + value: A + name: A + templateRef: + name: workflow-template-whalesay-template + template: whalesay-template + - arguments: + parameters: + - name: message + value: B + depends: A + name: B + templateRef: + name: workflow-template-whalesay-template + template: whalesay-template + - depends: A + name: C + templateRef: + name: workflow-template-inner-dag + template: inner-diamond + - arguments: + parameters: + - name: message + value: D + depends: B && C + name: D + templateRef: + name: workflow-template-whalesay-template + template: whalesay-template + name: diamond + ``` -```yaml -apiVersion: argoproj.io/v1alpha1 -kind: Workflow -metadata: - generateName: workflow-template-dag-diamond- -spec: - entrypoint: diamond - templates: - - dag: - tasks: - - arguments: - parameters: - - name: message - value: A - name: A - templateRef: - name: workflow-template-whalesay-template - template: whalesay-template - - arguments: - parameters: - - name: message - value: B - depends: A - name: B - templateRef: - name: workflow-template-whalesay-template - template: whalesay-template - - depends: A - name: C - templateRef: - name: workflow-template-inner-dag - template: inner-diamond - - arguments: - parameters: - - name: message - value: D - depends: B && C - name: D - templateRef: - name: workflow-template-whalesay-template - template: whalesay-template - name: diamond -``` diff --git a/docs/examples/workflows/upstream/workflow_template__hello_world.md b/docs/examples/workflows/upstream/workflow_template__hello_world.md index 40d8e7c69..7a21f95af 100644 --- a/docs/examples/workflows/upstream/workflow_template__hello_world.md +++ b/docs/examples/workflows/upstream/workflow_template__hello_world.md @@ -4,46 +4,48 @@ -## Hera - -```python -from hera.workflows import Step, Steps, Workflow -from hera.workflows.models import TemplateRef - -with Workflow( - generate_name="workflow-template-hello-world-", - entrypoint="whalesay", -) as w: - whalesay_template_ref = TemplateRef( - name="workflow-template-whalesay-template", - template="whalesay-template", - ) - with Steps(name="whalesay"): - Step( - name="call-whalesay-template", - template_ref=whalesay_template_ref, - arguments={"message": "hello world"}, + +=== "Hera" + + ```python linenums="1" + from hera.workflows import Step, Steps, Workflow + from hera.workflows.models import TemplateRef + + with Workflow( + generate_name="workflow-template-hello-world-", + entrypoint="whalesay", + ) as w: + whalesay_template_ref = TemplateRef( + name="workflow-template-whalesay-template", + template="whalesay-template", ) -``` - -## YAML - -```yaml -apiVersion: argoproj.io/v1alpha1 -kind: Workflow -metadata: - generateName: workflow-template-hello-world- -spec: - entrypoint: whalesay - templates: - - name: whalesay - steps: - - - arguments: - parameters: - - name: message - value: hello world - name: call-whalesay-template - templateRef: - name: workflow-template-whalesay-template - template: whalesay-template -``` + with Steps(name="whalesay"): + Step( + name="call-whalesay-template", + template_ref=whalesay_template_ref, + arguments={"message": "hello world"}, + ) + ``` + +=== "YAML" + + ```yaml linenums="1" + apiVersion: argoproj.io/v1alpha1 + kind: Workflow + metadata: + generateName: workflow-template-hello-world- + spec: + entrypoint: whalesay + templates: + - name: whalesay + steps: + - - arguments: + parameters: + - name: message + value: hello world + name: call-whalesay-template + templateRef: + name: workflow-template-whalesay-template + template: whalesay-template + ``` + diff --git a/docs/examples/workflows/upstream/workflow_template__workflow_template_ref.md b/docs/examples/workflows/upstream/workflow_template__workflow_template_ref.md index cf72bce1f..e19a8e125 100644 --- a/docs/examples/workflows/upstream/workflow_template__workflow_template_ref.md +++ b/docs/examples/workflows/upstream/workflow_template__workflow_template_ref.md @@ -4,28 +4,30 @@ -## Hera - -```python -from hera.workflows import Workflow -from hera.workflows.models import WorkflowTemplateRef - -wt_ref = WorkflowTemplateRef(name="workflow-template-submittable") - -w = Workflow( - generate_name="workflow-template-hello-world-", - workflow_template_ref=wt_ref, -) -``` - -## YAML - -```yaml -apiVersion: argoproj.io/v1alpha1 -kind: Workflow -metadata: - generateName: workflow-template-hello-world- -spec: - workflowTemplateRef: - name: workflow-template-submittable -``` + +=== "Hera" + + ```python linenums="1" + from hera.workflows import Workflow + from hera.workflows.models import WorkflowTemplateRef + + wt_ref = WorkflowTemplateRef(name="workflow-template-submittable") + + w = Workflow( + generate_name="workflow-template-hello-world-", + workflow_template_ref=wt_ref, + ) + ``` + +=== "YAML" + + ```yaml linenums="1" + apiVersion: argoproj.io/v1alpha1 + kind: Workflow + metadata: + generateName: workflow-template-hello-world- + spec: + workflowTemplateRef: + name: workflow-template-submittable + ``` + diff --git a/docs/generate.py b/docs/generate.py index ee3c928a3..bd462dc09 100644 --- a/docs/generate.py +++ b/docs/generate.py @@ -1,6 +1,7 @@ import re import shutil from pathlib import Path +import textwrap # This code reads the contents at the path which is a python file, @@ -32,17 +33,19 @@ def generate_markdown(path: Path, sub_folder: str): {docstring.strip()} -## Hera -```python -{py_contents.strip()} -``` +=== "Hera" -## YAML + ```python linenums="1" +{textwrap.indent(py_contents.strip(), " ")} + ``` + +=== "YAML" + + ```yaml linenums="1" +{textwrap.indent(yaml_contents.strip(), " ")} + ``` -```yaml -{yaml_contents.strip()} -``` """ (Path("examples") / sub_folder / path.stem).with_suffix(".md").write_text(contents) diff --git a/docs/introduction.md b/docs/introduction.md new file mode 100644 index 000000000..85cb27e9e --- /dev/null +++ b/docs/introduction.md @@ -0,0 +1,59 @@ +# Introduction + +Hera is a Python library that allows you to construct and submit Argo Workflows. It is designed to be intuitive and easy to use, while also providing a powerful interface to the underlying Argo API. + +## Hera V5 vs V4 + +Hera v5 is a major release that introduces breaking changes from v4. The main reason for this is that v5 is a complete rewrite of the library, and is now based on the OpenAPI specification of Argo Workflows. This allows us to provide a more intuitive interface to the Argo API, while also providing full feature parity with Argo Workflows. This means that you can now use all the features of Argo Workflows in your workflows. Additionally, it has been re-structured to accommodate other Argo projects, such as Argo Events and Argo CD. Currently only Argo Workflows is supported, and there is some work in progress to add support for Argo Events. + +The codebase is now much more readable, and the focus can be fully dedicated to improving the Python interface to various Argo projects rather than maintaining feature parity with the Argo codebase. +The library is divided into the following components: + +- `hera.shared` - This package contains the shared code that will be used by all Argo projects. This includes common global configuration to interact with the Argo API, and common Pydantic base models that are used by all Argo projects. + +- `hera.events.models` - This package contains the auto-generated code that allows you to construct Argo Events. It provides Pydantic models for all the Argo Events OpenAPI objects, and allows you to construct events using these models. These models are based on the OpenAPI specification, and are therefore exactly the same as the models used by Argo Events. + +- `hera.workflows.models` - This package contains the auto-generated code that allows you to construct Argo Workflows. It provides Pydantic models for all the Argo Workflows OpenAPI objects, and allows you to construct workflows using these models. These models are based on the OpenAPI specification, and are therefore exactly the same as the models used by Argo Workflows. + +- `hera.workflows` - This package contains the hand-written code that allows you to construct and submit Argo Workflows. It wraps the auto-generated code, and provides a more intuitive interface to the Argo API. It also provides a number of useful features, such as the ability to submit workflows from a Python function. This package has various extension points that allow you to plug-in the auto-generated models in case you need to use a feature that is not yet supported by the hand-written code. + +The major differences between v4 and v5 are: + +- The `hera.workflows.models` package is now auto-generated, and is based on the OpenAPI specification of Argo Workflows. This means that all the models are exactly the same as the models used by Argo Workflows, and you can use all the features of Argo Workflows in your workflows written with `hera`. + +- The auto-generated models are based on Pydantic, which means that you can use all the features of Pydantic to construct your workflows. This includes better type-checking, auto-completion in IDEs and more. + +- All template types are now supported. This means that you can now use all the template types that are supported by Argo Workflows, such as DAGs, Steps, Suspend and more. Previously, only the DAG template type was supported. + +- The hand-written code has been rewritten to be extensible. This means that you can now easily extend the library to support new features, or to support features that are not yet supported by the hand-written code. This is done by using the `hera.workflows.models` package, and plugging it into the `hera.workflows` package. + +The following example shows how to use the DAG template type. + +```python +from hera.workflows import ( + DAG, + Workflow, + script, +) + + +# Notice that we are using the script decorator to define the function. +# This is required in order to use the function as a template. +# The decorator also allows us to define the image that will be used to run the function and +# other parameters that are specific to the Script template type. +@script(add_cwd_to_sys_path=False, image="python:alpine3.6") +def say(message): + print(message) + + +with Workflow(generate_name="dag-diamond-", entrypoint="diamond") as w: + # Note that we need to explicitly specify the DAG template type. + with DAG(name="diamond"): + # We can now use the decorated function as tasks in the DAG. + A = say(name="A", arguments={"message": "A"}) + B = say(name="B", arguments={"message": "B"}) + C = say(name="C", arguments={"message": "C"}) + D = say(name="D", arguments={"message": "D"}) + # We can also use the `>>` operator to define dependencies between tasks. + A >> [B, C] >> D +``` diff --git a/mkdocs.yml b/mkdocs.yml index 3f5b3b7e4..e0bd2c6d2 100644 --- a/mkdocs.yml +++ b/mkdocs.yml @@ -5,6 +5,7 @@ copyright: Copyright © 2023 Flaviu Vadan, Sambhav Kothari, Elliot Gunton nav: - Home: README.md + - Introduction: introduction.md - Hera expr transpiler: expr.md - Examples: - Workflows: @@ -40,10 +41,11 @@ theme: name: Switch to dark mode features: - content.code.copy + - content.code.select - search.suggest - search.share - search.highlight - + - content.tabs.link repo_url: https://github.com/argoproj-labs/hera-workflows repo_name: argoproj-labs/hera-workflows edit_uri: blob/main/docs @@ -69,6 +71,11 @@ markdown_extensions: - pymdownx.inlinehilite - pymdownx.snippets - pymdownx.superfences + - pymdownx.tabbed: + alternate_style: true + # slugify: !!python/object/apply:pymdownx.slugs.slugify + # kwds: + # case: lower plugins: - awesome-pages - include-markdown