-
Notifications
You must be signed in to change notification settings - Fork 107
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add script_artifact_passing example (#598)
Fixes #591 with a script example to mirror `artifact_passing.py` upstream example. Will also be useful as an example of artifact passing noted in #595 Signed-off-by: Elliot Gunton <[email protected]>
- Loading branch information
1 parent
d9d4672
commit 85dc8c7
Showing
3 changed files
with
141 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,79 @@ | ||
# Script Artifact Passing | ||
|
||
|
||
|
||
|
||
|
||
|
||
=== "Hera" | ||
|
||
```python linenums="1" | ||
from hera.workflows import Artifact, Steps, Workflow, script | ||
|
||
|
||
@script(outputs=Artifact(name="hello-art", path="/tmp/hello_world.txt")) | ||
def whalesay(): | ||
with open("/tmp/hello_world.txt", "wb") as f: | ||
f.write("hello world") | ||
|
||
|
||
@script(inputs=Artifact(name="message", path="/tmp/message")) | ||
def print_message(): | ||
with open("//tmp/message", "rb") as f: | ||
message = f.readline() | ||
print(message) | ||
|
||
|
||
with Workflow(generate_name="artifact-passing-", entrypoint="artifact-example") as w: | ||
with Steps(name="artifact-example") as s: | ||
whalesay(name="generate-artifact") | ||
print_message( | ||
name="consume-artifact", | ||
arguments=[Artifact(name="message", from_="{{steps.generate-artifact.outputs.artifacts.hello-art}}")], | ||
) | ||
``` | ||
|
||
=== "YAML" | ||
|
||
```yaml linenums="1" | ||
apiVersion: argoproj.io/v1alpha1 | ||
kind: Workflow | ||
metadata: | ||
generateName: artifact-passing- | ||
spec: | ||
entrypoint: artifact-example | ||
templates: | ||
- 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 | ||
- name: whalesay | ||
outputs: | ||
artifacts: | ||
- name: hello-art | ||
path: /tmp/hello_world.txt | ||
script: | ||
command: | ||
- python | ||
image: python:3.8 | ||
source: "import os\nimport sys\nsys.path.append(os.getcwd())\nwith open('/tmp/hello_world.txt',\ | ||
\ 'wb') as f:\n f.write('hello world')" | ||
- inputs: | ||
artifacts: | ||
- name: message | ||
path: /tmp/message | ||
name: print-message | ||
script: | ||
command: | ||
- python | ||
image: python:3.8 | ||
source: "import os\nimport sys\nsys.path.append(os.getcwd())\nwith open('//tmp/message',\ | ||
\ 'rb') as f:\n message = f.readline()\nprint(message)" | ||
``` | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
apiVersion: argoproj.io/v1alpha1 | ||
kind: Workflow | ||
metadata: | ||
generateName: artifact-passing- | ||
spec: | ||
entrypoint: artifact-example | ||
templates: | ||
- 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 | ||
- name: whalesay | ||
outputs: | ||
artifacts: | ||
- name: hello-art | ||
path: /tmp/hello_world.txt | ||
script: | ||
command: | ||
- python | ||
image: python:3.8 | ||
source: "import os\nimport sys\nsys.path.append(os.getcwd())\nwith open('/tmp/hello_world.txt',\ | ||
\ 'wb') as f:\n f.write('hello world')" | ||
- inputs: | ||
artifacts: | ||
- name: message | ||
path: /tmp/message | ||
name: print-message | ||
script: | ||
command: | ||
- python | ||
image: python:3.8 | ||
source: "import os\nimport sys\nsys.path.append(os.getcwd())\nwith open('//tmp/message',\ | ||
\ 'rb') as f:\n message = f.readline()\nprint(message)" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
from hera.workflows import Artifact, Steps, Workflow, script | ||
|
||
|
||
@script(outputs=Artifact(name="hello-art", path="/tmp/hello_world.txt")) | ||
def whalesay(): | ||
with open("/tmp/hello_world.txt", "wb") as f: | ||
f.write("hello world") | ||
|
||
|
||
@script(inputs=Artifact(name="message", path="/tmp/message")) | ||
def print_message(): | ||
with open("//tmp/message", "rb") as f: | ||
message = f.readline() | ||
print(message) | ||
|
||
|
||
with Workflow(generate_name="artifact-passing-", entrypoint="artifact-example") as w: | ||
with Steps(name="artifact-example") as s: | ||
whalesay(name="generate-artifact") | ||
print_message( | ||
name="consume-artifact", | ||
arguments=[Artifact(name="message", from_="{{steps.generate-artifact.outputs.artifacts.hello-art}}")], | ||
) |