#How do I run shell commands in dagger v0.10.x
1 messages · Page 1 of 1 (latest)
hey! not sure I follow the question. sh.runV("kubectl", "get", "ns") doesn't seem to be a part of the Dagger API.
functions in v0.10x did not change the underlying Dagger API, the main difference is that you have an entrypoint now where you can use dagger call which allows users that don't have the SDK runtime installed to be able to run the dagger pipelines
still facing issues to exclude my files with ls execution like this list-dir function:
// List files uploaded to Container
func (m *Ci) ListDir(ctx context.Context, dir *Directory) (string, error) {
return dag.
Container().
From("alpine").
WithMountedDirectory("/dir", dir).
WithExec([]string{"sh", "-c", "ls dir"}).Stdout(ctx)
// WithDefaultTerminalCmd([]string{"ls"}).Stdout(ctx)
// WithExec([]string{"ls", "/dir"}).
// Stdout(ctx)
}
then call: dagger call list-dir --dir ..
my dagger.json
{
"name": "ci",
"sdk": "go",
"source": "dagger",
"engineVersion": "v0.10.1",
"exclude": [
"ci",
".yarn",
".vscode",
".next",
"magefiles",
"node_modules",
".env",
"go.*",
"*.go"
],
"views": {
"default": {
"exclude": [
"ci",
".yarn",
".vscode",
".next",
"magefiles",
"node_modules",
".env",
"go.*",
"*.go"
]
}
}
}
👋 are you using a checkout of this PR? https://github.com/dagger/dagger/pull/6857 ? Because the exclude and views feature hasn't been merged yet into main
ah oki makes sense now! One last thing, using WithExec() is the only way in dagger to execute shell commands?
currently yes, is there anything missing there that you're needing?
I run my pipeline locally with magefile and dagger like: dagger run mage BuildAndDeploy which builds from Dockerfile and deploys to K8s and in my previous question I used sh.RunV which is indeed not from dagger API but from mage. In fact I can use both ways, I just was confused about the new Docs v0.10.x and thought I need to change everything to dagger call functions.
Anyway, what I am basically missing is to load env file with multiple KEY=VALUE pairs like .env, to use it like this would be fine but with more values: https://docs.dagger.io/developer-guide/go/203021/secrets/
well... that's the good thing about Dagger. Since it's code, you can load the .env file with any Go library like https://github.com/joho/godotenv and then inject that into yoru pipeline either via secrets or env variables