Refactor random generation into a definition to make it reusable
Signed-off-by: Tom Chauveau <tom.chauveau@epitech.eu>
This commit is contained in:
@@ -11,8 +11,10 @@ TestConfig: awsConfig: aws.#Config & {
|
||||
}
|
||||
|
||||
TestECR: {
|
||||
random: #Random & {}
|
||||
|
||||
repository: "125635003186.dkr.ecr.\(TestConfig.awsConfig.region).amazonaws.com/dagger-ci"
|
||||
tag: "test-ecr-\(random)"
|
||||
tag: "test-ecr-\(random.out)"
|
||||
|
||||
creds: ecr.#Credentials & {
|
||||
config: TestConfig.awsConfig
|
||||
@@ -25,7 +27,7 @@ TestECR: {
|
||||
op.#DockerBuild & {
|
||||
dockerfile: """
|
||||
FROM alpine
|
||||
RUN echo \(random) > /test
|
||||
RUN echo \(random.out) > /test
|
||||
"""
|
||||
},
|
||||
|
||||
@@ -61,7 +63,7 @@ TestECR: {
|
||||
op.#Exec & {
|
||||
always: true
|
||||
args: [
|
||||
"sh", "-c", "test $(cat test) = \(random)",
|
||||
"sh", "-c", "test $(cat test) = \(random.out)",
|
||||
]
|
||||
},
|
||||
]
|
||||
@@ -76,7 +78,7 @@ TestECR: {
|
||||
op.#DockerBuild & {
|
||||
dockerfile: #"""
|
||||
FROM \#(push.ref)
|
||||
RUN test $(cat test) = \#(random)
|
||||
RUN test $(cat test) = \#(random.out)
|
||||
"""#
|
||||
},
|
||||
]
|
||||
|
@@ -1,21 +1,33 @@
|
||||
package ecr
|
||||
|
||||
import (
|
||||
"strconv"
|
||||
|
||||
"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"
|
||||
},
|
||||
]
|
||||
#Random: {
|
||||
size: *12 | number
|
||||
|
||||
out: {
|
||||
string
|
||||
|
||||
#up: [
|
||||
op.#Load & {from: alpine.#Image},
|
||||
|
||||
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"
|
||||
},
|
||||
]
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user