WIP: engine.#Exec

Signed-off-by: Andrea Luzzardi <aluzzardi@gmail.com>
This commit is contained in:
Andrea Luzzardi
2021-12-15 21:35:05 +01:00
parent 977485aa27
commit 12be9a7dd8
15 changed files with 717 additions and 0 deletions

26
tests/tasks/exec/args.cue Normal file
View File

@@ -0,0 +1,26 @@
package main
import (
"alpha.dagger.io/europa/dagger/engine"
)
engine.#Plan & {
actions: {
image: engine.#Pull & {
source: "alpine:3.15.0@sha256:e7d88de73db3d3fd9b2d63aa7f447a10fd0220b7cbf39803c803f2af9ba256b3"
}
exec: engine.#Exec & {
input: image.output
args: ["sh", "-c", "echo -n hello world > /output.txt"]
}
verify: engine.#ReadFile & {
input: exec.output
path: "/output.txt"
} & {
// assert result
contents: "hello world"
}
}
}

View File

@@ -0,0 +1 @@
module: ""

View File

@@ -0,0 +1,3 @@
# generated by dagger
alpha.dagger.io
dagger.lock

24
tests/tasks/exec/env.cue Normal file
View File

@@ -0,0 +1,24 @@
package main
import (
"alpha.dagger.io/europa/dagger/engine"
)
engine.#Plan & {
actions: {
image: engine.#Pull & {
source: "alpine:3.15.0@sha256:e7d88de73db3d3fd9b2d63aa7f447a10fd0220b7cbf39803c803f2af9ba256b3"
}
verify: engine.#Exec & {
input: image.output
env: TEST: "hello world"
args: [
"sh", "-c",
#"""
test "$TEST" = "hello world"
"""#,
]
}
}
}

View File

@@ -0,0 +1,25 @@
package main
import (
"alpha.dagger.io/europa/dagger/engine"
)
engine.#Plan & {
actions: {
image: engine.#Pull & {
source: "alpine:3.15.0@sha256:e7d88de73db3d3fd9b2d63aa7f447a10fd0220b7cbf39803c803f2af9ba256b3"
}
verify: engine.#Exec & {
input: image.output
hosts: "unit.test": "1.2.3.4"
args: [
"sh", "-c",
#"""
grep -q "unit.test" /etc/hosts
grep -q "1.2.3.4" /etc/hosts
"""#,
]
}
}
}

View File

@@ -0,0 +1,63 @@
package main
import (
"alpha.dagger.io/europa/dagger/engine"
)
engine.#Plan & {
actions: {
image: engine.#Pull & {
source: "alpine:3.15.0@sha256:e7d88de73db3d3fd9b2d63aa7f447a10fd0220b7cbf39803c803f2af9ba256b3"
}
sharedCache: engine.#CacheDir & {
id: "mycache"
}
exec: engine.#Exec & {
input: image.output
mounts: cache: {
dest: "/cache"
contents: sharedCache
}
args: [
"sh", "-c",
#"""
echo -n hello world > /cache/output.txt
"""#,
]
}
verify: engine.#Exec & {
input: image.output
mounts: cache: {
dest: "/cache"
contents: sharedCache
}
args: [
"sh", "-c",
#"""
test -f /cache/output.txt
test "$(cat /cache/output.txt)" = "hello world"
"""#,
]
}
otherCache: engine.#CacheDir & {
id: "othercache"
}
verifyOtherCache: engine.#Exec & {
input: image.output
mounts: cache: {
dest: "/cache"
contents: otherCache
}
args: [
"sh", "-c",
#"""
test ! -f /cache/output.txt
"""#,
]
}
}
}

View File

@@ -0,0 +1,37 @@
package main
import (
"alpha.dagger.io/europa/dagger/engine"
)
engine.#Plan & {
actions: {
image: engine.#Pull & {
source: "alpine:3.15.0@sha256:e7d88de73db3d3fd9b2d63aa7f447a10fd0220b7cbf39803c803f2af9ba256b3"
}
exec: engine.#Exec & {
input: image.output
args: [
"sh", "-c",
#"""
echo -n hello world > /output.txt
"""#,
]
}
verify: engine.#Exec & {
input: image.output
mounts: fs: {
dest: "/target"
contents: exec.output
}
args: [
"sh", "-c",
#"""
test "$(cat /target/output.txt)" = "hello world"
"""#,
]
}
}
}

View File

@@ -0,0 +1,28 @@
package main
import (
"alpha.dagger.io/europa/dagger/engine"
)
engine.#Plan & {
context: secrets: testSecret: envvar: "TESTSECRET"
actions: {
image: engine.#Pull & {
source: "alpine:3.15.0@sha256:e7d88de73db3d3fd9b2d63aa7f447a10fd0220b7cbf39803c803f2af9ba256b3"
}
verify: engine.#Exec & {
input: image.output
mounts: secret: {
dest: "/run/secrets/test"
contents: context.secrets.testSecret.contents
}
args: [
"sh", "-c",
#"""
test "$(cat /run/secrets/test)" = "hello world"
"""#,
]
}
}
}

View File

@@ -0,0 +1,37 @@
package main
import (
"alpha.dagger.io/europa/dagger/engine"
)
engine.#Plan & {
actions: {
image: engine.#Pull & {
source: "alpine:3.15.0@sha256:e7d88de73db3d3fd9b2d63aa7f447a10fd0220b7cbf39803c803f2af9ba256b3"
}
exec: engine.#Exec & {
input: image.output
mounts: temp: {
dest: "/temp"
contents: engine.#TempDir
}
args: [
"sh", "-c",
#"""
echo -n hello world > /temp/output.txt
"""#,
]
}
verify: engine.#Exec & {
input: exec.output
args: [
"sh", "-c",
#"""
test ! -f /temp/output.txt
"""#,
]
}
}
}

41
tests/tasks/exec/user.cue Normal file
View File

@@ -0,0 +1,41 @@
package main
import (
"alpha.dagger.io/europa/dagger/engine"
)
engine.#Plan & {
actions: {
image: engine.#Pull & {
source: "alpine:3.15.0@sha256:e7d88de73db3d3fd9b2d63aa7f447a10fd0220b7cbf39803c803f2af9ba256b3"
}
addUser: engine.#Exec & {
input: image.output
args: ["adduser", "-D", "test"]
}
verifyUsername: engine.#Exec & {
input: addUser.output
user: "test"
args: [
"sh", "-c",
#"""
test "$(whoami)" = "test"
"""#,
]
}
verifyUserID: engine.#Exec & {
input: addUser.output
user: "1000"
args: [
"sh", "-c",
#"""
test "$(whoami)" = "test"
"""#,
]
}
}
}

View File

@@ -0,0 +1,24 @@
package main
import (
"alpha.dagger.io/europa/dagger/engine"
)
engine.#Plan & {
actions: {
image: engine.#Pull & {
source: "alpine:3.15.0@sha256:e7d88de73db3d3fd9b2d63aa7f447a10fd0220b7cbf39803c803f2af9ba256b3"
}
verify: engine.#Exec & {
input: image.output
workdir: "/tmp"
args: [
"sh", "-c",
#"""
test "$(pwd)" = "/tmp"
"""#,
]
}
}
}