Merge pull request #579 from TomChv/refacto-random

Refactor random
This commit is contained in:
Andrea Luzzardi 2021-06-07 14:54:08 -07:00 committed by GitHub
commit 4365541d4d
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
20 changed files with 288 additions and 216 deletions

View File

@ -11,8 +11,10 @@ TestConfig: awsConfig: aws.#Config & {
} }
TestECR: { TestECR: {
random: #Random & {}
repository: "125635003186.dkr.ecr.\(TestConfig.awsConfig.region).amazonaws.com/dagger-ci" repository: "125635003186.dkr.ecr.\(TestConfig.awsConfig.region).amazonaws.com/dagger-ci"
tag: "test-ecr-\(random)" tag: "test-ecr-\(random.out)"
creds: ecr.#Credentials & { creds: ecr.#Credentials & {
config: TestConfig.awsConfig config: TestConfig.awsConfig
@ -25,7 +27,7 @@ TestECR: {
op.#DockerBuild & { op.#DockerBuild & {
dockerfile: """ dockerfile: """
FROM alpine FROM alpine
RUN echo \(random) > /test RUN echo \(random.out) > /test
""" """
}, },
@ -61,7 +63,7 @@ TestECR: {
op.#Exec & { op.#Exec & {
always: true always: true
args: [ args: [
"sh", "-c", "test $(cat test) = \(random)", "sh", "-c", "test $(cat test) = \(random.out)",
] ]
}, },
] ]
@ -76,7 +78,7 @@ TestECR: {
op.#DockerBuild & { op.#DockerBuild & {
dockerfile: #""" dockerfile: #"""
FROM \#(push.ref) FROM \#(push.ref)
RUN test $(cat test) = \#(random) RUN test $(cat test) = \#(random.out)
"""# """#
}, },
] ]

View File

