#How do I run shell commands in dagger v0.10.x

1 messages · Page 1 of 1 (latest)

fiery isle
#

How could I run shell commands with
kubectl get ns
Is there a way to attach my terminal where I run dagger to execute normal shell commands in my dagger pipeline?

vapid yacht
#

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

fiery isle
#

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"
            ]
        }
    }
}
vapid yacht
# fiery isle then call: `dagger call list-dir --dir ..` my dagger.json ```json { "name"...

👋 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

GitHub

Fixes #6155 and #6606
Adds support for views as described in the linked issue to support filtering individual directory args. This also required adding a way of configuring this from the CLI, which...

fiery isle
#

ah oki makes sense now! One last thing, using WithExec() is the only way in dagger to execute shell commands?

vapid yacht
fiery isle
#

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/

Dagger allows you to utilize confidential information, such as passwords, API keys, SSH keys and so on, in your Dagger Modules and Dagger Functions, without exposing those secrets in plaintext logs, writing them into the filesystem of containers you're building, or inserting them into the cache.

vapid yacht