Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Example using ImageSpec in Raw container #1773

Merged
merged 4 commits into from
Dec 14, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
import math
import sys


def write_output(output_dir, output_file, v):
with open(f"{output_dir}/{output_file}", "w") as f:
f.write(str(v))


def calculate_area(a, b):
return math.pi * a * b


def main(a, b, output_dir):
a = float(a)
b = float(b)

area = calculate_area(a, b)

write_output(output_dir, "area", area)
write_output(output_dir, "metadata", "[from python rawcontainer]")


if __name__ == "__main__":
a = sys.argv[1]
b = sys.argv[2]
output_dir = sys.argv[3]

main(a, b, output_dir)
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import logging

from flytekit import ContainerTask, kwtypes, task, workflow
from flytekit import ContainerTask, ImageSpec, kwtypes, task, workflow
from flytekit.core.base_task import TaskMetadata

logger = logging.getLogger(__file__)
Expand Down Expand Up @@ -29,16 +29,22 @@
metadata=TaskMetadata(cache=True, cache_version="1.0"),
)

# use `ImageSpec` to copy files or directories into container `/root`
calculate_ellipse_area_python = ContainerTask(
name="ellipse-area-metadata-python",
input_data_dir="/var/inputs",
output_data_dir="/var/outputs",
inputs=kwtypes(a=float, b=float),
outputs=kwtypes(area=float, metadata=str),
image="ghcr.io/flyteorg/rawcontainers-python:v2",
image=ImageSpec(
base_image="ghcr.io/flyteorg/rawcontainers-python:v2",
registry="localhost:30000",
builder="default",
copy=["calculate-ellipse-area-new.py"],
),
command=[
"python",
"calculate-ellipse-area.py",
"calculate-ellipse-area-new.py",
"{{.inputs.a}}",
"{{.inputs.b}}",
"/var/outputs",
Expand Down
Loading