@ -1,21 +1,33 @@
package ecr package ecr
import ( import (
"strconv"
"dagger.io/alpine" "dagger.io/alpine"
"dagger.io/dagger/op" "dagger.io/dagger/op"
) )
// Generate a random number #Random: {
random: { size: *12 | number
string
#up: [ out: {
op.#Load & {from: alpine.#Image}, string
op.#Exec & {
always: true #up: [
args: ["sh", "-c", "cat /dev/urandom | tr -dc 'a-z' | fold -w 10 | head -n 1 | tr -d '\n' > /rand"] op.#Load & {from: alpine.#Image},
},
op.#Export & { op.#Exec & {
source: "/rand" always: true
}, args: ["sh", "-c", #"""
] tr -cd '[:alpha:]' < /dev/urandom | fold -w "$SIZE" | head -n 1 | tr '[A-Z]' '[a-z]' | tr -d '\n' > /rand
"""#,
]
env: SIZE: strconv.FormatInt(size, 10)
},
op.#Export & {
source: "/rand"
},
]
}
} }

View File

@ -15,7 +15,9 @@ registry: {
} }
TestPushAndPull: { TestPushAndPull: {
ref: "daggerio/ci-test:\(random)" random: #Random & {}
ref: "daggerio/ci-test:\(random.out)"
// Create image // Create image
image: docker.#ImageFromDockerfile & { image: docker.#ImageFromDockerfile & {

View File

@ -1,21 +1,33 @@
package docker package docker
import ( import (
"strconv"
"dagger.io/alpine" "dagger.io/alpine"
"dagger.io/dagger/op" "dagger.io/dagger/op"
) )
// Generate a random number #Random: {
random: { size: *12 | number
string
#up: [ out: {
op.#Load & {from: alpine.#Image}, string
op.#Exec & {
always: true #up: [
args: ["sh", "-c", "cat /dev/urandom | tr -dc 'a-z' | fold -w 10 | head -n 1 | tr -d '\n' > /rand"] op.#Load & {from: alpine.#Image},
},
op.#Export & { op.#Exec & {
source: "/rand" always: true
}, args: ["sh", "-c", #"""
] tr -cd '[:alpha:]' < /dev/urandom | fold -w "$SIZE" | head -n 1 | tr '[A-Z]' '[a-z]' | tr -d '\n' > /rand
"""#,
]
env: SIZE: strconv.FormatInt(size, 10)
},
op.#Export & {
source: "/rand"
},
]
}
} }

View File

@ -9,11 +9,15 @@ key: dagger.#Secret @dagger(input)
passphrase: dagger.#Secret @dagger(input) passphrase: dagger.#Secret @dagger(input)
user: string @dagger(input) user: string @dagger(input)
TestRun: run: docker.#Run & { TestRun: {
host: "143.198.64.230" random: #Random & {}
ref: "nginx:alpine"
"user": user run: docker.#Run & {
"passphrase": passphrase host: "143.198.64.230"
name: "daggerci-test-simple-\(random)" ref: "nginx:alpine"
"key": key "user": user
"passphrase": passphrase
name: "daggerci-test-simple-\(random.out)"
"key": key
}
} }

View File

@ -1,20 +1,33 @@
package docker package docker
import ( import (
"dagger.io/dagger/op" "strconv"
"dagger.io/alpine" "dagger.io/alpine"
"dagger.io/dagger/op"
) )
random: { #Random: {
string size: *12 | number
#up: [
op.#Load & {from: alpine.#Image}, out: {
op.#Exec & { string
always: true
args: ["sh", "-c", "cat /dev/urandom | tr -dc 'a-z' | fold -w 10 | head -n 1 | tr -d '\n' > /rand"] #up: [
}, op.#Load & {from: alpine.#Image},
op.#Export & {
source: "/rand" op.#Exec & {
}, always: true
] args: ["sh", "-c", #"""
tr -cd '[:alpha:]' < /dev/urandom | fold -w "$SIZE" | head -n 1 | tr '[A-Z]' '[a-z]' | tr -d '\n' > /rand
"""#,
]
env: SIZE: strconv.FormatInt(size, 10)
},
op.#Export & {
source: "/rand"
},
]
}
} }

View File

@ -1,20 +1,33 @@
package docker package docker
import ( import (
"dagger.io/dagger/op" "strconv"
"dagger.io/alpine" "dagger.io/alpine"
"dagger.io/dagger/op"
) )
random: { #Random: {
string size: *12 | number
#up: [
op.#Load & {from: alpine.#Image}, out: {
op.#Exec & { string
always: true
args: ["sh", "-c", "cat /dev/urandom | tr -dc 'a-z' | fold -w 10 | head -n 1 | tr -d '\n' > /rand"] #up: [
}, op.#Load & {from: alpine.#Image},
op.#Export & {
source: "/rand" op.#Exec & {
}, always: true
] args: ["sh", "-c", #"""
tr -cd '[:alpha:]' < /dev/urandom | fold -w "$SIZE" | head -n 1 | tr '[A-Z]' '[a-z]' | tr -d '\n' > /rand
"""#,
]
env: SIZE: strconv.FormatInt(size, 10)
},
op.#Export & {
source: "/rand"
},
]
}
} }

View File

@ -7,10 +7,14 @@ import (
key: dagger.#Secret @dagger(input) key: dagger.#Secret @dagger(input)
TestRun: run: docker.#Run & { TestRun: {
host: "143.198.64.230" random: #Random & {}
ref: "nginx:alpine"
user: "root" run: docker.#Run & {
name: "daggerci-test-simple-\(random)" host: "143.198.64.230"
"key": key ref: "nginx:alpine"
user: "root"
name: "daggerci-test-simple-\(random.out)"
"key": key
}
} }

View File

@ -1,20 +1,33 @@
package docker package docker
import ( import (
"dagger.io/dagger/op" "strconv"
"dagger.io/alpine" "dagger.io/alpine"
"dagger.io/dagger/op"
) )
random: { #Random: {
string size: *12 | number
#up: [
op.#Load & {from: alpine.#Image}, out: {
op.#Exec & { string
always: true
args: ["sh", "-c", "cat /dev/urandom | tr -dc 'a-z' | fold -w 10 | head -n 1 | tr -d '\n' > /rand"] #up: [
}, op.#Load & {from: alpine.#Image},
op.#Export & {
source: "/rand" op.#Exec & {
}, always: true
] args: ["sh", "-c", #"""
tr -cd '[:alpha:]' < /dev/urandom | fold -w "$SIZE" | head -n 1 | tr '[A-Z]' '[a-z]' | tr -d '\n' > /rand
"""#,
]
env: SIZE: strconv.FormatInt(size, 10)
},
op.#Export & {
source: "/rand"
},
]
}
} }

View File

@ -10,11 +10,15 @@ key: dagger.#Secret @dagger(input)
passphrase: dagger.#Secret @dagger(input) passphrase: dagger.#Secret @dagger(input)
user: string @dagger(input) user: string @dagger(input)
TestRun: run: docker.#Run & { TestRun: {
host: "143.198.64.230" random: #Random & {}
ref: "nginx:alpine"
"user": user run: docker.#Run & {
"passphrase": passphrase host: "143.198.64.230"
name: "daggerci-test-simple-\(random)" ref: "nginx:alpine"
"key": key "user": user
"passphrase": passphrase
name: "daggerci-test-simple-\(random.out)"
"key": key
}
} }

View File

@ -9,8 +9,10 @@ import (
TestConfig: gcpConfig: gcp.#Config TestConfig: gcpConfig: gcp.#Config
TestGCR: { TestGCR: {
random: #Random & {}
repository: "gcr.io/dagger-ci/test" repository: "gcr.io/dagger-ci/test"
tag: "test-gcr-\(random)" tag: "test-gcr-\(random.out)"
creds: gcr.#Credentials & { creds: gcr.#Credentials & {
config: TestConfig.gcpConfig config: TestConfig.gcpConfig
@ -23,7 +25,7 @@ TestGCR: {
op.#DockerBuild & { op.#DockerBuild & {
dockerfile: """ dockerfile: """
FROM alpine FROM alpine
RUN echo \(random) > /test RUN echo \(random.out) > /test
""" """
}, },
@ -59,7 +61,7 @@ TestGCR: {
op.#Exec & { op.#Exec & {
always: true always: true
args: [ args: [
"sh", "-c", "test $(cat test) = \(random)", "sh", "-c", "test $(cat test) = \(random.out)",
] ]
}, },
] ]
@ -74,7 +76,7 @@ TestGCR: {
op.#DockerBuild & { op.#DockerBuild & {
dockerfile: #""" dockerfile: #"""
FROM \#(push.ref) FROM \#(push.ref)
RUN test $(cat test) = \#(random) RUN test $(cat test) = \#(random.out)
"""# """#
}, },
] ]

