#Command works locally but not inside dagger call

1 messages · Page 1 of 1 (latest)

proven sedge
#

Hi! I wrote this following function:

// Returns a container that has Okteto CLI with the correct context set
func (m *OktetodoDagger) Hi() *Container {

    token := os.Getenv("OKTETO_TOKEN")

    return dag.Container().
        From("okteto/okteto").
        WithEnvVariable("OKTETO_TOKEN", token).
        WithExec([]string{"okteto", "ctx", "use", "arsh.okteto.me"})
}

But when I try to run it I get an error. The same command when I copy paste and run locally it works (see attached screenshot). Any idea what I might be doing wrong?

trim sleet
#

Hey @proven sedge 👋 With functions, they don't have direct access to the host with methods like os.Getenv because each function runs as a sandbox container. The right way to accomplish this today would be to pass in the token as a *Secret argument to the function. More here https://docs.dagger.io/manuals/user/180138/host-env

Dagger Functions do not have access to environment variables on the host you invoke the Dagger Function from (i.e. the host you execute a CLI command like dagger call from). Instead, these variables need to be explicitly passed when executing dagger call.

proven sedge
#

Ah sorry I don't why I assumed the container would also have access to host environment variables, my bad. Thanks a ton Kyle!