2021-11-04 08:05:24 +01:00
|
|
|
package docker
|
|
|
|
|
|
|
|
import (
|
|
|
|
"list"
|
|
|
|
|
|
|
|
"dagger.io/dagger"
|
2022-01-07 05:53:29 +01:00
|
|
|
"dagger.io/dagger/engine"
|
2021-11-04 08:05:24 +01:00
|
|
|
)
|
|
|
|
|
|
|
|
// Run a command in a container
|
|
|
|
#Run: {
|
2022-01-15 21:33:50 +01:00
|
|
|
_image: #Image
|
|
|
|
|
|
|
|
{
|
|
|
|
image: #Image
|
|
|
|
_image: image
|
|
|
|
} | {
|
|
|
|
// For compatibility with #Build
|
|
|
|
input: #Image
|
|
|
|
_image: input
|
|
|
|
}
|
2021-11-04 08:05:24 +01:00
|
|
|
|
|
|
|
always: bool | *false
|
|
|
|
|
|
|
|
// Filesystem mounts
|
|
|
|
mounts: [name=string]: engine.#Mount
|
|
|
|
|
|
|
|
// Expose network ports
|
2021-12-14 23:33:11 +01:00
|
|
|
// FIXME: investigate feasibility
|
2021-11-04 08:05:24 +01:00
|
|
|
ports: [name=string]: {
|
|
|
|
frontend: dagger.#Service
|
|
|
|
backend: {
|
|
|
|
protocol: *"tcp" | "udp"
|
|
|
|
address: string
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// Command to execute
|
|
|
|
cmd: {
|
|
|
|
// Name of the command to execute
|
|
|
|
// Examples: "ls", "/bin/bash"
|
|
|
|
name: string
|
|
|
|
|
|
|
|
// Positional arguments to the command
|
|
|
|
// Examples: ["/tmp"]
|
|
|
|
args: [...string]
|
|
|
|
|
|
|
|
// Command-line flags represented in a civilized form
|
|
|
|
// Example: {"-l": true, "-c": "echo hello world"}
|
|
|
|
flags: [string]: (string | true)
|
|
|
|
|
|
|
|
_flatFlags: list.FlattenN([
|
|
|
|
for k, v in flags {
|
|
|
|
if (v & bool) != _|_ {
|
|
|
|
[k]
|
|
|
|
}
|
|
|
|
if (v & string) != _|_ {
|
|
|
|
[k, v]
|
|
|
|
}
|
|
|
|
},
|
|
|
|
], 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
|
|
|
|
|
|
|
|
// Working directory for the command
|
|
|
|
// Example: "/src"
|
|
|
|
workdir: string | *"/"
|
|
|
|
|
|
|
|
// Username or UID to ad
|
|
|
|
// User identity for this command
|
|
|
|
// Examples: "root", "0", "1002"
|
2021-12-14 23:33:11 +01:00
|
|
|
user: string | *"root"
|
2021-11-04 08:05:24 +01:00
|
|
|
|
|
|
|
// Output fields
|
|
|
|
{
|
|
|
|
// Has the command completed?
|
|
|
|
completed: bool & (_exec.exit != _|_)
|
|
|
|
|
|
|
|
// Was completion successful?
|
|
|
|
success: bool & (_exec.exit == 0)
|
|
|
|
|
|
|
|
// Details on error, if any
|
|
|
|
error: {
|
|
|
|
// Error code
|
|
|
|
code: _exec.exit
|
|
|
|
|
|
|
|
// Error message
|
|
|
|
message: string | *null
|
|
|
|
}
|
|
|
|
|
2022-01-15 21:33:50 +01:00
|
|
|
export: {
|
|
|
|
rootfs: dagger.#FS & _exec.output
|
2021-11-04 08:05:24 +01:00
|
|
|
files: [path=string]: {
|
2022-01-15 21:33:50 +01:00
|
|
|
contents: string & _read.contents
|
|
|
|
_read: engine.#ReadFile & {
|
2021-11-04 08:05:24 +01:00
|
|
|
input: _exec.output
|
|
|
|
"path": path
|
|
|
|
}
|
|
|
|
}
|
|
|
|
directories: [path=string]: {
|
2022-01-15 21:33:50 +01:00
|
|
|
contents: dagger.#FS & _subdir.output
|
|
|
|
_subdir: dagger.#Subdir & {
|
2021-11-04 08:05:24 +01:00
|
|
|
input: _exec.output
|
|
|
|
"path": path
|
2022-01-15 21:33:50 +01:00
|
|
|
}
|
2021-11-04 08:05:24 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-01-15 21:33:50 +01:00
|
|
|
// For compatibility with #Build
|
|
|
|
output: #Image & {
|
|
|
|
rootfs: _exec.output
|
|
|
|
config: _image.config
|
|
|
|
}
|
|
|
|
|
2021-11-04 08:05:24 +01:00
|
|
|
// Actually execute the command
|
|
|
|
_exec: engine.#Exec & {
|
2021-12-14 23:33:11 +01:00
|
|
|
args: [cmd.name] + cmd._flatFlags + cmd.args
|
2022-01-15 21:33:50 +01:00
|
|
|
input: _image.rootfs
|
2021-12-14 23:33:11 +01:00
|
|
|
"mounts": mounts
|
|
|
|
"env": env
|
2021-11-04 08:05:24 +01:00
|
|
|
"workdir": workdir
|
2021-12-14 23:33:11 +01:00
|
|
|
"user": user
|
2021-11-04 08:05:24 +01:00
|
|
|
}
|
|
|
|
}
|