Merge pull request #331 from dagger/fix-double-exec

Fixed duplicated execution on `op.#Exec.always: true`
This commit is contained in:
Andrea Luzzardi 2021-04-15 13:09:00 -07:00 committed by GitHub
commit 84f914216d
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
6 changed files with 32 additions and 24 deletions

View File

@ -385,13 +385,10 @@ func (p *Pipeline) Exec(ctx context.Context, op *compiler.Value, st llb.State) (
}
// always?
// FIXME: initialize once for an entire compute job, to avoid cache misses
if cmd.Always {
cacheBuster, err := randomID(8)
if err != nil {
return st, err
}
opts = append(opts, llb.AddEnv("DAGGER_CACHEBUSTER", cacheBuster))
// FIXME: also disables persistent cache directories
// There's an ongoing proposal that would fix this: https://github.com/moby/buildkit/issues/1213
opts = append(opts, llb.IgnoreCache)
}
// mounts
if mounts := op.Lookup("mount"); mounts.Exists() {

View File

@ -1,15 +0,0 @@
package dagger
import (
"crypto/rand"
"fmt"
)
func randomID(size int) (string, error) {
b := make([]byte, size)
_, err := rand.Read(b)
if err != nil {
return "", err
}
return fmt.Sprintf("%x", b), nil
}

View File

@ -19,9 +19,7 @@ import (
out: string
aws.#Script & {
// FIXME: we should not rely on the cache for this but it's being
// executed several times if enabled: https://github.com/dagger/dagger/issues/42
// always: true
always: true
files: {
"/inputs/listenerArn": listenerArn

View File

@ -45,6 +45,7 @@ package op
do: "exec"
args: [...string]
env?: [string]: string
// `true` means also ignoring the mount cache volumes
always?: true | *false
dir: string | *"/"
mount: [string]: "tmpfs" | "cache" | {from: _, path: string | *"/"}

View File

@ -0,0 +1,25 @@
package main
import (
"dagger.io/alpine"
"dagger.io/dagger/op"
)
rand: {
string
#up: [
op.#Load & {from: alpine.#Image},
op.#Exec & {
always: true
args: ["sh", "-c", """
tr -dc A-Za-z0-9 </dev/urandom | head -c 13 > /id
"""]
},
op.#Export & {source: "/id"},
]
}
// If rand is executed twice, cue won't validate
ref1: rand
ref2: ref1

View File

@ -35,6 +35,8 @@ test::compute::simple(){
"$dagger" "${DAGGER_BINARY_ARGS[@]}" compute "$d"/compute/success/overload/flat
test::one "Compute: overloading #Component should work" --exit=0 \
"$dagger" "${DAGGER_BINARY_ARGS[@]}" compute "$d"/compute/success/overload/wrapped
test::one "Compute: Disabling the cache on exec should not compute twice when referenced by another key" --exit=0 \
"$dagger" "${DAGGER_BINARY_ARGS[@]}" compute "$d"/compute/success/exec-nocache
}
test::compute::dependencies(){