Add #Push definition and tests

Signed-off-by: Tom Chauveau <tom.chauveau@epitech.eu>
This commit is contained in:
Tom Chauveau 2021-05-13 18:52:22 +02:00
parent 24aee99ba9
commit 8ce8e8e01f
8 changed files with 132 additions and 42 deletions

View File

@ -27,7 +27,20 @@ import (
] ]
} }
// FIXME: #Push // Push a docker image
#Push: {
// Remote ref (example: "index.docker.io/alpine:latest")
ref: string
// Image
source: dagger.#Artifact
#up: [
op.#Load & {from: source},
op.#PushContainer & {"ref": ref},
]
}
// FIXME: #Run // FIXME: #Run
// Build a Docker image from the provided Dockerfile contents // Build a Docker image from the provided Dockerfile contents

View File

@ -17,12 +17,4 @@ setup() {
run curl -sS "$deployUrl" run curl -sS "$deployUrl"
assert_success assert_success
assert_output --partial "Todo App" assert_output --partial "Todo App"
}
@test "example: docker" {
skip_unless_file_exist "$TESTDIR"/examples/docker/Dockerfile
"$DAGGER" new --plan-dir "$TESTDIR"/../examples/docker/ docker
"$DAGGER" input dir source "$TESTDIR"/examples/docker/ -e "docker"
"$DAGGER" up -e "docker"
} }

View File

@ -1,2 +0,0 @@
FROM alpine
RUN echo test >> /test.txt

View File

@ -66,13 +66,18 @@ setup() {
"$DAGGER" compute "$TESTDIR"/stdlib/docker/build/ --input-dir source="$TESTDIR"/stdlib/docker/build "$DAGGER" compute "$TESTDIR"/stdlib/docker/build/ --input-dir source="$TESTDIR"/stdlib/docker/build
} }
@test "stdlib: docker-pull" {
"$DAGGER" compute "$TESTDIR"/stdlib/docker/pull/
}
@test "stdlib: docker-dockerfile" { @test "stdlib: docker-dockerfile" {
"$DAGGER" compute "$TESTDIR"/stdlib/docker/dockerfile/ --input-dir source="$TESTDIR"/stdlib/docker/dockerfile/testdata "$DAGGER" compute "$TESTDIR"/stdlib/docker/dockerfile/ --input-dir source="$TESTDIR"/stdlib/docker/dockerfile/testdata
} }
@test "stdlib: docker-push-and-pull" {
skip_unless_secrets_available "$TESTDIR"/stdlib/docker/push-pull/inputs.yaml
# check that they succeed with the credentials
run "$DAGGER" compute --input-yaml "$TESTDIR"/stdlib/docker/push-pull/inputs.yaml --input-dir source="$TESTDIR"/stdlib/docker/push-pull/testdata "$TESTDIR"/stdlib/docker/push-pull/
assert_success
}
@test "stdlib: terraform" { @test "stdlib: terraform" {
skip_unless_secrets_available "$TESTDIR"/stdlib/aws/inputs.yaml skip_unless_secrets_available "$TESTDIR"/stdlib/aws/inputs.yaml

View File

@ -1,27 +0,0 @@
package docker
import (
"dagger.io/dagger/op"
"dagger.io/docker"
)
TestImageFromRegistry: {
image: docker.#Pull & {
from: "index.docker.io/the0only0vasek/alpine-test"
}
verify: #up: [
op.#Load & {
from: image
},
op.#Exec & {
always: true
args: [
"sh", "-c", """
grep -q "test" /test.txt
""",
]
},
]
}

View File

