Add new Client API

Signed-off-by: Helder Correia <174525+helderco@users.noreply.github.com>
This commit is contained in:
Helder Correia
2022-03-07 12:12:39 -01:00
parent a5a0207dde
commit da90baa087
30 changed files with 1566 additions and 9 deletions

View File

@@ -0,0 +1,68 @@
package main
import (
"strings"
"dagger.io/dagger"
)
dagger.#Plan & {
client: commands: {
normal: {
name: "echo"
args: ["hello europa"]
}
relative: {
name: "cat"
args: ["./test.txt"]
}
secret: {
name: "tee"
stdout: dagger.#Secret
stdin: "hello secretive europa"
}
error: {
name: "sh"
flags: "-c": ">&2 echo 'error'"
stderr: string
}
invalid: name: "foobar"
}
actions: {
image: dagger.#Pull & {
source: "alpine:3.15.0@sha256:e7d88de73db3d3fd9b2d63aa7f447a10fd0220b7cbf39803c803f2af9ba256b3"
}
test: {
invalid: dagger.#Exec & {
input: image.output
args: ["echo", client.commands.invalid.stdout]
}
valid: {
normal: dagger.#Exec & {
input: image.output
args: ["test", strings.TrimSpace(client.commands.normal.stdout), "=", "hello europa"]
}
relative: dagger.#Exec & {
input: image.output
args: ["test", strings.TrimSpace(client.commands.relative.stdout), "=", "test"]
}
error: dagger.#Exec & {
input: image.output
args: ["test", strings.TrimSpace(client.commands.error.stderr), "=", "error"]
}
secret: dagger.#Exec & {
input: image.output
mounts: secret: {
dest: "/run/secrets/test"
contents: client.commands.secret.stdout
}
args: [
"sh", "-c",
#"""
test "$(cat /run/secrets/test)" = "hello secretive europa"
"""#,
]
}
}
}
}
}

View File

@@ -0,0 +1 @@
test

44
tests/plan/client/env/test.cue vendored Normal file
View File

@@ -0,0 +1,44 @@
package main
import (
"dagger.io/dagger"
)
dagger.#Plan & {
client: env: {
TEST_STRING: string
TEST_SECRET: dagger.#Secret
TEST_FAIL: "env"
}
actions: {
image: dagger.#Pull & {
source: "alpine:3.15.0@sha256:e7d88de73db3d3fd9b2d63aa7f447a10fd0220b7cbf39803c803f2af9ba256b3"
}
test: {
concrete: dagger.#Exec & {
input: image.output
args: [client.env.TEST_FAIL]
}
usage: {
string: dagger.#Exec & {
input: image.output
args: ["test", client.env.TEST_STRING, "=", "foo"]
}
secret: dagger.#Exec & {
input: image.output
mounts: secret: {
dest: "/run/secrets/test"
contents: client.env.TEST_SECRET
}
args: [
"sh", "-c",
#"""
test "$(cat /run/secrets/test)" = "bar"
ls -l /run/secrets/test | grep -- "-r--------"
"""#,
]
}
}
}
}
}

View File

@@ -0,0 +1,41 @@
package main
import (
"dagger.io/dagger"
)
dagger.#Plan & {
client: filesystem: "test.txt": {
// no dependencies between these two, one must be forced
read: contents: string
write: contents: actions.test.export.contents
}
actions: {
image: dagger.#Pull & {
source: "alpine:3.15.0@sha256:e7d88de73db3d3fd9b2d63aa7f447a10fd0220b7cbf39803c803f2af9ba256b3"
}
test: {
read: dagger.#Exec & {
input: image.output
args: ["echo", client.filesystem."test.txt".read.contents]
}
write: dagger.#Exec & {
input: image.output
args: ["sh", "-c",
#"""
echo -n bar > /out.txt
"""#,
]
}
export: dagger.#ReadFile & {
input: write.output
path: "out.txt"
}
// FIXME: hack until we can do outputs with `dagger do`
verify: dagger.#Exec & {
input: image.output
args: ["echo", client.filesystem."test.txt".write.contents]
}
}
}
}

View File

@@ -0,0 +1,3 @@
#!/bin/sh
env

View File

@@ -0,0 +1 @@
bar

View File

@@ -0,0 +1,44 @@
package main
import (
"dagger.io/dagger"
)
dagger.#Plan & {
client: filesystem: {
"cmd.sh": read: contents: "env"
"test.txt": read: contents: string
"secret.txt": read: contents: dagger.#Secret
}
actions: {
image: dagger.#Pull & {
source: "alpine:3.15.0@sha256:e7d88de73db3d3fd9b2d63aa7f447a10fd0220b7cbf39803c803f2af9ba256b3"
}
test: {
concrete: dagger.#Exec & {
input: image.output
args: ["sh", "-c", client.filesystem."cmd.sh".read.contents]
}
usage: {
string: dagger.#Exec & {
input: image.output
args: ["test", client.filesystem."test.txt".read.contents, "=", "foo"]
}
secret: dagger.#Exec & {
input: image.output
mounts: secret: {
dest: "/run/secrets/test"
contents: client.filesystem."secret.txt".read.contents
}
args: [
"sh", "-c",
#"""
test "$(cat /run/secrets/test)" = "bar"
ls -l /run/secrets/test | grep -- "-r--------"
"""#,
]
}
}
}
}
}

View File

@@ -0,0 +1 @@
foo

View File

@@ -0,0 +1,11 @@
package main
import (
"dagger.io/dagger"
)
dagger.#Plan & {
client: filesystem: "/foobar": read: contents: dagger.#FS
actions: test: {
}
}

View File

@@ -0,0 +1,22 @@
package main
import (
"dagger.io/dagger"
)
dagger.#Plan & {
client: filesystem: "../rootfs": read: {
contents: dagger.#FS
include: ["*.txt"]
}
actions: test: {
[string]: dagger.#ReadFile & {
input: client.filesystem."../rootfs".read.contents
}
valid: {
path: "test.txt"
contents: "local directory"
}
notIncluded: path: "test.log"
}
}

View File

@@ -0,0 +1 @@
excluded

View File

@@ -0,0 +1 @@
local directory

View File

@@ -0,0 +1,27 @@
package main
import (
"dagger.io/dagger"
)
dagger.#Plan & {
client: filesystem: rootfs: read: {
contents: dagger.#FS
exclude: ["*.log"]
}
actions: test: {
[string]: dagger.#ReadFile & {
input: client.filesystem.rootfs.read.contents
}
valid: {
path: "test.txt"
contents: "local directory"
}
conflictingValues: {
path: "test.txt"
contents: "local foobar"
}
excluded: path: "test.log"
notExists: path: "test.json"
}
}

View File

@@ -0,0 +1,29 @@
package main
import (
"dagger.io/dagger"
)
dagger.#Plan & {
client: filesystem: "/var/run/docker.soc": read: contents: dagger.#Service
actions: {
image: dagger.#Pull & {
source: "alpine:3.15.0@sha256:e7d88de73db3d3fd9b2d63aa7f447a10fd0220b7cbf39803c803f2af9ba256b3"
}
imageWithDocker: dagger.#Exec & {
input: image.output
args: ["apk", "add", "--no-cache", "docker-cli"]
}
test: dagger.#Exec & {
input: imageWithDocker.output
mounts: docker: {
dest: "/var/run/docker.sock"
contents: client.filesystem."/var/run/docker.soc".read.contents
}
args: ["docker", "info"]
}
}
}

View File

@@ -0,0 +1,29 @@
package main
import (
"dagger.io/dagger"
)
dagger.#Plan & {
client: filesystem: "/var/run/docker.sock": read: contents: dagger.#Service
actions: {
image: dagger.#Pull & {
source: "alpine:3.15.0@sha256:e7d88de73db3d3fd9b2d63aa7f447a10fd0220b7cbf39803c803f2af9ba256b3"
}
imageWithDocker: dagger.#Exec & {
input: image.output
args: ["apk", "add", "--no-cache", "docker-cli"]
}
test: dagger.#Exec & {
input: imageWithDocker.output
mounts: docker: {
dest: "/var/run/docker.sock"
contents: client.filesystem."/var/run/docker.sock".read.contents
}
args: ["docker", "info"]
}
}
}

View File

@@ -0,0 +1,29 @@
package main
import (
"dagger.io/dagger"
)
dagger.#Plan & {
client: filesystem: "//./pipe/docker_engine": read: contents: dagger.#Service
actions: {
image: dagger.#Pull & {
source: "alpine:3.15.0@sha256:e7d88de73db3d3fd9b2d63aa7f447a10fd0220b7cbf39803c803f2af9ba256b3"
}
imageWithDocker: dagger.#Exec & {
input: image.output
args: ["apk", "add", "--no-cache", "docker-cli"]
}
test: dagger.#Exec & {
input: imageWithDocker.output
mounts: docker: {
dest: "/var/run/docker.sock"
contents: client.filesystem."//./pipe/docker_engine".read.contents
}
args: ["docker", "info"]
}
}
}

View File

@@ -0,0 +1,69 @@
package main
import (
"dagger.io/dagger"
)
dagger.#Plan & {
client: filesystem: {
out_fs: write: contents: actions.test.fs.data.output
"out_files/test.txt": write: contents: actions.test.file.data.contents
"out_files/secret.txt": write: {
contents: actions.test.secret.data.output
permissions: 0o600
}
}
actions: {
image: dagger.#Pull & {
source: "alpine:3.15.0@sha256:e7d88de73db3d3fd9b2d63aa7f447a10fd0220b7cbf39803c803f2af9ba256b3"
}
test: {
fs: {
data: dagger.#WriteFile & {
input: dagger.#Scratch
path: "/test"
contents: "foobar"
}
// FIXME: hack until we can do outputs with `dagger do`
verify: dagger.#ReadFile & {
input: client.filesystem."out_fs".write.contents
path: "test"
}
}
file: {
// Only using contents for reference in client
data: dagger.#WriteFile & {
input: dagger.#Scratch
path: "/test"
contents: "foobaz"
}
// FIXME: hack until we can do outputs with `dagger do`
verify: dagger.#Exec & {
input: image.output
args: ["echo", "-c", client.filesystem."out_files/test.txt".write.contents]
}
}
secret: {
create: dagger.#WriteFile & {
input: dagger.#Scratch
path: "/test"
contents: "foo-barab-oof"
}
data: dagger.#NewSecret & {
input: create.output
path: "/test"
}
// FIXME: hack until we can do outputs with `dagger do`
verify: dagger.#Exec & {
input: image.output
mounts: secret: {
dest: "/run/secrets/test"
contents: client.filesystem."out_files/secret.txt".write.contents
}
args: ["id"]
}
}
}
}
}