stdlib: add random package
Signed-off-by: Andrea Luzzardi <aluzzardi@gmail.com>
This commit is contained in:
@@ -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)"
|
||||
"""#,
|
||||
]
|
||||
},
|
||||
|
@@ -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"
|
||||
},
|
||||
]
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user