Merge pull request #1569 from shykes/docker-run-tweak
Simplify docker.#Run
This commit is contained in:
commit
298a119b09
@ -27,7 +27,7 @@ import (
|
|||||||
},
|
},
|
||||||
for pkgName, pkg in packages {
|
for pkgName, pkg in packages {
|
||||||
docker.#Run & {
|
docker.#Run & {
|
||||||
cmd: {
|
command: {
|
||||||
name: "apk"
|
name: "apk"
|
||||||
args: ["add", "\(pkgName)\(pkg.version)"]
|
args: ["add", "\(pkgName)\(pkg.version)"]
|
||||||
flags: {
|
flags: {
|
||||||
|
@ -17,10 +17,13 @@ dagger.#Plan & {
|
|||||||
|
|
||||||
check: docker.#Run & {
|
check: docker.#Run & {
|
||||||
image: build.output
|
image: build.output
|
||||||
script: """
|
command: {
|
||||||
|
name: "sh"
|
||||||
|
flags: "-c": """
|
||||||
jq --version > /jq-version.txt
|
jq --version > /jq-version.txt
|
||||||
curl --version > /curl-version.txt
|
curl --version > /curl-version.txt
|
||||||
"""
|
"""
|
||||||
|
}
|
||||||
|
|
||||||
export: files: {
|
export: files: {
|
||||||
"/jq-version.txt": contents: =~"^jq"
|
"/jq-version.txt": contents: =~"^jq"
|
||||||
|
@ -6,9 +6,13 @@ import (
|
|||||||
)
|
)
|
||||||
|
|
||||||
// Run a bash command or script in a container
|
// Run a bash command or script in a container
|
||||||
#Run: docker.#Run & {
|
#Run: {
|
||||||
|
// Contents of the bash script
|
||||||
script: string
|
script: string
|
||||||
cmd: {
|
|
||||||
|
// FIXME: don't pass the script as argument: write to filesystme instead
|
||||||
|
docker.#Run & {
|
||||||
|
command: {
|
||||||
name: "bash"
|
name: "bash"
|
||||||
flags: {
|
flags: {
|
||||||
"-c": script
|
"-c": script
|
||||||
@ -19,3 +23,4 @@ import (
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
@ -36,7 +36,7 @@ import (
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Command to execute
|
// Command to execute
|
||||||
cmd?: {
|
command?: {
|
||||||
// Name of the command to execute
|
// Name of the command to execute
|
||||||
// Examples: "ls", "/bin/bash"
|
// Examples: "ls", "/bin/bash"
|
||||||
name: string
|
name: string
|
||||||
@ -61,17 +61,6 @@ import (
|
|||||||
], 1)
|
], 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
|
// Environment variables
|
||||||
// Example: {"DEBUG": "1"}
|
// Example: {"DEBUG": "1"}
|
||||||
env: [string]: string
|
env: [string]: string
|
||||||
@ -133,10 +122,10 @@ import (
|
|||||||
"always": always
|
"always": always
|
||||||
"mounts": mounts
|
"mounts": mounts
|
||||||
|
|
||||||
if cmd != _|_ {
|
if command != _|_ {
|
||||||
args: [cmd.name] + cmd._flatFlags + cmd.args
|
args: [command.name] + command._flatFlags + command.args
|
||||||
}
|
}
|
||||||
if cmd == _|_ {
|
if command == _|_ {
|
||||||
args: list.Concat([
|
args: list.Concat([
|
||||||
if _image.config.entrypoint != _|_ {
|
if _image.config.entrypoint != _|_ {
|
||||||
_image.config.entrypoint
|
_image.config.entrypoint
|
||||||
|
@ -16,19 +16,28 @@ dagger.#Plan & {
|
|||||||
steps: [
|
steps: [
|
||||||
alpine.#Build,
|
alpine.#Build,
|
||||||
docker.#Run & {
|
docker.#Run & {
|
||||||
script: """
|
command: {
|
||||||
|
name: "sh"
|
||||||
|
flags: "-c": """
|
||||||
echo -n hello > /bar.txt
|
echo -n hello > /bar.txt
|
||||||
"""
|
"""
|
||||||
|
}
|
||||||
},
|
},
|
||||||
docker.#Run & {
|
docker.#Run & {
|
||||||
script: """
|
command: {
|
||||||
|
name: "sh"
|
||||||
|
flags: "-c": """
|
||||||
echo -n $(cat /bar.txt) world > /foo.txt
|
echo -n $(cat /bar.txt) world > /foo.txt
|
||||||
"""
|
"""
|
||||||
|
}
|
||||||
},
|
},
|
||||||
docker.#Run & {
|
docker.#Run & {
|
||||||
script: """
|
command: {
|
||||||
|
name: "sh"
|
||||||
|
flags: "-c": """
|
||||||
echo -n $(cat /foo.txt) >> /test.txt
|
echo -n $(cat /foo.txt) >> /test.txt
|
||||||
"""
|
"""
|
||||||
|
}
|
||||||
},
|
},
|
||||||
]
|
]
|
||||||
}
|
}
|
||||||
|
@ -17,9 +17,10 @@ dagger.#Plan & {
|
|||||||
steps: [
|
steps: [
|
||||||
alpine.#Build,
|
alpine.#Build,
|
||||||
docker.#Run & {
|
docker.#Run & {
|
||||||
script: """
|
command: {
|
||||||
echo -n $TEST >> /test.txt
|
name: "sh"
|
||||||
"""
|
flags: "-c": "echo -n $TEST >> /test.txt"
|
||||||
|
}
|
||||||
env: TEST: #testValue
|
env: TEST: #testValue
|
||||||
},
|
},
|
||||||
]
|
]
|
||||||
|
@ -27,7 +27,7 @@ dagger.#Plan & {
|
|||||||
}
|
}
|
||||||
run: docker.#Run & {
|
run: docker.#Run & {
|
||||||
image: myimage
|
image: myimage
|
||||||
cmd: name: "ls"
|
command: name: "ls"
|
||||||
export: files: {
|
export: files: {
|
||||||
"/dagger.txt": _ & {
|
"/dagger.txt": _ & {
|
||||||
contents: "not hello from dagger"
|
contents: "not hello from dagger"
|
||||||
@ -57,9 +57,12 @@ dagger.#Plan & {
|
|||||||
|
|
||||||
verify_working_directory: docker.#Run & {
|
verify_working_directory: docker.#Run & {
|
||||||
image: myimage
|
image: myimage
|
||||||
script: #"""
|
command: {
|
||||||
|
name: "sh"
|
||||||
|
flags: "-c": #"""
|
||||||
pwd > dir.txt
|
pwd > dir.txt
|
||||||
"""#
|
"""#
|
||||||
|
}
|
||||||
export: files: "/bin/dir.txt": _ & {
|
export: files: "/bin/dir.txt": _ & {
|
||||||
contents: "/bin\n"
|
contents: "/bin\n"
|
||||||
}
|
}
|
||||||
@ -67,9 +70,12 @@ dagger.#Plan & {
|
|||||||
verify_working_directory_is_overridden: docker.#Run & {
|
verify_working_directory_is_overridden: docker.#Run & {
|
||||||
image: myimage
|
image: myimage
|
||||||
workdir: "/"
|
workdir: "/"
|
||||||
script: #"""
|
command: {
|
||||||
|
name: "sh"
|
||||||
|
flags: "-c": #"""
|
||||||
pwd > dir.txt
|
pwd > dir.txt
|
||||||
"""#
|
"""#
|
||||||
|
}
|
||||||
export: files: "/dir.txt": _ & {
|
export: files: "/dir.txt": _ & {
|
||||||
contents: "/\n"
|
contents: "/\n"
|
||||||
}
|
}
|
||||||
|
@ -5,6 +5,7 @@ import (
|
|||||||
"universe.dagger.io/docker"
|
"universe.dagger.io/docker"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
// FIXME: this test is currently broken (see docker.bats)
|
||||||
dagger.#Plan & {
|
dagger.#Plan & {
|
||||||
actions: build: docker.#Build & {
|
actions: build: docker.#Build & {
|
||||||
steps: [
|
steps: [
|
||||||
@ -16,17 +17,17 @@ dagger.#Plan & {
|
|||||||
source: "alpine"
|
source: "alpine"
|
||||||
},
|
},
|
||||||
docker.#Run & {
|
docker.#Run & {
|
||||||
cmd: name: "ls"
|
command: name: "ls"
|
||||||
},
|
},
|
||||||
]
|
]
|
||||||
},
|
},
|
||||||
docker.#Run & {
|
docker.#Run & {
|
||||||
cmd: name: "ls"
|
command: name: "ls"
|
||||||
},
|
},
|
||||||
]
|
]
|
||||||
},
|
},
|
||||||
docker.#Run & {
|
docker.#Run & {
|
||||||
cmd: name: "ls"
|
command: name: "ls"
|
||||||
},
|
},
|
||||||
]
|
]
|
||||||
}
|
}
|
||||||
|
@ -14,12 +14,12 @@ dagger.#Plan & {
|
|||||||
source: "alpine"
|
source: "alpine"
|
||||||
},
|
},
|
||||||
docker.#Run & {
|
docker.#Run & {
|
||||||
cmd: name: "ls"
|
command: name: "ls"
|
||||||
},
|
},
|
||||||
]
|
]
|
||||||
},
|
},
|
||||||
docker.#Run & {
|
docker.#Run & {
|
||||||
cmd: name: "ls"
|
command: name: "ls"
|
||||||
},
|
},
|
||||||
]
|
]
|
||||||
}
|
}
|
||||||
|
@ -13,7 +13,7 @@ dagger.#Plan & {
|
|||||||
|
|
||||||
run: docker.#Run & {
|
run: docker.#Run & {
|
||||||
"image": image.output
|
"image": image.output
|
||||||
cmd: {
|
command: {
|
||||||
name: "/bin/sh"
|
name: "/bin/sh"
|
||||||
args: ["-c", "echo -n hello world >> /output.txt"]
|
args: ["-c", "echo -n hello world >> /output.txt"]
|
||||||
}
|
}
|
||||||
|
@ -13,10 +13,13 @@ dagger.#Plan & {
|
|||||||
|
|
||||||
run: docker.#Run & {
|
run: docker.#Run & {
|
||||||
"image": image.output
|
"image": image.output
|
||||||
script: #"""
|
command: {
|
||||||
|
name: "sh"
|
||||||
|
flags: "-c": #"""
|
||||||
mkdir -p test
|
mkdir -p test
|
||||||
echo -n hello world >> /test/output.txt
|
echo -n hello world >> /test/output.txt
|
||||||
"""#
|
"""#
|
||||||
|
}
|
||||||
export: {
|
export: {
|
||||||
directories: "/test": _
|
directories: "/test": _
|
||||||
files: "/test/output.txt": _ & {
|
files: "/test/output.txt": _ & {
|
||||||
|
@ -12,9 +12,12 @@ dagger.#Plan & {
|
|||||||
|
|
||||||
run: docker.#Run & {
|
run: docker.#Run & {
|
||||||
"image": image.output
|
"image": image.output
|
||||||
script: #"""
|
command: {
|
||||||
|
name: "sh"
|
||||||
|
flags: "-c": #"""
|
||||||
echo -n hello world >> /output.txt
|
echo -n hello world >> /output.txt
|
||||||
"""#
|
"""#
|
||||||
|
}
|
||||||
export: files: "/output.txt": _ & {
|
export: files: "/output.txt": _ & {
|
||||||
contents: "hello world"
|
contents: "hello world"
|
||||||
}
|
}
|
||||||
|
@ -13,9 +13,12 @@ dagger.#Plan & {
|
|||||||
|
|
||||||
run: docker.#Run & {
|
run: docker.#Run & {
|
||||||
"image": image.output
|
"image": image.output
|
||||||
script: #"""
|
command: {
|
||||||
|
name: "sh"
|
||||||
|
flags: "-c": #"""
|
||||||
echo -n $TEST_MESSAGE >> /output.txt
|
echo -n $TEST_MESSAGE >> /output.txt
|
||||||
"""#
|
"""#
|
||||||
|
}
|
||||||
env: TEST_MESSAGE: "hello world"
|
env: TEST_MESSAGE: "hello world"
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -38,7 +38,10 @@ dagger.#Plan & {
|
|||||||
dev.assets,
|
dev.assets,
|
||||||
// 2. Mix magical command
|
// 2. Mix magical command
|
||||||
mix.#Run & {
|
mix.#Run & {
|
||||||
script: "mix phx.digest"
|
command: {
|
||||||
|
name: "mix"
|
||||||
|
args: ["phx.digest"]
|
||||||
|
}
|
||||||
mix: {
|
mix: {
|
||||||
env: "prod"
|
env: "prod"
|
||||||
app: _appName
|
app: _appName
|
||||||
@ -94,7 +97,12 @@ dagger.#Plan & {
|
|||||||
}
|
}
|
||||||
// FIXME: run 'yarn install' and 'yarn run compile' separately, with different caching?
|
// FIXME: run 'yarn install' and 'yarn run compile' separately, with different caching?
|
||||||
// FIXME: can we reuse universe.dagger.io/yarn ???? 0:-)
|
// FIXME: can we reuse universe.dagger.io/yarn ???? 0:-)
|
||||||
script: "yarn install --frozen-lockfile && yarn run compile"
|
command: {
|
||||||
|
name: "sh"
|
||||||
|
flags: "-c": """
|
||||||
|
yarn install --frozen-lockfile && yarn run compile"
|
||||||
|
"""
|
||||||
|
}
|
||||||
workdir: "/app/assets"
|
workdir: "/app/assets"
|
||||||
},
|
},
|
||||||
]
|
]
|
||||||
@ -111,7 +119,10 @@ dagger.#Plan & {
|
|||||||
// Run tests
|
// Run tests
|
||||||
run: docker.#Run & {
|
run: docker.#Run & {
|
||||||
image: build.output
|
image: build.output
|
||||||
script: "mix test"
|
command: {
|
||||||
|
name: "mix"
|
||||||
|
args: ["test"]
|
||||||
|
}
|
||||||
// Don't cache running tests
|
// Don't cache running tests
|
||||||
// Just because we've tested a version before, doesn't mean we don't
|
// Just because we've tested a version before, doesn't mean we don't
|
||||||
// want to test it again.
|
// want to test it again.
|
||||||
|
@ -42,7 +42,10 @@ import (
|
|||||||
depsCache: "locked"
|
depsCache: "locked"
|
||||||
}
|
}
|
||||||
workdir: "/app"
|
workdir: "/app"
|
||||||
script: "mix deps.get"
|
command: {
|
||||||
|
name: "mix"
|
||||||
|
args: ["deps.get"]
|
||||||
|
}
|
||||||
},
|
},
|
||||||
// 4. Build!
|
// 4. Build!
|
||||||
// FIXME: step 5 is to add image data, see issue 1339
|
// FIXME: step 5 is to add image data, see issue 1339
|
||||||
@ -54,7 +57,10 @@ import (
|
|||||||
buildCache: "locked"
|
buildCache: "locked"
|
||||||
}
|
}
|
||||||
workdir: "/app"
|
workdir: "/app"
|
||||||
script: "mix do deps.compile, compile"
|
command: {
|
||||||
|
name: "mix"
|
||||||
|
args: ["do", "deps.compile,compile"]
|
||||||
|
}
|
||||||
},
|
},
|
||||||
]
|
]
|
||||||
}
|
}
|
||||||
|
@ -51,7 +51,7 @@ import (
|
|||||||
}
|
}
|
||||||
},
|
},
|
||||||
docker.#Run & {
|
docker.#Run & {
|
||||||
cmd: {
|
command: {
|
||||||
name: "yarn"
|
name: "yarn"
|
||||||
args: ["global", "add", "netlify-cli@8.6.21"]
|
args: ["global", "add", "netlify-cli@8.6.21"]
|
||||||
}
|
}
|
||||||
@ -76,7 +76,10 @@ import (
|
|||||||
// yarn: version: "=~1.22"
|
// yarn: version: "=~1.22"
|
||||||
// }
|
// }
|
||||||
// steps: [{
|
// steps: [{
|
||||||
// run: script: "yarn global add netlify-cli@3.38.10"
|
// run: command: {
|
||||||
|
// name: "sh"
|
||||||
|
// flags: "-c": "yarn global add netlify-cli@3.38.10"
|
||||||
|
// }
|
||||||
// }]
|
// }]
|
||||||
// }
|
// }
|
||||||
|
|
||||||
@ -111,7 +114,7 @@ import (
|
|||||||
contents: token
|
contents: token
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
cmd: name: "/app/deploy.sh"
|
command: name: "/app/deploy.sh"
|
||||||
|
|
||||||
export: files: {
|
export: files: {
|
||||||
"/netlify/url": _
|
"/netlify/url": _
|
||||||
|
@ -8,9 +8,13 @@ import (
|
|||||||
)
|
)
|
||||||
|
|
||||||
// Run a python script in a container
|
// Run a python script in a container
|
||||||
#Run: docker.#Run & {
|
#Run: {
|
||||||
|
// Contents of the python script
|
||||||
script: string
|
script: string
|
||||||
cmd: {
|
|
||||||
|
// FIXME: don't pass the script as argument: write to filesystme instead
|
||||||
|
docker.#Run & {
|
||||||
|
command: {
|
||||||
name: "python"
|
name: "python"
|
||||||
flags: "-c": script
|
flags: "-c": script
|
||||||
}
|
}
|
||||||
@ -22,3 +26,4 @@ import (
|
|||||||
packages: python: version: "3"
|
packages: python: version: "3"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
Reference in New Issue
Block a user