stdlib: add random package

Signed-off-by: Andrea Luzzardi <aluzzardi@gmail.com>
This commit is contained in:
Andrea Luzzardi
2021-06-08 11:46:31 -07:00
parent 4c40a87634
commit db0937c927
24 changed files with 152 additions and 580 deletions

View File

@@ -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)"
"""#,
]
},

View File

@@ -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"
},
]
}
}