#Passing Function as Container Argument

1 messages · Page 1 of 1 (latest)

unique vapor
#

I am trying to get something to work that feels like it should be possible, but I am struggling to figure it out.

Following the docs here: https://docs.dagger.io/manuals/user/249202/arguments#container-arguments

Is it possible to pass in a container argument where the value for the argument is a dagger function that returns a container type?

I can easily do this via the SDK like this:

// Test Test Container Chains
func (m *Mariadb) Test() *Container {
    return m.Chain(m.Base("latest", "sample-database"))
}

But I want to be able to write command via the CLI like this and it does not seem to be possible.

dagger call chain --ctr base

Looking around Discord I do see this discussion where we said this was not possible (yet) - is that still the case? #daggernauts message

I think my mental model is that anything that is possible via the CLI is also possible via the SDK, but that does not seem to be the case here right?

Dagger Functions, just like regular functions, can accept arguments. In addition to basic types (string, boolean, integer, array...), Dagger also defines powerful core types which functions can use for their arguments: Directory, File, Container, Service, and Secret.

smoky geode
#

still not possible although it is on the roadmap to fix it. I'd say it's in scope for #1225586103122133083 cc @naive heron @runic lava @tall ridge

unique vapor
#

Thanks @smoky geode this is going to be a game changer 😄

unique vapor
#

@devout wave this is the last thing we were talking about last week - looks like there is one missing piece that is preventing us from doing the thing we discussed.

good news is that its something we will support in the near future 😄

smoky geode
unique vapor
tall ridge
#

I see 3 things being discussed here. For clarity:

  • Using core functions directly with dagger call (as per the "cheat" comment) is on the roadmap but doesn't seem to be what Lev's asking. How would you use it for that?
  • Syntax for the CLI to use a module's function as an argument in another function as described in dagger call chain --ctr base has never been discussed afaik, and doesn't seem viable.
  • What has been discussed is allowing to use IDs as values, which would permit something like dagger call chain --ctr $(dagger call base id), but it's blocked on IDs being valid or not outside a session like this.
#

I think my mental model is that anything that is possible via the CLI is also possible via the SDK, but that does not seem to be the case here right?

It's not quite. The CLI has access to host resources, while the SDK has a much better DX. We've discussed since the beginning that our preference should be for users to create a module to encode pipelines rather than rely on the CLI (unless you're debugging or experimenting). But still, allow the CLI to be powerful for those that want it if we can. Maybe what you want in this case could be dagger script ?

GitHub

TLDR: dagger call is very safe, but lacks the convenience of artisanal scripts. There is a way to get both: safety and convenience. Problem Now that Dagger Functions are generally available, the st...

unique vapor
# tall ridge > I think my mental model is that anything that is possible via the CLI is also ...

To the last point, I think the key idea for what I’m talking about is that the person using dagger like this would likely be a “consumer”, someone that’s doesn’t want to write a module for whatever reason but instead use dagger exclusively via the CLI.

In the Venn diagram of developers vs operators, this is most likely the “operator” persona that we’ve discussed in the past.

With that in mind I agree that dagger script seems like it would get us pretty far for this scenario.

tall ridge
#

Yeah, for non-programmers that may know only a bit of bash, the likelier solution would be the last point in my list (i.e., CLI accepting id values in arguments).