bash.#Run: new and improved

* Script is written to filesystem, not inlined as argument
* Pass script either as string, or directory+filename

Signed-off-by: Solomon Hykes <solomon@dagger.io>
This commit is contained in:
Solomon Hykes
2022-02-08 17:54:42 +00:00
parent 4944bead44
commit 013900c2a2
8 changed files with 171 additions and 75 deletions

View File

@@ -2,25 +2,59 @@
package bash
import (
"dagger.io/dagger"
"dagger.io/dagger/engine"
"universe.dagger.io/docker"
)
// Run a bash command or script in a container
// Run a bash script in a Docker container
// Since this is a thin wrapper over docker.#Run, we embed it.
// Whether to embed or wrap is a case-by-case decision, like in Go.
#Run: {
// Contents of the bash script
script: string
// The script to execute
script: {
// A directory containing one or more bash scripts
directory: dagger.#FS
// Name of the file to execute
filename: string
_directory: directory
_filename: filename
} | {
// Script contents
contents: string
_filename: "run.sh"
_write: engine.#WriteFile & {
input: engine.#Scratch
path: _filename
"contents": contents
}
_directory: _write.output
}
// Arguments to the script
args: [...string]
// Where in the container to mount the scripts directory
_mountpoint: "/bash/scripts"
// FIXME: don't pass the script as argument: write to filesystme instead
docker.#Run & {
command: {
name: "bash"
name: "bash"
"args": ["\(_mountpoint)/\(script._filename)"] + args
// FIXME: make default flags overrideable
flags: {
"-c": script
"--noprofile": true
"--norc": true
"-e": true
"-o": "pipefail"
"--norc": true
"-e": true
"-o": "pipefail"
}
}
mounts: "Bash scripts": {
contents: script._directory
dest: _mountpoint
}
}
}