View File

@ -1,20 +1,33 @@
package gcr package gcr
import ( import (
"strconv"
"dagger.io/alpine" "dagger.io/alpine"
"dagger.io/dagger/op" "dagger.io/dagger/op"
) )
// Generate a random number #Random: {
random: { size: *12 | number
string
#up: [ out: {
op.#Load & {from: alpine.#Image}, string
op.#Exec & {
args: ["sh", "-c", "cat /dev/urandom | tr -dc 'a-z' | fold -w 10 | head -n 1 | tr -d '\n' > /rand"] #up: [
}, op.#Load & {from: alpine.#Image},
op.#Export & {
source: "/rand" op.#Exec & {
}, always: true
] args: ["sh", "-c", #"""
tr -cd '[:alpha:]' < /dev/urandom | fold -w "$SIZE" | head -n 1 | tr '[A-Z]' '[a-z]' | tr -d '\n' > /rand
"""#,
]
env: SIZE: strconv.FormatInt(size, 10)
},
op.#Export & {
source: "/rand"
},
]
}
} }

View File

@ -11,9 +11,11 @@ kubeconfig: dagger.#Secret @dagger(input)
// Deploy user local chart // Deploy user local chart
TestHelmSimpleChart: { TestHelmSimpleChart: {
random: #Random & {}
// Deploy chart // Deploy chart
deploy: helm.#Chart & { deploy: helm.#Chart & {
name: "dagger-test-helm-simple-chart-\(random)" name: "dagger-test-helm-simple-chart-\(random.out)"
namespace: "dagger-test" namespace: "dagger-test"
"kubeconfig": kubeconfig "kubeconfig": kubeconfig
chartSource: dagger.#Artifact chartSource: dagger.#Artifact
@ -28,9 +30,11 @@ TestHelmSimpleChart: {
// Deploy remote chart // Deploy remote chart
TestHelmRepoChart: { TestHelmRepoChart: {
random: #Random & {}
// Deploy chart // Deploy chart
deploy: helm.#Chart & { deploy: helm.#Chart & {
name: "dagger-test-helm-repository-\(random)" name: "dagger-test-helm-repository-\(random.out)"
namespace: "dagger-test" namespace: "dagger-test"
"kubeconfig": kubeconfig "kubeconfig": kubeconfig
chart: "redis" chart: "redis"

View File

@ -1,21 +1,33 @@
package helm package helm
import ( import (
"strconv"
"dagger.io/alpine" "dagger.io/alpine"
"dagger.io/dagger/op" "dagger.io/dagger/op"
) )
// Generate a random number #Random: {
random: { size: *12 | number
string
#up: [ out: {
op.#Load & {from: alpine.#Image}, string
op.#Exec & {
always: true #up: [
args: ["sh", "-c", "cat /dev/urandom | tr -dc 'a-z' | fold -w 10 | head -n 1 | tr -d '\n' > /rand"] op.#Load & {from: alpine.#Image},
},
op.#Export & { op.#Exec & {
source: "/rand" always: true
}, args: ["sh", "-c", #"""
] tr -cd '[:alpha:]' < /dev/urandom | fold -w "$SIZE" | head -n 1 | tr '[A-Z]' '[a-z]' | tr -d '\n' > /rand
"""#,
]
env: SIZE: strconv.FormatInt(size, 10)
},
op.#Export & {
source: "/rand"
},
]
}
} }

View File

@ -11,11 +11,13 @@ import (
kubeconfig: dagger.#Secret @dagger(input) kubeconfig: dagger.#Secret @dagger(input)
TestKubeApply: { TestKubeApply: {
random: #Random & {}
// Pod spec // Pod spec
kubeSrc: { kubeSrc: {
apiVersion: "v1" apiVersion: "v1"
kind: "Pod" kind: "Pod"
metadata: name: "kube-test-\(random)" metadata: name: "kube-test-\(random.out)"
spec: { spec: {
restartPolicy: "Never" restartPolicy: "Never"
containers: [{ containers: [{

View File

@ -1,21 +1,33 @@
package kubernetes package kubernetes
import ( import (
"strconv"
"dagger.io/alpine" "dagger.io/alpine"
"dagger.io/dagger/op" "dagger.io/dagger/op"
) )
// Generate a random number #Random: {
random: { size: *12 | number
string
#up: [ out: {
op.#Load & {from: alpine.#Image}, string
op.#Exec & {
always: true #up: [
args: ["sh", "-c", "cat /dev/urandom | tr -dc 'a-z' | fold -w 10 | head -n 1 | tr -d '\n' > /rand"] op.#Load & {from: alpine.#Image},
},
op.#Export & { op.#Exec & {
source: "/rand" always: true
}, args: ["sh", "-c", #"""
] tr -cd '[:alpha:]' < /dev/urandom | fold -w "$SIZE" | head -n 1 | tr '[A-Z]' '[a-z]' | tr -d '\n' > /rand
"""#,
]
env: SIZE: strconv.FormatInt(size, 10)
},
op.#Export & {
source: "/rand"
},
]
}
} }

View File

@ -7,10 +7,12 @@ import (
) )
TestNetlify: { TestNetlify: {
random: #Random & {}
// Generate a website containing the random number // Generate a website containing the random number
html: #up: [ html: #up: [
op.#WriteFile & { op.#WriteFile & {
content: random content: random.out
dest: "index.html" dest: "index.html"
}, },
] ]
@ -38,7 +40,7 @@ TestNetlify: {
"pipefail", "pipefail",
"-c", "-c",
#""" #"""
test "$(curl \#(deploy.deployUrl))" = "\#(random)" test "$(curl \#(deploy.deployUrl))" = "\#(random.out)"
"""#, """#,
] ]
}, },

