2022-02-09 01:20:11 +01:00
|
|
|
package docker
|
|
|
|
|
|
|
|
import (
|
|
|
|
"dagger.io/dagger"
|
2022-03-26 16:09:21 +01:00
|
|
|
"dagger.io/dagger/core"
|
2022-02-09 01:20:11 +01:00
|
|
|
"universe.dagger.io/docker"
|
|
|
|
)
|
|
|
|
|
|
|
|
dagger.#Plan & {
|
|
|
|
|
2022-03-09 19:45:46 +01:00
|
|
|
actions: test: image: {
|
2022-02-09 01:20:11 +01:00
|
|
|
|
|
|
|
// Test: change image config with docker.#Set
|
|
|
|
set: {
|
|
|
|
image: output: docker.#Image & {
|
2022-02-16 19:37:16 +01:00
|
|
|
rootfs: dagger.#Scratch
|
2022-02-09 01:20:11 +01:00
|
|
|
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: {
|
2022-03-26 16:09:21 +01:00
|
|
|
build: core.#Dockerfile & {
|
2022-02-16 19:37:16 +01:00
|
|
|
source: dagger.#Scratch
|
2022-02-09 01:20:11 +01:00
|
|
|
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 & {
|
2022-02-09 07:16:13 +01:00
|
|
|
input: myimage
|
2022-02-09 01:20:11 +01:00
|
|
|
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
|
2022-03-26 16:09:21 +01:00
|
|
|
|
2022-02-09 01:20:11 +01:00
|
|
|
"""
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
verify_cmd_is_run: docker.#Run & {
|
2022-02-09 07:16:13 +01:00
|
|
|
input: myimage
|
2022-02-09 01:20:11 +01:00
|
|
|
export: files: "/dagger.txt": _ & {
|
|
|
|
contents: "hello from dagger"
|
|
|
|
}
|
|
|
|
}
|
|
|
|
verify_env_is_overridden: docker.#Run & {
|
2022-02-09 07:16:13 +01:00
|
|
|
input: myimage
|
2022-02-09 01:20:11 +01:00
|
|
|
export: files: "/dagger.txt": _ & {
|
|
|
|
contents: "hello from europa"
|
|
|
|
}
|
|
|
|
env: HELLO_FROM: "europa"
|
|
|
|
}
|
|
|
|
|
|
|
|
verify_working_directory: docker.#Run & {
|
2022-02-09 07:16:13 +01:00
|
|
|
input: myimage
|
2022-02-09 01:20:11 +01:00
|
|
|
command: {
|
|
|
|
name: "sh"
|
|
|
|
flags: "-c": #"""
|
|
|
|
pwd > dir.txt
|
|
|
|
"""#
|
|
|
|
}
|
|
|
|
export: files: "/bin/dir.txt": _ & {
|
|
|
|
contents: "/bin\n"
|
|
|
|
}
|
|
|
|
}
|
|
|
|
verify_working_directory_is_overridden: docker.#Run & {
|
2022-02-09 07:16:13 +01:00
|
|
|
input: myimage
|
2022-02-09 01:20:11 +01:00
|
|
|
workdir: "/"
|
|
|
|
command: {
|
|
|
|
name: "sh"
|
|
|
|
flags: "-c": #"""
|
|
|
|
pwd > dir.txt
|
|
|
|
"""#
|
|
|
|
}
|
|
|
|
export: files: "/dir.txt": _ & {
|
|
|
|
contents: "/\n"
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|