#Default value for platform?

1 messages ยท Page 1 of 1 (latest)

hollow wasp
#

I have a function that takes a platform (dagger.Platform in go). I want that argument to be optional. But if i use the null default value (I assume an empty string) it causes my build to blow up. How can I get a functional default value to a paltform argument?

sudden aurora
#

I don't think there's another way today.

#

cc @tidal lagoon

#

?

tidal lagoon
#

For arch, that works, I don't think there's a way to know the host OS though

hollow wasp
#

I saw another way being used somewhere in our CI but can't find it anymore ๐Ÿ˜ญ

#

some constant that exists in dagger.gen.go? cc @tiny ermine (sorry for the multiping)

sudden aurora
hollow wasp
#

Ah! Yeah that's it! Thank you

#

(hate that that requires error checking but anyway)

#

Would be cool to have a way to choose if I want the default to be 1) the engine's default platform, or 2) the caller's platform ๐Ÿ™‚

rancid oyster
#

DefaultPlatform() is the platform of the engine. For the host, it's supported by the CLI, using the special value "current":

dagger call my-func --platform=current
#

They use the same underlying library but may get different values because the CLI runs on the host while the API runs in a container.

hollow wasp
#

I know ๐Ÿ™‚ I want a way to choose between them in my pragmas

#

Proposal:

func Foo(
  // +optional
  // +default="client"      <-- OPTION 1: use the client's platform
  // +default="runtime"    <-- OPTION 2: use the current runtime platform (running the current function)
  // +default="engine"      <-- OPTION 3: use the engine's default platform
  platform dagger.Platform,
)

The CLI would map them:

$ dagger call foo --platform=client
$ dagger call foo --platform=runtime
$ dagger call foo --platform=engine

"runtime" and "engine" may not be the same if eg. the engine supports multiple platforms, and the current function is running in a non-default one, in qemu for some reason. I don't think there's a way to configure this at the moment, but it could conceivably happen

spice ruin