View File

@ -1,20 +1,33 @@
package netlify package netlify
import ( import (
"strconv"
"dagger.io/alpine" "dagger.io/alpine"
"dagger.io/dagger/op" "dagger.io/dagger/op"
) )
// Generate a random number #Random: {
random: { size: *12 | number
string
#up: [ out: {
op.#Load & {from: alpine.#Image}, string
op.#Exec & {
args: ["sh", "-c", "cat /dev/urandom | tr -dc 'a-z' | fold -w 10 | head -n 1 | tr -d '\n' > /rand"] #up: [
}, op.#Load & {from: alpine.#Image},
op.#Export & {
source: "/rand" op.#Exec & {
}, always: true
] args: ["sh", "-c", #"""
tr -cd '[:alpha:]' < /dev/urandom | fold -w "$SIZE" | head -n 1 | tr '[A-Z]' '[a-z]' | tr -d '\n' > /rand
"""#,
]
env: SIZE: strconv.FormatInt(size, 10)
},
op.#Export & {
source: "/rand"
},
]
}
} }

View File

@ -1,46 +0,0 @@
package netlify
import (
"dagger.io/dagger/op"
"dagger.io/alpine"
"dagger.io/netlify"
)
TestNetlify: {
// Generate a website containing the random number
html: #up: [
op.#WriteFile & {
content: random
dest: "index.html"
},
]
// Deploy to netlify
deploy: netlify.#Site & {
contents: html
name: "dagger-test"
}
// Check if the deployed site has the random marker
check: #up: [
op.#Load & {
from: alpine.#Image & {
package: bash: "=~5.1"
package: curl: true
}
},
op.#Exec & {
args: [
"/bin/bash",
"--noprofile",
"--norc",
"-eo",
"pipefail",
"-c",
#"""
test "$(curl \#(deploy.deployUrl))" = "\#(random)"
"""#,
]
},
]
}

View File

@ -1,21 +0,0 @@
package netlify
import (
"dagger.io/alpine"
"dagger.io/dagger/op"
)
// Generate a random number
random: {
string
#up: [
op.#Load & {from: alpine.#Image},
op.#Exec & {
always: true
args: ["sh", "-c", "cat /dev/urandom | tr -dc 'a-z' | fold -w 10 | head -n 1 | tr -d '\n' > /rand"]
},
op.#Export & {
source: "/rand"
},
]
}