Merge pull request #426 from TomChv/tests-examples-docker

Add tests for docker example
This commit is contained in:
Andrea Luzzardi 2021-05-14 12:23:12 -07:00 committed by GitHub
commit c85b25cc6c
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
12 changed files with 216 additions and 3 deletions

View File

@ -9,6 +9,6 @@ import (
source: dagger.#Artifact
// Container image
container: docker.#ImageFromSource & {
container: docker.#Build & {
"source": source
}

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
// Build a Docker image from the provided Dockerfile contents

View File

@ -19,6 +19,11 @@ skip_unless_secrets_available() {
sops exec-file "$inputFile" echo > /dev/null 2>&1 || skip "$inputFile cannot be decrypted"
}
skip_unless_file_exist() {
local inputFile="$1"
test -f "$inputFile" || skip "$inputFile does not exist"
}
skip_unless_local_kube() {
if [ -f ~/.kube/config ] && grep -q "user: kind-kind" ~/.kube/config &> /dev/null && grep -q "127.0.0.1" ~/.kube/config &> /dev/null; then
echo "Kubernetes available"

View File

@ -60,6 +60,24 @@ setup() {
"$DAGGER" compute "$TESTDIR"/stdlib/aws/ecr --input-yaml "$TESTDIR"/stdlib/aws/inputs.yaml
}
@test "stdlib: docker-build" {
skip_unless_file_exist "$TESTDIR"/stdlib/docker/build/Dockerfile
"$DAGGER" compute "$TESTDIR"/stdlib/docker/build/ --input-dir source="$TESTDIR"/stdlib/docker/build
}
@test "stdlib: docker-dockerfile" {
"$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" {
skip_unless_secrets_available "$TESTDIR"/stdlib/aws/inputs.yaml

View File

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

View File

@ -0,0 +1,31 @@
package docker
import (
"dagger.io/dagger"
"dagger.io/dagger/op"
"dagger.io/docker"
)
// Build a Docker image from source, using included Dockerfile
source: dagger.#Artifact
TestBuild: {
image: docker.#Build & {
"source": source
}
verify: #up: [
op.#Load & {
from: image
},
op.#Exec & {
always: true
args: [
"sh", "-c", """
grep -q "test" /test.txt
""",
]
},
]
}

View File

@ -0,0 +1,34 @@
package docker
import (
"dagger.io/dagger"
"dagger.io/dagger/op"
"dagger.io/docker"
)
source: dagger.#Artifact
TestImageFromDockerfile: {
image: docker.#ImageFromDockerfile & {
dockerfile: """
FROM alpine
COPY test.txt /test.txt
"""
context: source
}
verify: #up: [
op.#Load & {
from: image
},
op.#Exec & {
always: true
args: [
"sh", "-c", """
grep -q "test" /test.txt
""",
]
},
]
}

View File

@ -0,0 +1 @@
test

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/moMd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0OS
-----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