From db0937c9275b471f8ad648eb02edb65c51e3a6a6 Mon Sep 17 00:00:00 2001 From: Andrea Luzzardi Date: Tue, 8 Jun 2021 11:46:31 -0700 Subject: [PATCH] stdlib: add random package Signed-off-by: Andrea Luzzardi --- stdlib/random/string.cue | 69 +++++++++++++++++++ tests/ops/push-container/main.cue | 25 ++++--- tests/ops/push-container/random.cue | 49 ------------- .../aws/ecr/.dagger/env/default/plan/ecr.cue | 13 ++-- .../ecr/.dagger/env/default/plan/random.cue | 49 ------------- tests/stdlib/docker/push-pull/push-pull.cue | 7 +- tests/stdlib/docker/push-pull/random.cue | 49 ------------- .../local/.dagger/env/default/plan/local.cue | 7 +- .../local/.dagger/env/default/plan/random.cue | 49 ------------- .../.dagger/env/default/plan/passphrase.cue | 7 +- .../.dagger/env/default/plan/passphrase.cue | 7 +- .../.dagger/env/default/plan/random.cue | 49 ------------- .../.dagger/env/default/plan/random.cue | 49 ------------- .../env/default/plan/wrong-passphrase.cue | 7 +- .../ssh/.dagger/env/default/plan/random.cue | 49 ------------- .../ssh/.dagger/env/default/plan/simple.cue | 9 +-- .../gcp/gcr/.dagger/env/default/plan/gcr.cue | 13 ++-- .../gcr/.dagger/env/default/plan/random.cue | 49 ------------- tests/stdlib/kubernetes/helm/helm.cue | 13 ++-- tests/stdlib/kubernetes/helm/random.cue | 49 ------------- tests/stdlib/kubernetes/kubernetes.cue | 7 +- tests/stdlib/kubernetes/random.cue | 49 ------------- .../.dagger/env/default/plan/netlify.cue | 9 ++- .../.dagger/env/default/plan/random.cue | 49 ------------- 24 files changed, 152 insertions(+), 580 deletions(-) create mode 100644 stdlib/random/string.cue delete mode 100644 tests/ops/push-container/random.cue delete mode 100644 tests/stdlib/aws/ecr/.dagger/env/default/plan/random.cue delete mode 100644 tests/stdlib/docker/push-pull/random.cue delete mode 100644 tests/stdlib/docker/run/local/.dagger/env/default/plan/random.cue delete mode 100644 tests/stdlib/docker/run/ssh-passphrase/.dagger/env/default/plan/random.cue delete mode 100644 tests/stdlib/docker/run/ssh-wrong-passphrase/.dagger/env/default/plan/random.cue delete mode 100644 tests/stdlib/docker/run/ssh/.dagger/env/default/plan/random.cue delete mode 100644 tests/stdlib/gcp/gcr/.dagger/env/default/plan/random.cue delete mode 100644 tests/stdlib/kubernetes/helm/random.cue delete mode 100644 tests/stdlib/kubernetes/random.cue delete mode 100644 tests/stdlib/netlify/.dagger/env/default/plan/random.cue diff --git a/stdlib/random/string.cue b/stdlib/random/string.cue new file mode 100644 index 00000000..7fe66ac1 --- /dev/null +++ b/stdlib/random/string.cue @@ -0,0 +1,69 @@ +// Random generation utilities. +// +// Example: +// ``` +// str: random.#String & { +// seed: "str" +// length: 10 +// } +// ``` +package random + +import ( + "strconv" + + "dagger.io/alpine" + "dagger.io/dagger/op" +) + +// Generate a random string +#String: { + // Seed of the random string to generate. + // When using the same `seed`, the same random string will be generated + // because of caching. + // FIXME: this is necessary because of https://github.com/dagger/dagger/issues/591 + seed: string @dagger(input) + + // length of the string + length: *12 | number @dagger(input) + + // generated random string + out: { + string + + #up: [ + op.#Load & {from: alpine.#Image & { + package: python3: "=~3.8" + }}, + + op.#WriteFile & { + dest: "/entrypoint.py" + content: #""" + import random + import string + import os + + length = int(os.environ['LENGTH']) + letters = string.ascii_lowercase + + print ( ''.join(random.choice(letters) for i in range(length)) ) + """# + }, + + op.#Exec & { + args: ["sh", "-c", #""" + printf "$(python3 /entrypoint.py)" > /rand + """#, + ] + env: LENGTH: strconv.FormatInt(length, 10) + env: SEED: seed + + always: true + }, + + op.#Export & { + source: "/rand" + }, + ] + } @dagger(output) +} diff --git a/tests/ops/push-container/main.cue b/tests/ops/push-container/main.cue index 7d39e1bb..13e3827a 100644 --- a/tests/ops/push-container/main.cue +++ b/tests/ops/push-container/main.cue @@ -3,6 +3,7 @@ package main import ( "dagger.io/dagger/op" "dagger.io/alpine" + "dagger.io/random" ) registry: { @@ -11,15 +12,19 @@ registry: { } TestPushContainer: { + tag: random.#String & { + seed: "push-container" + } + // Push an image with a random tag push: { - ref: "daggerio/ci-test:\(random)" + ref: "daggerio/ci-test:\(tag.out)" #up: [ op.#DockerLogin & { registry }, op.#WriteFile & { - content: random + content: tag.out dest: "/rand" }, op.#PushContainer & { @@ -41,7 +46,7 @@ TestPushContainer: { op.#Exec & { args: [ "sh", "-c", #""" - test "$(cat /src/rand)" = "\#(random)" + test "$(cat /src/rand)" = "\#(tag.out)" """#, ] mount: "/src": from: pull @@ -51,14 +56,18 @@ TestPushContainer: { // Ensures image metadata is preserved in a push TestPushContainerMetadata: { + tag: random.#String & { + seed: "container-metadata" + } + // `docker build` using an `ENV` and push the image push: { - ref: "daggerio/ci-test:\(random)-dockerbuild" + ref: "daggerio/ci-test:\(tag.out)-dockerbuild" #up: [ op.#DockerBuild & { dockerfile: #""" FROM alpine:latest@sha256:ab00606a42621fb68f2ed6ad3c88be54397f981a7b70a79db3d1172b11c4367d - ENV CHECK \#(random) + ENV CHECK \#(tag.out) """# }, op.#PushContainer & { @@ -76,7 +85,7 @@ TestPushContainerMetadata: { args: [ "sh", "-c", #""" env - test "$CHECK" = "\#(random)" + test "$CHECK" = "\#(tag.out)" """#, ] }, @@ -85,7 +94,7 @@ TestPushContainerMetadata: { // Do a FetchContainer followed by a PushContainer, make sure // the ENV is preserved pullPush: { - ref: "daggerio/ci-test:\(random)-pullpush" + ref: "daggerio/ci-test:\(tag.out)-pullpush" #up: [ op.#FetchContainer & { @@ -104,7 +113,7 @@ TestPushContainerMetadata: { op.#Exec & { args: [ "sh", "-c", #""" - test "$CHECK" = "\#(random)" + test "$CHECK" = "\#(tag.out)" """#, ] }, diff --git a/tests/ops/push-container/random.cue b/tests/ops/push-container/random.cue deleted file mode 100644 index 5787a9e1..00000000 --- a/tests/ops/push-container/random.cue +++ /dev/null @@ -1,49 +0,0 @@ -package main - -import ( - "strconv" - - "dagger.io/alpine" - "dagger.io/dagger/op" -) - -#Random: { - size: *12 | number - - out: { - string - - #up: [ - op.#Load & {from: alpine.#Image & { - package: python3: "=~3.8" - }}, - - op.#WriteFile & { - dest: "/entrypoint.py" - content: #""" - import random - import string - import os - - size = int(os.environ['SIZE']) - letters = string.ascii_lowercase - - print ( ''.join(random.choice(letters) for i in range(size)) ) - """# - }, - - op.#Exec & { - always: true - args: ["sh", "-c", #""" - printf "$(python3 /entrypoint.py)" > /rand - """#, - ] - env: SIZE: strconv.FormatInt(size, 10) - }, - - op.#Export & { - source: "/rand" - }, - ] - } -} diff --git a/tests/stdlib/aws/ecr/.dagger/env/default/plan/ecr.cue b/tests/stdlib/aws/ecr/.dagger/env/default/plan/ecr.cue index 96a6c982..2e094048 100644 --- a/tests/stdlib/aws/ecr/.dagger/env/default/plan/ecr.cue +++ b/tests/stdlib/aws/ecr/.dagger/env/default/plan/ecr.cue @@ -4,6 +4,7 @@ import ( "dagger.io/aws" "dagger.io/aws/ecr" "dagger.io/dagger/op" + "dagger.io/random" ) TestConfig: awsConfig: aws.#Config & { @@ -11,10 +12,12 @@ TestConfig: awsConfig: aws.#Config & { } TestECR: { - random: #Random & {} + suffix: random.#String & { + seed: "" + } repository: "125635003186.dkr.ecr.\(TestConfig.awsConfig.region).amazonaws.com/dagger-ci" - tag: "test-ecr-\(random.out)" + tag: "test-ecr-\(suffix.out)" creds: ecr.#Credentials & { config: TestConfig.awsConfig @@ -27,7 +30,7 @@ TestECR: { op.#DockerBuild & { dockerfile: """ FROM alpine - RUN echo \(random.out) > /test + RUN echo \(suffix.out) > /test """ }, @@ -63,7 +66,7 @@ TestECR: { op.#Exec & { always: true args: [ - "sh", "-c", "test $(cat test) = \(random.out)", + "sh", "-c", "test $(cat test) = \(suffix.out)", ] }, ] @@ -78,7 +81,7 @@ TestECR: { op.#DockerBuild & { dockerfile: #""" FROM \#(push.ref) - RUN test $(cat test) = \#(random.out) + RUN test $(cat test) = \#(suffix.out) """# }, ] diff --git a/tests/stdlib/aws/ecr/.dagger/env/default/plan/random.cue b/tests/stdlib/aws/ecr/.dagger/env/default/plan/random.cue deleted file mode 100644 index 5787a9e1..00000000 --- a/tests/stdlib/aws/ecr/.dagger/env/default/plan/random.cue +++ /dev/null @@ -1,49 +0,0 @@ -package main - -import ( - "strconv" - - "dagger.io/alpine" - "dagger.io/dagger/op" -) - -#Random: { - size: *12 | number - - out: { - string - - #up: [ - op.#Load & {from: alpine.#Image & { - package: python3: "=~3.8" - }}, - - op.#WriteFile & { - dest: "/entrypoint.py" - content: #""" - import random - import string - import os - - size = int(os.environ['SIZE']) - letters = string.ascii_lowercase - - print ( ''.join(random.choice(letters) for i in range(size)) ) - """# - }, - - op.#Exec & { - always: true - args: ["sh", "-c", #""" - printf "$(python3 /entrypoint.py)" > /rand - """#, - ] - env: SIZE: strconv.FormatInt(size, 10) - }, - - op.#Export & { - source: "/rand" - }, - ] - } -} diff --git a/tests/stdlib/docker/push-pull/push-pull.cue b/tests/stdlib/docker/push-pull/push-pull.cue index 41b82a37..edaad5b3 100644 --- a/tests/stdlib/docker/push-pull/push-pull.cue +++ b/tests/stdlib/docker/push-pull/push-pull.cue @@ -5,6 +5,7 @@ import ( "dagger.io/dagger/op" "dagger.io/alpine" "dagger.io/docker" + "dagger.io/random" ) source: dagger.#Artifact @@ -15,9 +16,11 @@ registry: { } TestPushAndPull: { - random: #Random & {} + tag: random.#String & { + seed: "" + } - ref: "daggerio/ci-test:\(random.out)" + ref: "daggerio/ci-test:\(tag.out)" // Create image image: docker.#ImageFromDockerfile & { diff --git a/tests/stdlib/docker/push-pull/random.cue b/tests/stdlib/docker/push-pull/random.cue deleted file mode 100644 index 5787a9e1..00000000 --- a/tests/stdlib/docker/push-pull/random.cue +++ /dev/null @@ -1,49 +0,0 @@ -package main - -import ( - "strconv" - - "dagger.io/alpine" - "dagger.io/dagger/op" -) - -#Random: { - size: *12 | number - - out: { - string - - #up: [ - op.#Load & {from: alpine.#Image & { - package: python3: "=~3.8" - }}, - - op.#WriteFile & { - dest: "/entrypoint.py" - content: #""" - import random - import string - import os - - size = int(os.environ['SIZE']) - letters = string.ascii_lowercase - - print ( ''.join(random.choice(letters) for i in range(size)) ) - """# - }, - - op.#Exec & { - always: true - args: ["sh", "-c", #""" - printf "$(python3 /entrypoint.py)" > /rand - """#, - ] - env: SIZE: strconv.FormatInt(size, 10) - }, - - op.#Export & { - source: "/rand" - }, - ] - } -} diff --git a/tests/stdlib/docker/run/local/.dagger/env/default/plan/local.cue b/tests/stdlib/docker/run/local/.dagger/env/default/plan/local.cue index 7dec865e..1862365f 100644 --- a/tests/stdlib/docker/run/local/.dagger/env/default/plan/local.cue +++ b/tests/stdlib/docker/run/local/.dagger/env/default/plan/local.cue @@ -3,13 +3,16 @@ package main import ( "dagger.io/docker" "dagger.io/dagger" + "dagger.io/random" ) TestRun: { - random: #Random & {} + suffix: random.#String & { + seed: "" + } run: docker.#Run & { - name: "daggerci-test-local-\(random.out)" + name: "daggerci-test-local-\(suffix.out)" ref: "hello-world" } } diff --git a/tests/stdlib/docker/run/local/.dagger/env/default/plan/random.cue b/tests/stdlib/docker/run/local/.dagger/env/default/plan/random.cue deleted file mode 100644 index 5787a9e1..00000000 --- a/tests/stdlib/docker/run/local/.dagger/env/default/plan/random.cue +++ /dev/null @@ -1,49 +0,0 @@ -package main - -import ( - "strconv" - - "dagger.io/alpine" - "dagger.io/dagger/op" -) - -#Random: { - size: *12 | number - - out: { - string - - #up: [ - op.#Load & {from: alpine.#Image & { - package: python3: "=~3.8" - }}, - - op.#WriteFile & { - dest: "/entrypoint.py" - content: #""" - import random - import string - import os - - size = int(os.environ['SIZE']) - letters = string.ascii_lowercase - - print ( ''.join(random.choice(letters) for i in range(size)) ) - """# - }, - - op.#Exec & { - always: true - args: ["sh", "-c", #""" - printf "$(python3 /entrypoint.py)" > /rand - """#, - ] - env: SIZE: strconv.FormatInt(size, 10) - }, - - op.#Export & { - source: "/rand" - }, - ] - } -} diff --git a/tests/stdlib/docker/run/passphrase/.dagger/env/default/plan/passphrase.cue b/tests/stdlib/docker/run/passphrase/.dagger/env/default/plan/passphrase.cue index e15adc7c..091272b0 100644 --- a/tests/stdlib/docker/run/passphrase/.dagger/env/default/plan/passphrase.cue +++ b/tests/stdlib/docker/run/passphrase/.dagger/env/default/plan/passphrase.cue @@ -3,6 +3,7 @@ package docker import ( "dagger.io/docker" "dagger.io/dagger" + "dagger.io/random" ) key: dagger.#Secret @dagger(input) @@ -10,14 +11,16 @@ passphrase: dagger.#Secret @dagger(input) user: string @dagger(input) TestRun: { - random: #Random & {} + suffix: random.#String & { + seed: "" + } run: docker.#Run & { host: "143.198.64.230" ref: "nginx:alpine" "user": user "passphrase": passphrase - name: "daggerci-test-simple-\(random.out)" + name: "daggerci-test-simple-\(suffix.out)" "key": key } } diff --git a/tests/stdlib/docker/run/ssh-passphrase/.dagger/env/default/plan/passphrase.cue b/tests/stdlib/docker/run/ssh-passphrase/.dagger/env/default/plan/passphrase.cue index e058b1ca..f29a77a3 100644 --- a/tests/stdlib/docker/run/ssh-passphrase/.dagger/env/default/plan/passphrase.cue +++ b/tests/stdlib/docker/run/ssh-passphrase/.dagger/env/default/plan/passphrase.cue @@ -3,6 +3,7 @@ package main import ( "dagger.io/docker" "dagger.io/dagger" + "dagger.io/random" ) TestConfig: { @@ -13,11 +14,13 @@ TestConfig: { } TestRun: { - random: #Random & {} + suffix: random.#String & { + seed: "" + } run: docker.#Run & { ref: "hello-world" - name: "daggerci-test-simple-\(random.out)" + name: "daggerci-test-simple-\(suffix.out)" ssh: { host: TestConfig.host diff --git a/tests/stdlib/docker/run/ssh-passphrase/.dagger/env/default/plan/random.cue b/tests/stdlib/docker/run/ssh-passphrase/.dagger/env/default/plan/random.cue deleted file mode 100644 index 5787a9e1..00000000 --- a/tests/stdlib/docker/run/ssh-passphrase/.dagger/env/default/plan/random.cue +++ /dev/null @@ -1,49 +0,0 @@ -package main - -import ( - "strconv" - - "dagger.io/alpine" - "dagger.io/dagger/op" -) - -#Random: { - size: *12 | number - - out: { - string - - #up: [ - op.#Load & {from: alpine.#Image & { - package: python3: "=~3.8" - }}, - - op.#WriteFile & { - dest: "/entrypoint.py" - content: #""" - import random - import string - import os - - size = int(os.environ['SIZE']) - letters = string.ascii_lowercase - - print ( ''.join(random.choice(letters) for i in range(size)) ) - """# - }, - - op.#Exec & { - always: true - args: ["sh", "-c", #""" - printf "$(python3 /entrypoint.py)" > /rand - """#, - ] - env: SIZE: strconv.FormatInt(size, 10) - }, - - op.#Export & { - source: "/rand" - }, - ] - } -} diff --git a/tests/stdlib/docker/run/ssh-wrong-passphrase/.dagger/env/default/plan/random.cue b/tests/stdlib/docker/run/ssh-wrong-passphrase/.dagger/env/default/plan/random.cue deleted file mode 100644 index 5787a9e1..00000000 --- a/tests/stdlib/docker/run/ssh-wrong-passphrase/.dagger/env/default/plan/random.cue +++ /dev/null @@ -1,49 +0,0 @@ -package main - -import ( - "strconv" - - "dagger.io/alpine" - "dagger.io/dagger/op" -) - -#Random: { - size: *12 | number - - out: { - string - - #up: [ - op.#Load & {from: alpine.#Image & { - package: python3: "=~3.8" - }}, - - op.#WriteFile & { - dest: "/entrypoint.py" - content: #""" - import random - import string - import os - - size = int(os.environ['SIZE']) - letters = string.ascii_lowercase - - print ( ''.join(random.choice(letters) for i in range(size)) ) - """# - }, - - op.#Exec & { - always: true - args: ["sh", "-c", #""" - printf "$(python3 /entrypoint.py)" > /rand - """#, - ] - env: SIZE: strconv.FormatInt(size, 10) - }, - - op.#Export & { - source: "/rand" - }, - ] - } -} diff --git a/tests/stdlib/docker/run/ssh-wrong-passphrase/.dagger/env/default/plan/wrong-passphrase.cue b/tests/stdlib/docker/run/ssh-wrong-passphrase/.dagger/env/default/plan/wrong-passphrase.cue index 5c1bda50..092fa3e4 100644 --- a/tests/stdlib/docker/run/ssh-wrong-passphrase/.dagger/env/default/plan/wrong-passphrase.cue +++ b/tests/stdlib/docker/run/ssh-wrong-passphrase/.dagger/env/default/plan/wrong-passphrase.cue @@ -3,6 +3,7 @@ package main import ( "dagger.io/docker" "dagger.io/dagger" + "dagger.io/random" ) TestConfig: { @@ -13,10 +14,12 @@ TestConfig: { } TestRun: { - random: #Random & {} + suffix: random.#String & { + seed: "" + } run: docker.#Run & { - name: "daggerci-test-simple-\(random.out)" + name: "daggerci-test-simple-\(suffix.out)" ref: "hello-world" ssh: { diff --git a/tests/stdlib/docker/run/ssh/.dagger/env/default/plan/random.cue b/tests/stdlib/docker/run/ssh/.dagger/env/default/plan/random.cue deleted file mode 100644 index 5787a9e1..00000000 --- a/tests/stdlib/docker/run/ssh/.dagger/env/default/plan/random.cue +++ /dev/null @@ -1,49 +0,0 @@ -package main - -import ( - "strconv" - - "dagger.io/alpine" - "dagger.io/dagger/op" -) - -#Random: { - size: *12 | number - - out: { - string - - #up: [ - op.#Load & {from: alpine.#Image & { - package: python3: "=~3.8" - }}, - - op.#WriteFile & { - dest: "/entrypoint.py" - content: #""" - import random - import string - import os - - size = int(os.environ['SIZE']) - letters = string.ascii_lowercase - - print ( ''.join(random.choice(letters) for i in range(size)) ) - """# - }, - - op.#Exec & { - always: true - args: ["sh", "-c", #""" - printf "$(python3 /entrypoint.py)" > /rand - """#, - ] - env: SIZE: strconv.FormatInt(size, 10) - }, - - op.#Export & { - source: "/rand" - }, - ] - } -} diff --git a/tests/stdlib/docker/run/ssh/.dagger/env/default/plan/simple.cue b/tests/stdlib/docker/run/ssh/.dagger/env/default/plan/simple.cue index b1478042..830ffcbf 100644 --- a/tests/stdlib/docker/run/ssh/.dagger/env/default/plan/simple.cue +++ b/tests/stdlib/docker/run/ssh/.dagger/env/default/plan/simple.cue @@ -3,6 +3,7 @@ package main import ( "dagger.io/docker" "dagger.io/dagger" + "dagger.io/random" ) TestConfig: { @@ -11,13 +12,13 @@ TestConfig: { key: dagger.#Secret @dagger(input) } -key: dagger.#Secret @dagger(input) - TestSSH: { - random: #Random & {} + suffix: random.#String & { + seed: "" + } run: docker.#Run & { - name: "daggerci-test-simple-\(random.out)" + name: "daggerci-test-simple-\(suffix.out)" ref: "hello-world" ssh: { diff --git a/tests/stdlib/gcp/gcr/.dagger/env/default/plan/gcr.cue b/tests/stdlib/gcp/gcr/.dagger/env/default/plan/gcr.cue index 207a519d..e5adc2b6 100644 --- a/tests/stdlib/gcp/gcr/.dagger/env/default/plan/gcr.cue +++ b/tests/stdlib/gcp/gcr/.dagger/env/default/plan/gcr.cue @@ -4,15 +4,18 @@ import ( "dagger.io/gcp" "dagger.io/gcp/gcr" "dagger.io/dagger/op" + "dagger.io/random" ) TestConfig: gcpConfig: gcp.#Config TestGCR: { - random: #Random & {} + suffix: random.#String & { + seed: "" + } repository: "gcr.io/dagger-ci/test" - tag: "test-gcr-\(random.out)" + tag: "test-gcr-\(suffix.out)" creds: gcr.#Credentials & { config: TestConfig.gcpConfig @@ -25,7 +28,7 @@ TestGCR: { op.#DockerBuild & { dockerfile: """ FROM alpine - RUN echo \(random.out) > /test + RUN echo \(suffix.out) > /test """ }, @@ -61,7 +64,7 @@ TestGCR: { op.#Exec & { always: true args: [ - "sh", "-c", "test $(cat test) = \(random.out)", + "sh", "-c", "test $(cat test) = \(suffix.out)", ] }, ] @@ -76,7 +79,7 @@ TestGCR: { op.#DockerBuild & { dockerfile: #""" FROM \#(push.ref) - RUN test $(cat test) = \#(random.out) + RUN test $(cat test) = \#(suffix.out) """# }, ] diff --git a/tests/stdlib/gcp/gcr/.dagger/env/default/plan/random.cue b/tests/stdlib/gcp/gcr/.dagger/env/default/plan/random.cue deleted file mode 100644 index 5787a9e1..00000000 --- a/tests/stdlib/gcp/gcr/.dagger/env/default/plan/random.cue +++ /dev/null @@ -1,49 +0,0 @@ -package main - -import ( - "strconv" - - "dagger.io/alpine" - "dagger.io/dagger/op" -) - -#Random: { - size: *12 | number - - out: { - string - - #up: [ - op.#Load & {from: alpine.#Image & { - package: python3: "=~3.8" - }}, - - op.#WriteFile & { - dest: "/entrypoint.py" - content: #""" - import random - import string - import os - - size = int(os.environ['SIZE']) - letters = string.ascii_lowercase - - print ( ''.join(random.choice(letters) for i in range(size)) ) - """# - }, - - op.#Exec & { - always: true - args: ["sh", "-c", #""" - printf "$(python3 /entrypoint.py)" > /rand - """#, - ] - env: SIZE: strconv.FormatInt(size, 10) - }, - - op.#Export & { - source: "/rand" - }, - ] - } -} diff --git a/tests/stdlib/kubernetes/helm/helm.cue b/tests/stdlib/kubernetes/helm/helm.cue index 3b4dfdf6..04255d10 100644 --- a/tests/stdlib/kubernetes/helm/helm.cue +++ b/tests/stdlib/kubernetes/helm/helm.cue @@ -3,6 +3,7 @@ package main import ( "dagger.io/dagger" "dagger.io/kubernetes/helm" + "dagger.io/random" ) // We assume that a kinD cluster is running locally @@ -11,11 +12,13 @@ kubeconfig: dagger.#Secret @dagger(input) // Deploy user local chart TestHelmSimpleChart: { - random: #Random & {} + suffix: random.#String & { + seed: "simple" + } // Deploy chart deploy: helm.#Chart & { - name: "dagger-test-helm-simple-chart-\(random.out)" + name: "dagger-test-helm-simple-chart-\(suffix.out)" namespace: "dagger-test" "kubeconfig": kubeconfig chartSource: dagger.#Artifact @@ -30,11 +33,13 @@ TestHelmSimpleChart: { // Deploy remote chart TestHelmRepoChart: { - random: #Random & {} + suffix: random.#String & { + seed: "repo" + } // Deploy chart deploy: helm.#Chart & { - name: "dagger-test-helm-repository-\(random.out)" + name: "dagger-test-helm-repository-\(suffix.out)" namespace: "dagger-test" "kubeconfig": kubeconfig chart: "redis" diff --git a/tests/stdlib/kubernetes/helm/random.cue b/tests/stdlib/kubernetes/helm/random.cue deleted file mode 100644 index 5787a9e1..00000000 --- a/tests/stdlib/kubernetes/helm/random.cue +++ /dev/null @@ -1,49 +0,0 @@ -package main - -import ( - "strconv" - - "dagger.io/alpine" - "dagger.io/dagger/op" -) - -#Random: { - size: *12 | number - - out: { - string - - #up: [ - op.#Load & {from: alpine.#Image & { - package: python3: "=~3.8" - }}, - - op.#WriteFile & { - dest: "/entrypoint.py" - content: #""" - import random - import string - import os - - size = int(os.environ['SIZE']) - letters = string.ascii_lowercase - - print ( ''.join(random.choice(letters) for i in range(size)) ) - """# - }, - - op.#Exec & { - always: true - args: ["sh", "-c", #""" - printf "$(python3 /entrypoint.py)" > /rand - """#, - ] - env: SIZE: strconv.FormatInt(size, 10) - }, - - op.#Export & { - source: "/rand" - }, - ] - } -} diff --git a/tests/stdlib/kubernetes/kubernetes.cue b/tests/stdlib/kubernetes/kubernetes.cue index cd693930..9853f6bc 100644 --- a/tests/stdlib/kubernetes/kubernetes.cue +++ b/tests/stdlib/kubernetes/kubernetes.cue @@ -4,6 +4,7 @@ import ( "encoding/yaml" "dagger.io/dagger" "dagger.io/kubernetes" + "dagger.io/random" ) // We assume that a kinD cluster is running locally @@ -11,13 +12,15 @@ import ( kubeconfig: dagger.#Secret @dagger(input) TestKubeApply: { - random: #Random & {} + suffix: random.#String & { + seed: "" + } // Pod spec kubeSrc: { apiVersion: "v1" kind: "Pod" - metadata: name: "kube-test-\(random.out)" + metadata: name: "kube-test-\(suffix.out)" spec: { restartPolicy: "Never" containers: [{ diff --git a/tests/stdlib/kubernetes/random.cue b/tests/stdlib/kubernetes/random.cue deleted file mode 100644 index 5787a9e1..00000000 --- a/tests/stdlib/kubernetes/random.cue +++ /dev/null @@ -1,49 +0,0 @@ -package main - -import ( - "strconv" - - "dagger.io/alpine" - "dagger.io/dagger/op" -) - -#Random: { - size: *12 | number - - out: { - string - - #up: [ - op.#Load & {from: alpine.#Image & { - package: python3: "=~3.8" - }}, - - op.#WriteFile & { - dest: "/entrypoint.py" - content: #""" - import random - import string - import os - - size = int(os.environ['SIZE']) - letters = string.ascii_lowercase - - print ( ''.join(random.choice(letters) for i in range(size)) ) - """# - }, - - op.#Exec & { - always: true - args: ["sh", "-c", #""" - printf "$(python3 /entrypoint.py)" > /rand - """#, - ] - env: SIZE: strconv.FormatInt(size, 10) - }, - - op.#Export & { - source: "/rand" - }, - ] - } -} diff --git a/tests/stdlib/netlify/.dagger/env/default/plan/netlify.cue b/tests/stdlib/netlify/.dagger/env/default/plan/netlify.cue index bee7ccbb..68b35b9c 100644 --- a/tests/stdlib/netlify/.dagger/env/default/plan/netlify.cue +++ b/tests/stdlib/netlify/.dagger/env/default/plan/netlify.cue @@ -4,15 +4,18 @@ import ( "dagger.io/dagger/op" "dagger.io/alpine" "dagger.io/netlify" + "dagger.io/random" ) TestNetlify: { - random: #Random & {} + data: random.#String & { + seed: "" + } // Generate a website containing the random number html: #up: [ op.#WriteFile & { - content: random.out + content: data.out dest: "index.html" }, ] @@ -40,7 +43,7 @@ TestNetlify: { "pipefail", "-c", #""" - test "$(curl \#(deploy.deployUrl))" = "\#(random.out)" + test "$(curl \#(deploy.deployUrl))" = "\#(data.out)" """#, ] }, diff --git a/tests/stdlib/netlify/.dagger/env/default/plan/random.cue b/tests/stdlib/netlify/.dagger/env/default/plan/random.cue deleted file mode 100644 index 5787a9e1..00000000 --- a/tests/stdlib/netlify/.dagger/env/default/plan/random.cue +++ /dev/null @@ -1,49 +0,0 @@ -package main - -import ( - "strconv" - - "dagger.io/alpine" - "dagger.io/dagger/op" -) - -#Random: { - size: *12 | number - - out: { - string - - #up: [ - op.#Load & {from: alpine.#Image & { - package: python3: "=~3.8" - }}, - - op.#WriteFile & { - dest: "/entrypoint.py" - content: #""" - import random - import string - import os - - size = int(os.environ['SIZE']) - letters = string.ascii_lowercase - - print ( ''.join(random.choice(letters) for i in range(size)) ) - """# - }, - - op.#Exec & { - always: true - args: ["sh", "-c", #""" - printf "$(python3 /entrypoint.py)" > /rand - """#, - ] - env: SIZE: strconv.FormatInt(size, 10) - }, - - op.#Export & { - source: "/rand" - }, - ] - } -}