Hello!
I'm working on a PoC to explore using Dagger to retro-fit an existing CI.
I'm currently struggling with trying to access the Host Env. The existing CI is dense with Environment Variables, and there's a lot of embedded steps.
For example, we connect to Hashicorp vault to pull secrets into the CI, and this requires 4 envvars set in CircleCI's context (vault address, role, namespace, and an OIDC token).
My hope had been to create a Module that abstracts away the Vault items so end users can focus on just writing their steps, and if they need secrets, they can import and init the module:
func (m *MyDaggerModule) Build(
ctx context.Context,
// +defaultPath="/"
source *dagger.Directory,
) (string, error) {
vClient, err := vault.NewClient(vault.ClientConfig{}, dag)
dag.Container().From("alpine:latest").
WithEnvVariable("GITHUB_TOKEN", vClient.Fetch("GITHUB_TOKEN")).Etc()
// etc etc
Sadly this doesn't seem to work, as the Env isn't accessible from the Dagger function.
Even running something like:
os.Environ
Shows a limited set of Env vars.
The story is different if running "dagger run env", but I'm unclear on the difference between run and call.
It seems like the preferred method is soemthing along the lines of defining each variable you want from teh Host Env and passing it explicilty...
func (m *MyDaggerModule) Build(
ctx context.Context,
// +defaultPath="/"
source *dagger.Directory,
// vaultAddr the Address of HC Vault
vaultAddr string,
) (string, error) {
dagger call build --vault-addr env://VAULT_ADDR
But for an existing CI with 30+ env... this is not really feasible nor scalable. It kind of shatters the dream of building out setup modules that abstract away the setup and get out of the way of end users.
I sure the use of Vault in EVERY CI step is likely bloated, and maybe the answer is forcing developers to be more intentional with usage.
Seeking guidance on what the best practice is here?
I had been hoping to bundle everything up into dagger, but lack of access to Host Context makes this very difficult. Even an .env file isn't realistic, since I couldn't make a function to read and bundle the env without running it as privileged.