Merge pull request #1517 from jlongtine/docker-run-image-config
Use image.config in `docker.#Run`
This commit is contained in:
commit
afb64e926f
@ -44,9 +44,12 @@ package engine
|
||||
volume?: [string]: {}
|
||||
workdir?: string
|
||||
label?: [string]: string
|
||||
stopsignal?: string
|
||||
healthcheck?: #HealthCheck
|
||||
argsescaped?: bool
|
||||
onbuild?: [...string]
|
||||
stoptimeout?: int
|
||||
shell?: [...string]
|
||||
...
|
||||
}
|
||||
|
||||
#HealthCheck: {
|
||||
|
@ -36,7 +36,7 @@ import (
|
||||
}
|
||||
|
||||
// Command to execute
|
||||
cmd: {
|
||||
cmd?: {
|
||||
// Name of the command to execute
|
||||
// Examples: "ls", "/bin/bash"
|
||||
name: string
|
||||
@ -78,12 +78,12 @@ import (
|
||||
|
||||
// Working directory for the command
|
||||
// Example: "/src"
|
||||
workdir: string | *"/"
|
||||
workdir: string
|
||||
|
||||
// Username or UID to ad
|
||||
// User identity for this command
|
||||
// Examples: "root", "0", "1002"
|
||||
user: string | *"root"
|
||||
user: string
|
||||
|
||||
// Output fields
|
||||
{
|
||||
@ -129,12 +129,38 @@ import (
|
||||
|
||||
// Actually execute the command
|
||||
_exec: engine.#Exec & {
|
||||
args: [cmd.name] + cmd._flatFlags + cmd.args
|
||||
input: _image.rootfs
|
||||
"always": always
|
||||
"mounts": mounts
|
||||
"env": env
|
||||
input: _image.rootfs
|
||||
"always": always
|
||||
"mounts": mounts
|
||||
|
||||
if cmd != _|_ {
|
||||
args: [cmd.name] + cmd._flatFlags + cmd.args
|
||||
}
|
||||
if cmd == _|_ {
|
||||
args: list.Concat([
|
||||
if _image.config.entrypoint != _|_ {
|
||||
_image.config.entrypoint
|
||||
},
|
||||
if _image.config.cmd != _|_ {
|
||||
_image.config.cmd
|
||||
},
|
||||
])
|
||||
}
|
||||
"env": env
|
||||
if _image.config.env != _|_ {
|
||||
for key, val in _image.config.env {
|
||||
if env[key] == _|_ {
|
||||
env: "\(key)": val
|
||||
}
|
||||
}
|
||||
}
|
||||
"workdir": workdir
|
||||
"user": user
|
||||
if workdir == _|_ && _image.config.workdir != _|_ {
|
||||
workdir: _image.config.workdir
|
||||
}
|
||||
"user": user
|
||||
if user == _|_ && _image.config.user != _|_ {
|
||||
user: _image.config.user
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -17,4 +17,5 @@ setup() {
|
||||
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
|
||||
}
|
||||
|
78
pkg/universe.dagger.io/docker/test/image-config-test.cue
Normal file
78
pkg/universe.dagger.io/docker/test/image-config-test.cue
Normal file
@ -0,0 +1,78 @@
|
||||
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
|
||||
cmd: 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
|
||||
script: #"""
|
||||
pwd > dir.txt
|
||||
"""#
|
||||
export: files: "/bin/dir.txt": _ & {
|
||||
contents: "/bin\n"
|
||||
}
|
||||
}
|
||||
verify_working_directory_is_overridden: docker.#Run & {
|
||||
image: myimage
|
||||
workdir: "/"
|
||||
script: #"""
|
||||
pwd > dir.txt
|
||||
"""#
|
||||
export: files: "/dir.txt": _ & {
|
||||
contents: "/\n"
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user