@ -0,0 +1,34 @@
registry:
username: ENC[AES256_GCM,data:8AH6p9WHidanCA==,iv:ezThCQJv+bVBf8SdfSa2HFoP+eu6IZMPl5xvMOGDcps=,tag:mzR7xTKeQNDvkyd2Dm3AKw==,type:str]
secret: ENC[AES256_GCM,data:GtuaBAhFBw2JFaeuOm6mUr3m1j5fvCJjcWAzjsdU2xASFxwO,iv:YAXcRzBoemmef5PBdAOBa5acNPo4BoKH7Ngud/CWYfA=,tag:MCCUCOSutjRCI92raYrxdg==,type:str]
sops:
kms: []
gcp_kms: []
azure_kv: []
hc_vault: []
age: []
lastmodified: "2021-04-27T00:59:33Z"
mac: ENC[AES256_GCM,data:qk+oo4m5OpfuQ+R3pZUuvn+gqAk15OAJzOULrlYqt1FIDRk/Q5ah5QpIbVxeP1EDVyuY/V/E0ZngRlSV7Dyx6Cp/moMd8AFBHNgnTB+Lq+NmZ9HR1QMOxpbMpJmUGn7MqQ1Ys4wy0p2q2Y2+TuUpKwmRGJbGVYEVmqvV5OT3jhc=,iv:QsUFa2GVzy6iqqLXRz8HascQZPIIzKBhxHdlabov02k=,tag:7lk63FeXsOlTCgfmWd7zrg==,type:str]
pgp:
- created_at: "2021-03-18T22:59:59Z"
enc: |
-----BEGIN PGP MESSAGE-----
hQIMAzqVY590vudzAQ//etnfnpfCo9rAkctR+Fwg/7VdVL3Rov+6gnyjUnoN1BS1
8jnBF/86AZ7uK89dTcTZCsK1hKPxeYg1kJTKpA+zfDORupzTWcMrRyjwNk5wQ2Vg
N1adUwFsBQpk8WptpsU/ro6+3yH+Nn35begs6hP2fH/EQ9XOxw5gY0kp0AFjGaKJ
tRZVrr3f2hpLESo6LILRO97UXZiGcwTn5onslECL92260cU1nqEQp+ESK7XrdYIG
99oM3eXEraKw4WuQDaDE6U135aUl6vIJWD1JZzyr3RW3+5O9pn5rpN3Wc0TbDR6+
9Fs/TjuA1h5eJzbt+lkA74BtxPOBv9O7HJnWJpXjiG0VUGHdFXoq5Tr5Ol68RQxa
BWe7IfTO6FHN0xOl1dY7cn5jtf+xlFjL86s9OkrJUFa9lbQx8L/QPCeA2Xiu4tpW
+wTSel13k8Uv/JSGgLwSohW6N4XTQYdxPkO+a1V08adwFBXaGgqxfg0rNehcS5fp
y3TEq84cOlBsaI+rYpnOTPEajtYWfTe8WFf+lBOn1vZ9EiupjZtefGX2MIWPXoaK
kVBgRvzjp4/BY68yRvdi5sZFd2nakl+DOXzouuFbzsOkxL3o9FA9aCVsXtFqqzSG
Hvq4ZJ5ivXf6vQf+s7Tgc4qxW2CQwIPZVkHhQossrWgtkQ4WDAyzfhF0YuhEnpLS
XgGNLr82LMVmempaJd7GfAR2nwGnLUTYny1KoiW/1ie6DPwLZBX/UxPOplaS5wYH
Xd3gV3smg5xZ7/rfvzKTzJ1a5yH6D3xI05UtnUWdqojONcXS9NS+P7RArngJwSs=
=m0OS
-----END PGP MESSAGE-----
fp: 6CB37404020B5F0A0B41B5BB225EBAB0B936AC65
unencrypted_suffix: _unencrypted
version: 3.7.1

View File

@ -0,0 +1,74 @@
package docker
import (
"dagger.io/dagger"
"dagger.io/dagger/op"
"dagger.io/alpine"
"dagger.io/docker"
)
source: dagger.#Artifact
registry: {
username: string
secret: dagger.#Secret
}
TestPushAndPull: {
// Generate a random number
random: {
string
#up: [
op.#Load & {from: alpine.#Image},
op.#Exec & {
args: ["sh", "-c", "cat /dev/urandom | tr -dc 'a-z' | fold -w 10 | head -n 1 | tr -d '\n' > /rand"]
},
op.#Export & {
source: "/rand"
},
]
}
ref: "daggerio/ci-test:\(random)"
// Create image
image: docker.#ImageFromDockerfile & {
dockerfile: """
FROM alpine
COPY test.txt /test.txt
"""
context: source
}
// Login
login: #up: [
op.#DockerLogin & {
registry
},
]
// Push image
push: docker.#Push & {
"ref": ref
source: image
}
// Push image
pull: docker.#Pull & {
from: push.ref
}
// Check the content
verify: #up: [
op.#Load & {from: alpine.#Image},
op.#Exec & {
always: true
args: [
"sh", "-c", """
grep -q "test" /src/test.txt
""",
]
mount: "/src": from: pull
},
]
}

View File

@ -0,0 +1 @@
test