Merge pull request #1569 from shykes/docker-run-tweak

Simplify docker.#Run
This commit is contained in:
Solomon Hykes
2022-02-08 09:58:22 -08:00
committed by GitHub
18 changed files with 129 additions and 81 deletions

View File

@@ -36,7 +36,7 @@ import (
}
// Command to execute
cmd?: {
command?: {
// Name of the command to execute
// Examples: "ls", "/bin/bash"
name: string
@@ -61,17 +61,6 @@ import (
], 1)
}
// Optionally pass a script to interpret
// Example: "echo hello\necho world"
script?: string
if script != _|_ {
// Default interpreter is /bin/sh -c
cmd: *{
name: "/bin/sh"
flags: "-c": script
} | {}
}
// Environment variables
// Example: {"DEBUG": "1"}
env: [string]: string
@@ -133,10 +122,10 @@ import (
"always": always
"mounts": mounts
if cmd != _|_ {
args: [cmd.name] + cmd._flatFlags + cmd.args
if command != _|_ {
args: [command.name] + command._flatFlags + command.args
}
if cmd == _|_ {
if command == _|_ {
args: list.Concat([
if _image.config.entrypoint != _|_ {
_image.config.entrypoint

View File

@@ -16,19 +16,28 @@ dagger.#Plan & {
steps: [
alpine.#Build,
docker.#Run & {
script: """
command: {
name: "sh"
flags: "-c": """
echo -n hello > /bar.txt
"""
"""
}
},
docker.#Run & {
script: """
command: {
name: "sh"
flags: "-c": """
echo -n $(cat /bar.txt) world > /foo.txt
"""
"""
}
},
docker.#Run & {
script: """
command: {
name: "sh"
flags: "-c": """
echo -n $(cat /foo.txt) >> /test.txt
"""
"""
}
},
]
}

View File

@@ -17,9 +17,10 @@ dagger.#Plan & {
steps: [
alpine.#Build,
docker.#Run & {
script: """
echo -n $TEST >> /test.txt
"""
command: {
name: "sh"
flags: "-c": "echo -n $TEST >> /test.txt"
}
env: TEST: #testValue
},
]

View File

@@ -27,7 +27,7 @@ dagger.#Plan & {
}
run: docker.#Run & {
image: myimage
cmd: name: "ls"
command: name: "ls"
export: files: {
"/dagger.txt": _ & {
contents: "not hello from dagger"
@@ -57,9 +57,12 @@ dagger.#Plan & {
verify_working_directory: docker.#Run & {
image: myimage
script: #"""
pwd > dir.txt
"""#
command: {
name: "sh"
flags: "-c": #"""
pwd > dir.txt
"""#
}
export: files: "/bin/dir.txt": _ & {
contents: "/bin\n"
}
@@ -67,9 +70,12 @@ dagger.#Plan & {
verify_working_directory_is_overridden: docker.#Run & {
image: myimage
workdir: "/"
script: #"""
pwd > dir.txt
"""#
command: {
name: "sh"
flags: "-c": #"""
pwd > dir.txt
"""#
}
export: files: "/dir.txt": _ & {
contents: "/\n"
}

View File

@@ -5,6 +5,7 @@ import (
"universe.dagger.io/docker"
)
// FIXME: this test is currently broken (see docker.bats)
dagger.#Plan & {
actions: build: docker.#Build & {
steps: [
@@ -16,17 +17,17 @@ dagger.#Plan & {
source: "alpine"
},
docker.#Run & {
cmd: name: "ls"
command: name: "ls"
},
]
},
docker.#Run & {
cmd: name: "ls"
command: name: "ls"
},
]
},
docker.#Run & {
cmd: name: "ls"
command: name: "ls"
},
]
}

View File

@@ -14,12 +14,12 @@ dagger.#Plan & {
source: "alpine"
},
docker.#Run & {
cmd: name: "ls"
command: name: "ls"
},
]
},
docker.#Run & {
cmd: name: "ls"
command: name: "ls"
},
]
}

View File

@@ -13,7 +13,7 @@ dagger.#Plan & {
run: docker.#Run & {
"image": image.output
cmd: {
command: {
name: "/bin/sh"
args: ["-c", "echo -n hello world >> /output.txt"]
}

View File

@@ -13,10 +13,13 @@ dagger.#Plan & {
run: docker.#Run & {
"image": image.output
script: #"""
mkdir -p test
echo -n hello world >> /test/output.txt
"""#
command: {
name: "sh"
flags: "-c": #"""
mkdir -p test
echo -n hello world >> /test/output.txt
"""#
}
export: {
directories: "/test": _
files: "/test/output.txt": _ & {

View File

@@ -12,9 +12,12 @@ dagger.#Plan & {
run: docker.#Run & {
"image": image.output
script: #"""
echo -n hello world >> /output.txt
"""#
command: {
name: "sh"
flags: "-c": #"""
echo -n hello world >> /output.txt
"""#
}
export: files: "/output.txt": _ & {
contents: "hello world"
}

View File

@@ -13,9 +13,12 @@ dagger.#Plan & {
run: docker.#Run & {
"image": image.output
script: #"""
echo -n $TEST_MESSAGE >> /output.txt
"""#
command: {
name: "sh"
flags: "-c": #"""
echo -n $TEST_MESSAGE >> /output.txt
"""#
}
env: TEST_MESSAGE: "hello world"
}