Is there a way to create ContainerTask with a stri...
# ask-the-community
f
Is there a way to create ContainerTask with a string input and use that input in the command without writing cumbersome wrapper scripts which need to be part of the image? https://docs.flyte.org/projects/cookbook/en/stable/auto/core/containerization/raw_container.html#container-tasks
k
Yes
Just pass it in the command
Also this is an interesting point shell tasks should work- and they should carry your shell scripts - do they not?
For container tasks - In the command you can write the entire script - just use shelex to split it?
f
but how do I pass the input to the command?
k
Or just write in one block
What do you mean, inputs are all files
Aah you can infact also pass the entire script as an input
You can use Flyte expansion system
Let me share
We used to have an example that shows how to use Flyte engines expansion system
f
yeah, thought that something like that should be possible... the raw container example is way to complicated
k
Sadly it’s only in Godoc - we lost an example somewhere- I will try to find. But till then - https://pkg.go.dev/github.com/flyteorg/flyteplugins/go/tasks/pluginmachinery/core/template
Cc @Eduardo Apolinario (eapolinario) fyi. Can we find the original example and keep that as well
@Felix Ruess all the {{.inputs.myinput}} is available
If myinput name is a string or primitive value it will auto expand
f
Hm... what am I missing?
Copy code
test_input = ContainerTask(
    name="test_container_input",
    image="<http://registry.roboception.de/tools/blender_scripts:testing|registry.roboception.de/tools/blender_scripts:testing>",
    requests=Resources(gpu="1"),
    imputs=kwtypes(objectname=str, dataset=str),
    command=shlex.split("echo {{.inputs.objectname}} {{.inputs.dataset}}")
)

@workflow
def wf(objectname: str):
    test_input(objectname=objectname, dataset="train")
just results in
ValueError: Received unexpected keyword argument objectname in function test_container_input
nevermind stupid typo
k
Worked
?
f
yeah, I had a typo:
imputs
instead of
inputs
thanks! But I do wonder why the container example doesn't use this simpler mechanism
k
It used to
Can you contribute one
e
That's a good idea. I brought them back in https://github.com/flyteorg/flytesnacks/pull/918
107 Views