#How could I make the best use of toolchains while keeping the flexibility ?

1 messages Β· Page 1 of 1 (latest)

marsh lava
#

I've started migrated some our microservices builds to use toolchains but I find myself in a bit of an odd situation and would like to understand if there's a way around it.

I had a microservice module use my golang module which could be explained like that

- New()
  - Initialize the golang module etc

- Build() *dagger.Container
  - call golang.Build
  - return the container produced

- Test() (string,error)
  - call golang.Test()
  - return (string, error)

- Serve() *dagger.Service
  - call Build()
  - Add Env Variables to container
  - return container.AsService()

Now that i'm moving to toolchain i can get rid of Build() and Test() and have the setup the customizations according to my needs
Which leaves Serve(), this wont/can't move to a toolchain because specific to the microservice.
I find myself in a situation where I cant get the *dagger.Container from Build() because it's out of my module now (whole point of using toolchain).
Sure, I could get a instance of the golang module and use it but it feels like it would be defeating the purpose of toolchains (and i would repeat myself injecting customizations via my module's code)

What would be an elegant way of resolving this ? Is there a way to get the configured toolchain directly in my module ?

dense jewel
#

so in your module's Serve function, you should be able to call dag.ToolchainName().Build() to get the container from the toolchain directly

marsh lava
marsh lava
nocturne vine
#

@marsh lava the way we do it in our own repo, is to move everything in toolchains (no more inline code in the project .dagger), and some toolchains are general while others are very specialized or even project-specific.

Then from there, as marcos said, toolchains can import functions from other toolchains

marsh lava
nocturne vine
dense jewel
marsh lava
nocturne vine
marsh lava
dense jewel
nocturne vine
#

customizations definitely won't be applied if you import toolchain A from toolchain B directly. Mmm that is giving me pause, need to think about that

marsh lava
#

it actually works

dense jewel
marsh lava
#

calling dag.Golang().Build() from my microservice reads the customizations from my dagger.json

#

ah that's awesome, and totally intended i'm sure πŸ˜„

marsh lava
nocturne vine
#

actually it's the other way around now I'm motivated to make sure this works also in the everything-is-a-toolchain model πŸ™‚

#

we just need to make sure the whole system is consistent, with a good balance of simplicity and control

#

one improvement we want to make is introduce a simple workspace configuration file, to unify all the different configuration knobs for your dagger project that aren't in module code (because of the sandboxing)

so: customizations, user defaults, etc

marsh lava
nocturne vine
#

that is an option, but the json format is quite user hostile..

marsh lava
#

what's the goto these days ? YAML ? TOML ?

nocturne vine
#

we're considering toml (recommended by @past panther ) because it's simpler and more constrained than yaml, which limits the temptation to distort it into pseudo-code πŸ™‚

nocturne vine
#

@marsh lava how strong of a negative reaction do you have to the idea of a project getting all its dagger functions from toolchains, with some toolchains being universally reusable, some only useful to a single project, and a whole spectrum in between?

marsh lava