#Chain Custom Functions

1 messages · Page 1 of 1 (latest)

ivory bough
#

Hello, I am trying to see if it's possible to chain custom functions together.
For example:

    @function
    def my_container(self) -> dagger.Container:
        return ( dag
                .container()
                .from_(address="alpine:latest")
                .with_exec(["apk", "add", "yq", "curl"])
        )
    @function
    async def my_test_func(self, container: dagger.Container) -> str:
        k = await container.with_exec(["echo", "{\Hello\": \"world\"}", "|", "yq"]).stdout()
        return k

dagger call my-container my-test-func --container

How would i approach this?

tiny bridge
#

given that it currently returns a Container, you can't chain it

tiny bridge
ivory bough
#

Awesome! Will try it out and update here.

ivory bough
#

It works great!

from typing import Self
container: Optional[dagger.Container]
    @function
    def my_container(self) -> dagger.Container:
        self.container = ( dag
                .container()
                .from_(address="alpine:latest")
                .with_exec(["apk", "add", "yq", "curl"])
        )
        return self

    @function
    async def my_test_func(self, container: dagger.Container) -> str:
        k = await self.container.with_exec(["echo", "{\Hello\": \"world\"}", "|", "yq"]).stdout()
        return k