diff --git a/pkg/universe.dagger.io/docker/test/build-multi-steps.cue b/pkg/universe.dagger.io/docker/test/build-multi-steps.cue deleted file mode 100644 index f4fc6ce1..00000000 --- a/pkg/universe.dagger.io/docker/test/build-multi-steps.cue +++ /dev/null @@ -1,52 +0,0 @@ -package test - -import ( - "dagger.io/dagger" - "dagger.io/dagger/engine" - "universe.dagger.io/docker" - "universe.dagger.io/alpine" -) - -// This test verify that we can correctly build an image -// using docker.#Build with multiple steps executed during -// the building process -dagger.#Plan & { - actions: { - 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: engine.#ReadFile & { - input: image.output.rootfs - path: "/test.txt" - } & { - contents: "hello world" - } - } -} diff --git a/pkg/universe.dagger.io/docker/test/build-simple.cue b/pkg/universe.dagger.io/docker/test/build-simple.cue deleted file mode 100644 index 35290671..00000000 --- a/pkg/universe.dagger.io/docker/test/build-simple.cue +++ /dev/null @@ -1,36 +0,0 @@ -package test - -import ( - "dagger.io/dagger" - "dagger.io/dagger/engine" - "universe.dagger.io/docker" - "universe.dagger.io/alpine" -) - -// This test verify that we can correctly build a simplistic image -// using docker.#Build -dagger.#Plan & { - #testValue: "hello world" - - actions: { - image: docker.#Build & { - steps: [ - alpine.#Build, - docker.#Run & { - command: { - name: "sh" - flags: "-c": "echo -n $TEST >> /test.txt" - } - env: TEST: #testValue - }, - ] - } - - verify: engine.#ReadFile & { - input: image.output.rootfs - path: "/test.txt" - } & { - contents: #testValue - } - } -} diff --git a/pkg/universe.dagger.io/docker/test/build.cue b/pkg/universe.dagger.io/docker/test/build.cue new file mode 100644 index 00000000..061c605c --- /dev/null +++ b/pkg/universe.dagger.io/docker/test/build.cue @@ -0,0 +1,120 @@ +package docker + +import ( + "dagger.io/dagger" + "dagger.io/dagger/engine" + + "universe.dagger.io/alpine" + "universe.dagger.io/docker" +) + +dagger.#Plan & { + actions: tests: 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: engine.#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: engine.#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" + // }, + // ] + // } + } + } +} diff --git a/pkg/universe.dagger.io/docker/test/docker.bats b/pkg/universe.dagger.io/docker/test/docker.bats deleted file mode 100644 index 8198c44d..00000000 --- a/pkg/universe.dagger.io/docker/test/docker.bats +++ /dev/null @@ -1,28 +0,0 @@ -setup() { - load '../../bats_helpers' - - common_setup -} - -@test "docker.#Build" { - dagger up ./build-simple.cue - dagger up ./build-multi-steps.cue - - dagger up ./nested-build-test.cue - - # FIXME: this is currently broken - run dagger up ./multi-nested-build-test.cue - assert_failure -} - -@test "docker.#Run" { - dagger up ./run-command-test.cue - dagger up ./run-script-test.cue - dagger up ./run-export-file-test.cue - dagger up ./run-export-directory-test.cue - dagger up ./image-config-test.cue -} - -@test "docker.#Set" { - dagger up ./set.cue -} diff --git a/pkg/universe.dagger.io/docker/test/image-config-test.cue b/pkg/universe.dagger.io/docker/test/image-config-test.cue deleted file mode 100644 index f1d5d2e1..00000000 --- a/pkg/universe.dagger.io/docker/test/image-config-test.cue +++ /dev/null @@ -1,84 +0,0 @@ -package docker - -import ( - "dagger.io/dagger" - "dagger.io/dagger/engine" - "universe.dagger.io/docker" -) - -dagger.#Plan & { - actions: { - build: engine.#Dockerfile & { - source: engine.#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 & { - image: 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 & { - image: myimage - export: files: "/dagger.txt": _ & { - contents: "hello from dagger" - } - } - verify_env_is_overridden: docker.#Run & { - image: myimage - export: files: "/dagger.txt": _ & { - contents: "hello from europa" - } - env: HELLO_FROM: "europa" - } - - verify_working_directory: docker.#Run & { - image: myimage - command: { - name: "sh" - flags: "-c": #""" - pwd > dir.txt - """# - } - export: files: "/bin/dir.txt": _ & { - contents: "/bin\n" - } - } - verify_working_directory_is_overridden: docker.#Run & { - image: myimage - workdir: "/" - command: { - name: "sh" - flags: "-c": #""" - pwd > dir.txt - """# - } - export: files: "/dir.txt": _ & { - contents: "/\n" - } - } - } -} diff --git a/pkg/universe.dagger.io/docker/test/image.cue b/pkg/universe.dagger.io/docker/test/image.cue new file mode 100644 index 00000000..98ba4576 --- /dev/null +++ b/pkg/universe.dagger.io/docker/test/image.cue @@ -0,0 +1,121 @@ +package docker + +import ( + "dagger.io/dagger" + "dagger.io/dagger/engine" + "universe.dagger.io/docker" +) + +dagger.#Plan & { + + actions: tests: image: { + + // Test: change image config with docker.#Set + set: { + image: output: docker.#Image & { + rootfs: engine.#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: engine.#Dockerfile & { + source: engine.#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 & { + image: 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 & { + image: myimage + export: files: "/dagger.txt": _ & { + contents: "hello from dagger" + } + } + verify_env_is_overridden: docker.#Run & { + image: myimage + export: files: "/dagger.txt": _ & { + contents: "hello from europa" + } + env: HELLO_FROM: "europa" + } + + verify_working_directory: docker.#Run & { + image: myimage + command: { + name: "sh" + flags: "-c": #""" + pwd > dir.txt + """# + } + export: files: "/bin/dir.txt": _ & { + contents: "/bin\n" + } + } + verify_working_directory_is_overridden: docker.#Run & { + image: myimage + workdir: "/" + command: { + name: "sh" + flags: "-c": #""" + pwd > dir.txt + """# + } + export: files: "/dir.txt": _ & { + contents: "/\n" + } + } + } + } +} diff --git a/pkg/universe.dagger.io/docker/test/multi-nested-build-test.cue b/pkg/universe.dagger.io/docker/test/multi-nested-build-test.cue deleted file mode 100644 index 40c95e2e..00000000 --- a/pkg/universe.dagger.io/docker/test/multi-nested-build-test.cue +++ /dev/null @@ -1,34 +0,0 @@ -package docker - -import ( - "dagger.io/dagger" - "universe.dagger.io/docker" -) - -// FIXME: this test is currently broken (see docker.bats) -dagger.#Plan & { - actions: 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" - }, - ] - } -} diff --git a/pkg/universe.dagger.io/docker/test/nested-build-test.cue b/pkg/universe.dagger.io/docker/test/nested-build-test.cue deleted file mode 100644 index e1adb995..00000000 --- a/pkg/universe.dagger.io/docker/test/nested-build-test.cue +++ /dev/null @@ -1,26 +0,0 @@ -package docker - -import ( - "dagger.io/dagger" - "universe.dagger.io/docker" -) - -dagger.#Plan & { - actions: build: docker.#Build & { - steps: [ - docker.#Build & { - steps: [ - docker.#Pull & { - source: "alpine" - }, - docker.#Run & { - command: name: "ls" - }, - ] - }, - docker.#Run & { - command: name: "ls" - }, - ] - } -} diff --git a/pkg/universe.dagger.io/docker/test/run-command-test.cue b/pkg/universe.dagger.io/docker/test/run-command-test.cue deleted file mode 100644 index b7e03070..00000000 --- a/pkg/universe.dagger.io/docker/test/run-command-test.cue +++ /dev/null @@ -1,29 +0,0 @@ -package test - -import ( - "dagger.io/dagger" - "dagger.io/dagger/engine" - "universe.dagger.io/docker" - "universe.dagger.io/alpine" -) - -dagger.#Plan & { - actions: { - image: alpine.#Build - - run: docker.#Run & { - "image": image.output - command: { - name: "/bin/sh" - args: ["-c", "echo -n hello world >> /output.txt"] - } - } - - verify: engine.#ReadFile & { - input: run.output.rootfs - path: "/output.txt" - } & { - contents: "hello world" - } - } -} diff --git a/pkg/universe.dagger.io/docker/test/run-export-directory-test.cue b/pkg/universe.dagger.io/docker/test/run-export-directory-test.cue deleted file mode 100644 index e167169a..00000000 --- a/pkg/universe.dagger.io/docker/test/run-export-directory-test.cue +++ /dev/null @@ -1,41 +0,0 @@ -package test - -import ( - "dagger.io/dagger" - "dagger.io/dagger/engine" - "universe.dagger.io/docker" - "universe.dagger.io/alpine" -) - -dagger.#Plan & { - actions: { - image: alpine.#Build - - run: docker.#Run & { - "image": image.output - command: { - name: "sh" - flags: "-c": #""" - mkdir -p test - echo -n hello world >> /test/output.txt - """# - } - export: { - directories: "/test": _ - files: "/test/output.txt": _ & { - contents: "hello world" - } - } - } & { - completed: true - success: true - } - - verify: engine.#ReadFile & { - input: run.export.directories."/test".contents - path: "/output.txt" - } & { - contents: run.export.files."/test/output.txt".contents - } - } -} diff --git a/pkg/universe.dagger.io/docker/test/run-export-file-test.cue b/pkg/universe.dagger.io/docker/test/run-export-file-test.cue deleted file mode 100644 index 664a5b59..00000000 --- a/pkg/universe.dagger.io/docker/test/run-export-file-test.cue +++ /dev/null @@ -1,26 +0,0 @@ -package test - -import ( - "dagger.io/dagger" - "universe.dagger.io/docker" - "universe.dagger.io/alpine" -) - -dagger.#Plan & { - actions: { - image: alpine.#Build - - run: docker.#Run & { - "image": image.output - command: { - name: "sh" - flags: "-c": #""" - echo -n hello world >> /output.txt - """# - } - export: files: "/output.txt": _ & { - contents: "hello world" - } - } - } -} diff --git a/pkg/universe.dagger.io/docker/test/run-script-test.cue b/pkg/universe.dagger.io/docker/test/run-script-test.cue deleted file mode 100644 index 08832b3e..00000000 --- a/pkg/universe.dagger.io/docker/test/run-script-test.cue +++ /dev/null @@ -1,32 +0,0 @@ -package test - -import ( - "dagger.io/dagger" - "dagger.io/dagger/engine" - "universe.dagger.io/docker" - "universe.dagger.io/alpine" -) - -dagger.#Plan & { - actions: { - image: alpine.#Build - - run: docker.#Run & { - "image": image.output - command: { - name: "sh" - flags: "-c": #""" - echo -n $TEST_MESSAGE >> /output.txt - """# - } - env: TEST_MESSAGE: "hello world" - } - - verify: engine.#ReadFile & { - input: run.output.rootfs - path: "/output.txt" - } & { - contents: "hello world" - } - } -} diff --git a/pkg/universe.dagger.io/docker/test/run.cue b/pkg/universe.dagger.io/docker/test/run.cue new file mode 100644 index 00000000..d0ce07af --- /dev/null +++ b/pkg/universe.dagger.io/docker/test/run.cue @@ -0,0 +1,71 @@ +package docker + +import ( + "dagger.io/dagger" + "dagger.io/dagger/engine" + + "universe.dagger.io/docker" + "universe.dagger.io/alpine" +) + +dagger.#Plan & { + actions: tests: run: { + _build: alpine.#Build + _image: _build.output + + // Test: run a simple shell command + simpleShell: { + image: alpine.#Build + + run: docker.#Run & { + image: _image + command: { + name: "/bin/sh" + args: ["-c", "echo -n hello world >> /output.txt"] + } + } + + verify: engine.#ReadFile & { + input: run.output.rootfs + path: "/output.txt" + } + verify: contents: "hello world" + } + + // Test: export a file + exportFile: { + image: _image + command: { + name: "sh" + flags: "-c": #""" + echo -n hello world >> /output.txt + """# + } + export: files: "/output.txt": _ & { + // Assert content + contents: "hello world" + } + } + + // Test: export a directory + exportDirectory: { + run: docker.#Run & { + image: _image + command: { + name: "sh" + flags: "-c": #""" + mkdir -p /test + echo -n hello world >> /test/output.txt + """# + } + export: directories: "/test": _ + } + + verify: engine.#ReadFile & { + input: run.export.directories."/test".contents + path: "/output.txt" + } + verify: contents: "hello world" + } + } +} diff --git a/pkg/universe.dagger.io/docker/test/set.cue b/pkg/universe.dagger.io/docker/test/set.cue deleted file mode 100644 index b19ff93d..00000000 --- a/pkg/universe.dagger.io/docker/test/set.cue +++ /dev/null @@ -1,40 +0,0 @@ -package docker - -import ( - "dagger.io/dagger" - "dagger.io/dagger/engine" - "universe.dagger.io/docker" -) - -dagger.#Plan & { - actions: { - image: output: docker.#Image & { - rootfs: engine.#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", - ] - } - } -} diff --git a/pkg/universe.dagger.io/docker/test/test.bats b/pkg/universe.dagger.io/docker/test/test.bats new file mode 100644 index 00000000..f8fbedda --- /dev/null +++ b/pkg/universe.dagger.io/docker/test/test.bats @@ -0,0 +1,9 @@ +setup() { + load '../../bats_helpers' + + common_setup +} + +@test "docker" { + dagger up +}