mirror of
https://github.com/morten-olsen/morten-olsen.github.io.git
synced 2026-02-08 01:46:28 +01:00
update
This commit is contained in:
120
cue.mod/pkg/universe.dagger.io/docker/test/build.cue
generated
Executable file
120
cue.mod/pkg/universe.dagger.io/docker/test/build.cue
generated
Executable file
@@ -0,0 +1,120 @@
|
||||
package docker
|
||||
|
||||
import (
|
||||
"dagger.io/dagger"
|
||||
"dagger.io/dagger/core"
|
||||
|
||||
"universe.dagger.io/alpine"
|
||||
"universe.dagger.io/docker"
|
||||
)
|
||||
|
||||
dagger.#Plan & {
|
||||
actions: test: build: {
|
||||
// Test: simple docker.#Build
|
||||
simple: {
|
||||
#testValue: "hello world"
|
||||
|
||||
image: docker.#Build & {
|
||||
steps: [
|
||||
alpine.#Build,
|
||||
docker.#Run & {
|
||||
command: {
|
||||
name: "sh"
|
||||
flags: "-c": "echo -n $TEST >> /test.txt"
|
||||
}
|
||||
env: TEST: #testValue
|
||||
},
|
||||
]
|
||||
}
|
||||
|
||||
verify: core.#ReadFile & {
|
||||
input: image.output.rootfs
|
||||
path: "/test.txt"
|
||||
}
|
||||
verify: contents: #testValue
|
||||
}
|
||||
|
||||
// Test: docker.#Build with multiple steps
|
||||
multiSteps: {
|
||||
image: docker.#Build & {
|
||||
steps: [
|
||||
alpine.#Build,
|
||||
docker.#Run & {
|
||||
command: {
|
||||
name: "sh"
|
||||
flags: "-c": "echo -n hello > /bar.txt"
|
||||
}
|
||||
},
|
||||
docker.#Run & {
|
||||
command: {
|
||||
name: "sh"
|
||||
flags: "-c": "echo -n $(cat /bar.txt) world > /foo.txt"
|
||||
}
|
||||
},
|
||||
docker.#Run & {
|
||||
command: {
|
||||
name: "sh"
|
||||
flags: "-c": "echo -n $(cat /foo.txt) >> /test.txt"
|
||||
}
|
||||
},
|
||||
]
|
||||
}
|
||||
|
||||
verify: core.#ReadFile & {
|
||||
input: image.output.rootfs
|
||||
path: "/test.txt"
|
||||
}
|
||||
verify: contents: "hello world"
|
||||
}
|
||||
|
||||
// Test: simple nesting of docker.#Build
|
||||
nested: {
|
||||
build: docker.#Build & {
|
||||
steps: [
|
||||
docker.#Build & {
|
||||
steps: [
|
||||
docker.#Pull & {
|
||||
source: "alpine"
|
||||
},
|
||||
docker.#Run & {
|
||||
command: name: "ls"
|
||||
},
|
||||
]
|
||||
},
|
||||
docker.#Run & {
|
||||
command: name: "ls"
|
||||
},
|
||||
]
|
||||
}
|
||||
}
|
||||
|
||||
// Test: nested docker.#Build with 3+ levels of depth
|
||||
// FIXME: this test currently fails.
|
||||
nestedDeep: {
|
||||
// build: docker.#Build & {
|
||||
// steps: [
|
||||
// docker.#Build & {
|
||||
// steps: [
|
||||
// docker.#Build & {
|
||||
// steps: [
|
||||
// docker.#Pull & {
|
||||
// source: "alpine"
|
||||
// },
|
||||
// docker.#Run & {
|
||||
// command: name: "ls"
|
||||
// },
|
||||
// ]
|
||||
// },
|
||||
// docker.#Run & {
|
||||
// command: name: "ls"
|
||||
// },
|
||||
// ]
|
||||
// },
|
||||
// docker.#Run & {
|
||||
// command: name: "ls"
|
||||
// },
|
||||
// ]
|
||||
// }
|
||||
}
|
||||
}
|
||||
}
|
||||
70
cue.mod/pkg/universe.dagger.io/docker/test/dockerfile.cue
generated
Executable file
70
cue.mod/pkg/universe.dagger.io/docker/test/dockerfile.cue
generated
Executable file
@@ -0,0 +1,70 @@
|
||||
package docker
|
||||
|
||||
import (
|
||||
"dagger.io/dagger"
|
||||
"dagger.io/dagger/core"
|
||||
"universe.dagger.io/docker"
|
||||
)
|
||||
|
||||
dagger.#Plan & {
|
||||
client: filesystem: "./testdata": read: contents: dagger.#FS
|
||||
|
||||
actions: test: dockerfile: {
|
||||
simple: {
|
||||
build: docker.#Build & {
|
||||
steps: [
|
||||
docker.#Dockerfile & {
|
||||
source: dagger.#Scratch
|
||||
dockerfile: contents: """
|
||||
FROM alpine:3.15
|
||||
|
||||
RUN echo -n hello world >> /test.txt
|
||||
"""
|
||||
},
|
||||
docker.#Run & {
|
||||
command: {
|
||||
name: "/bin/sh"
|
||||
args: ["-c", """
|
||||
# Verify that docker.#Dockerfile correctly connect output
|
||||
# into other steps
|
||||
grep -q "hello world" /test.txt
|
||||
"""]
|
||||
}
|
||||
},
|
||||
]
|
||||
}
|
||||
|
||||
verify: core.#ReadFile & {
|
||||
input: build.output.rootfs
|
||||
path: "/test.txt"
|
||||
} & {
|
||||
contents: "hello world"
|
||||
}
|
||||
}
|
||||
|
||||
withInput: {
|
||||
build: docker.#Build & {
|
||||
steps: [
|
||||
docker.#Dockerfile & {
|
||||
source: client.filesystem."./testdata".read.contents
|
||||
},
|
||||
docker.#Run & {
|
||||
command: {
|
||||
name: "/bin/sh"
|
||||
args: ["-c", """
|
||||
hello >> /test.txt
|
||||
"""]
|
||||
}
|
||||
},
|
||||
]
|
||||
}
|
||||
|
||||
verify: core.#ReadFile & {
|
||||
input: build.output.rootfs
|
||||
path: "/test.txt"
|
||||
} & {
|
||||
contents: "hello world"
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
121
cue.mod/pkg/universe.dagger.io/docker/test/image.cue
generated
Executable file
121
cue.mod/pkg/universe.dagger.io/docker/test/image.cue
generated
Executable file
@@ -0,0 +1,121 @@
|
||||
package docker
|
||||
|
||||
import (
|
||||
"dagger.io/dagger"
|
||||
"dagger.io/dagger/core"
|
||||
"universe.dagger.io/docker"
|
||||
)
|
||||
|
||||
dagger.#Plan & {
|
||||
|
||||
actions: test: image: {
|
||||
|
||||
// Test: change image config with docker.#Set
|
||||
set: {
|
||||
image: output: docker.#Image & {
|
||||
rootfs: dagger.#Scratch
|
||||
config: {
|
||||
cmd: ["/bin/sh"]
|
||||
env: PATH: "/sbin:/bin"
|
||||
onbuild: ["COPY . /app"]
|
||||
}
|
||||
}
|
||||
set: docker.#Set & {
|
||||
input: image.output
|
||||
config: {
|
||||
env: FOO: "bar"
|
||||
workdir: "/root"
|
||||
onbuild: ["RUN /app/build.sh"]
|
||||
}
|
||||
}
|
||||
verify: set.output.config & {
|
||||
env: {
|
||||
PATH: "/sbin:/bin"
|
||||
FOO: "bar"
|
||||
}
|
||||
cmd: ["/bin/sh"]
|
||||
workdir: "/root"
|
||||
onbuild: [
|
||||
"COPY . /app",
|
||||
"RUN /app/build.sh",
|
||||
]
|
||||
}
|
||||
}
|
||||
|
||||
// Test: image config behavior is correct
|
||||
config: {
|
||||
build: core.#Dockerfile & {
|
||||
source: dagger.#Scratch
|
||||
dockerfile: contents: """
|
||||
FROM alpine:3.15.0
|
||||
RUN echo -n 'not hello from dagger' > /dagger.txt
|
||||
RUN echo '#!/bin/sh' > /bin/dagger
|
||||
ENV HELLO_FROM=dagger
|
||||
RUN echo 'echo -n "hello from $HELLO_FROM" > /dagger.txt' >> /bin/dagger
|
||||
RUN chmod +x /bin/dagger
|
||||
WORKDIR /bin
|
||||
CMD /bin/dagger
|
||||
"""
|
||||
}
|
||||
myimage: docker.#Image & {
|
||||
rootfs: build.output
|
||||
config: build.config
|
||||
}
|
||||
run: docker.#Run & {
|
||||
input: myimage
|
||||
command: name: "ls"
|
||||
export: files: {
|
||||
"/dagger.txt": _ & {
|
||||
contents: "not hello from dagger"
|
||||
}
|
||||
"/bin/dagger": _ & {
|
||||
contents: """
|
||||
#!/bin/sh
|
||||
echo -n "hello from $HELLO_FROM" > /dagger.txt
|
||||
|
||||
"""
|
||||
}
|
||||
}
|
||||
}
|
||||
verify_cmd_is_run: docker.#Run & {
|
||||
input: myimage
|
||||
export: files: "/dagger.txt": _ & {
|
||||
contents: "hello from dagger"
|
||||
}
|
||||
}
|
||||
verify_env_is_overridden: docker.#Run & {
|
||||
input: myimage
|
||||
export: files: "/dagger.txt": _ & {
|
||||
contents: "hello from europa"
|
||||
}
|
||||
env: HELLO_FROM: "europa"
|
||||
}
|
||||
|
||||
verify_working_directory: docker.#Run & {
|
||||
input: myimage
|
||||
command: {
|
||||
name: "sh"
|
||||
flags: "-c": #"""
|
||||
pwd > dir.txt
|
||||
"""#
|
||||
}
|
||||
export: files: "/bin/dir.txt": _ & {
|
||||
contents: "/bin\n"
|
||||
}
|
||||
}
|
||||
verify_working_directory_is_overridden: docker.#Run & {
|
||||
input: myimage
|
||||
workdir: "/"
|
||||
command: {
|
||||
name: "sh"
|
||||
flags: "-c": #"""
|
||||
pwd > dir.txt
|
||||
"""#
|
||||
}
|
||||
export: files: "/dir.txt": _ & {
|
||||
contents: "/\n"
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
108
cue.mod/pkg/universe.dagger.io/docker/test/run.cue
generated
Executable file
108
cue.mod/pkg/universe.dagger.io/docker/test/run.cue
generated
Executable file
@@ -0,0 +1,108 @@
|
||||
package docker
|
||||
|
||||
import (
|
||||
"dagger.io/dagger"
|
||||
"dagger.io/dagger/core"
|
||||
|
||||
"universe.dagger.io/docker"
|
||||
"universe.dagger.io/alpine"
|
||||
)
|
||||
|
||||
dagger.#Plan & {
|
||||
actions: test: run: {
|
||||
_build: alpine.#Build & {
|
||||
packages: bash: _
|
||||
}
|
||||
_image: _build.output
|
||||
|
||||
// Test: run a simple shell command
|
||||
simpleShell: {
|
||||
run: docker.#Run & {
|
||||
input: _image
|
||||
command: {
|
||||
name: "/bin/sh"
|
||||
args: ["-c", "echo -n hello world >> /output.txt"]
|
||||
}
|
||||
}
|
||||
|
||||
verify: core.#ReadFile & {
|
||||
input: run.output.rootfs
|
||||
path: "/output.txt"
|
||||
}
|
||||
verify: contents: "hello world"
|
||||
}
|
||||
|
||||
// Test: export a file
|
||||
exportFile: {
|
||||
run: docker.#Run & {
|
||||
input: _image
|
||||
command: {
|
||||
name: "sh"
|
||||
flags: "-c": #"""
|
||||
echo -n hello world >> /output.txt
|
||||
"""#
|
||||
}
|
||||
export: files: "/output.txt": string & "hello world"
|
||||
}
|
||||
}
|
||||
|
||||
// Test: export a directory
|
||||
exportDirectory: {
|
||||
run: docker.#Run & {
|
||||
input: _image
|
||||
command: {
|
||||
name: "sh"
|
||||
flags: "-c": #"""
|
||||
mkdir -p /test
|
||||
echo -n hello world >> /test/output.txt
|
||||
"""#
|
||||
}
|
||||
export: directories: "/test": _
|
||||
}
|
||||
|
||||
verify: core.#ReadFile & {
|
||||
input: run.export.directories."/test"
|
||||
path: "/output.txt"
|
||||
}
|
||||
verify: contents: "hello world"
|
||||
}
|
||||
|
||||
// Test: configs overriding image defaults
|
||||
configs: {
|
||||
_base: docker.#Set & {
|
||||
input: _image
|
||||
config: {
|
||||
user: "nobody"
|
||||
workdir: "/sbin"
|
||||
entrypoint: ["sh"]
|
||||
cmd: ["-c", "echo -n $0 $PWD $(whoami) > /tmp/output.txt"]
|
||||
}
|
||||
}
|
||||
|
||||
// check defaults not overriden by image config
|
||||
runDefaults: docker.#Run & {
|
||||
input: _image
|
||||
command: {
|
||||
name: "sh"
|
||||
flags: "-c": "echo -n $PWD $(whoami) > /output.txt"
|
||||
}
|
||||
export: files: "/output.txt": "/ root"
|
||||
}
|
||||
|
||||
// check image defaults
|
||||
imageDefaults: docker.#Run & {
|
||||
input: _base.output
|
||||
export: files: "/tmp/output.txt": "sh /sbin nobody"
|
||||
}
|
||||
|
||||
// check overrides by user
|
||||
overrides: docker.#Run & {
|
||||
input: _base.output
|
||||
entrypoint: ["bash"]
|
||||
workdir: "/root"
|
||||
user: "root"
|
||||
export: files: "/tmp/output.txt": "bash /root root"
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
12
cue.mod/pkg/universe.dagger.io/docker/test/test.bats
generated
Executable file
12
cue.mod/pkg/universe.dagger.io/docker/test/test.bats
generated
Executable file
@@ -0,0 +1,12 @@
|
||||
setup() {
|
||||
load '../../bats_helpers'
|
||||
|
||||
common_setup
|
||||
}
|
||||
|
||||
@test "docker" {
|
||||
dagger "do" -p ./build.cue test
|
||||
dagger "do" -p ./dockerfile.cue test
|
||||
dagger "do" -p ./run.cue test
|
||||
dagger "do" -p ./image.cue test
|
||||
}
|
||||
Reference in New Issue
Block a user