#knowing action invoked

1 messages · Page 1 of 1 (latest)

balmy galleon
#

Would that be a solution for you ?

#
package main

import (
    "dagger.io/dagger"

    "universe.dagger.io/alpine"
    "universe.dagger.io/docker"
)

dagger.#Plan & {
    client: env: {
        FOO:            string | *"auto"
        BAR:             string | *""
        BAZ:               string | *""
        TESTDIR:        string | *"okidoki"
    }

    actions: test: build: {
        // Test: simple docker.#Build
        simple: {
            image: docker.#Build & {
                steps: [
                    alpine.#Build,
                    docker.#Run & {
                        always: true
                        command: {
                            name: "sh"
                            flags: "-c": "echo -n $TEST"
                        }
                        env: TEST: client.env.TESTDIR
                    },
                ]
            }
        }
    }
}                
modest drum
#

some of them are secrets. I dont know how to get an empty default secret.

#

I have tried with optional params but its causing panics

#

I think because cue doesnt actually allow to reference optional fields without checks like if field != _|_ but dagger is not showing this cue error, its panicing instead

balmy galleon
#

Ok. The only way to do what you aim to do is to rely on dagger do --with.

modest drum
#

I also noticed that client commands are always run. This is causing simlar problems

#

some actions dont need the output of the client command. I dont know why it would run when its value is not referenced

#

I guess as soon as the client is touched, its completely evaluated.

balmy galleon
#
package main

import (
    "dagger.io/dagger"

    "universe.dagger.io/alpine"
    "universe.dagger.io/docker"
)

dagger.#Plan & {
    client: env: {
        if actions.test.build.ok {
            FOO:            string
            BAR:             string
            BAZ:               string
        }
        TESTDIR:        string | *"okidoki"
    }

    actions: test: build: {
        ok: bool | *false
        // Test: simple docker.#Build
        simple: {
            image: docker.#Build & {
                steps: [
                    alpine.#Build,
                    docker.#Run & {
                        always: true
                        command: {
                            name: "sh"
                            flags: "-c": "echo -n $TEST"
                        }
                        env: TEST: client.env.TESTDIR
                    },
                ]
            }
        }
    }
}
                ```
#
➜ dagger do test --log-format plain
11:33AM INFO  client.env | computing
11:33AM INFO  actions.test.build.simple.image._dag."0"._dag."0"._pull | computing
11:33AM INFO  client.env | completed    duration=0s
11:33AM INFO  actions.test.build.simple.image._dag."0"._dag."0"._pull | completed    duration=0s
11:33AM INFO  actions.test.build.simple.image._dag."1"._exec | computing
11:33AM INFO  actions.test.build.simple.image._dag."1"._exec | #3 0.069 okidoki
11:33AM INFO  actions.test.build.simple.image._dag."1"._exec | completed    duration=100ms
11:33AM INFO  actions.test.build.simple.image._dag."1"._exec | 

➜ dagger do test --log-format plain --with 'actions: test: build: ok: true'
11:33AM INFO  actions.test.build.simple.image._dag."0"._dag."0"._pull | computing
11:33AM INFO  client.env | computing
11:33AM ERROR client.env | failed: environment variable "BAR" not set
    duration=0s
11:33AM ERROR actions.test.build.simple.image._dag."0"._dag."0"._pull | cancelled    duration=0s
11:33AM FATAL system | failed to execute plan: task failed: client.env: environment variable "BAR" not set
modest drum
#

ah yes that was my tought and question

#

but you are using a boolean it seems. hmm

#

what is the rationale behind this?

#

ah, I see you use --with in the second command

balmy galleon
#

Here, we append directly in the DAG the value of ok, so that the

if actions.test.build.ok {
            FOO:            string
            BAR:             string
            BAZ:               string
        }
#

is not present at all in the DAG

#

These env var are not evaluated at all, because at evaluation, the DAG knows that ok is false or not

#

And will not contain these env vars

modest drum
#

yes that was my thought as well when I asked if I could know which action was invoked

#

the way you do it is somewhat hacky since you set the intendtion which action to run twice

#

its already said with dagger do some-action

#

would be nice to be able to do something like actions.selected == "test"

#

hm, this is causing another panic.

#

I think perhaps the best bet is using multiple plans by creating multiple cue files. But its not really nice either.