2021-05-06 08:53:04 +02:00
|
|
|
package os
|
2021-04-03 02:51:56 +02:00
|
|
|
|
|
|
|
import (
|
2021-04-06 03:37:31 +02:00
|
|
|
"strings"
|
|
|
|
|
2021-04-03 02:51:56 +02:00
|
|
|
"dagger.io/dagger"
|
2021-04-06 02:27:51 +02:00
|
|
|
"dagger.io/dagger/op"
|
2021-04-09 01:39:07 +02:00
|
|
|
|
|
|
|
"dagger.io/alpine"
|
2021-04-03 02:51:56 +02:00
|
|
|
)
|
|
|
|
|
2021-04-09 01:39:07 +02:00
|
|
|
// Default image for basic use cases
|
|
|
|
// FIXME: should just be 'alpine.#Image'.
|
|
|
|
// referring to '#.up' is a workaround to a dagger engine bug.
|
|
|
|
// see https://github.com/dagger/dagger/issues/304
|
|
|
|
#DefaultImage: alpine.#Image.#up
|
|
|
|
|
2021-05-06 08:53:04 +02:00
|
|
|
// Built-in container implementation, using buildkit
|
2021-04-03 02:51:56 +02:00
|
|
|
#Container: {
|
|
|
|
|
2021-04-06 22:52:06 +02:00
|
|
|
// Container image
|
2021-04-09 01:39:07 +02:00
|
|
|
image: dagger.#Artifact | *#DefaultImage
|
2021-05-06 08:53:04 +02:00
|
|
|
// {
|
|
|
|
// // Optionally fetch a remote image
|
|
|
|
// // eg. "index.docker.io/alpine"
|
|
|
|
// from: string
|
|
|
|
// image: #up: [op.#FetchContainer & { "ref": from }]
|
|
|
|
// } | {}
|
2021-04-03 02:51:56 +02:00
|
|
|
|
2021-04-06 22:52:06 +02:00
|
|
|
// Independently cacheable setup commands
|
2021-04-06 03:37:31 +02:00
|
|
|
setup: [...string]
|
2021-04-03 02:51:56 +02:00
|
|
|
|
2021-04-06 22:52:06 +02:00
|
|
|
// Command to execute
|
2021-04-30 08:05:22 +02:00
|
|
|
command: string | *""
|
2021-04-06 22:52:06 +02:00
|
|
|
|
2021-04-03 02:51:56 +02:00
|
|
|
// Environment variables shared by all commands
|
|
|
|
env: [string]: string
|
|
|
|
|
2021-04-06 22:52:06 +02:00
|
|
|
// Directory in which the command is executed
|
|
|
|
dir: string | *"/"
|
|
|
|
|
|
|
|
// If true, the command is never cached.
|
|
|
|
// (false by default).
|
|
|
|
always: true | *false
|
|
|
|
|
2021-05-06 08:53:04 +02:00
|
|
|
// Copy contents from other artifacts
|
|
|
|
copy: [string]: from: dagger.#Artifact
|
|
|
|
|
|
|
|
// Mount contents from other artifacts.
|
|
|
|
// Mount is active when executing `command`, but not `setup`.
|
|
|
|
|
|
|
|
mount: [string]: {
|
2021-05-14 01:20:58 +02:00
|
|
|
from: dagger.#Artifact
|
2021-05-06 08:53:04 +02:00
|
|
|
// FIXME: support source path
|
2021-04-03 02:51:56 +02:00
|
|
|
}
|
|
|
|
|
2021-05-06 08:53:04 +02:00
|
|
|
// Mount persistent cache directories
|
|
|
|
cache: [string]: true
|
|
|
|
|
|
|
|
// Mount temporary directories
|
|
|
|
tmpfs: [string]: true
|
|
|
|
|
2021-04-06 22:52:06 +02:00
|
|
|
// Configure the shell which executes all commands.
|
2021-04-06 03:37:31 +02:00
|
|
|
shell: {
|
2021-04-06 22:52:06 +02:00
|
|
|
// Path of the shell to execute
|
2021-04-06 03:37:31 +02:00
|
|
|
path: string | *"/bin/sh"
|
2021-04-06 22:52:06 +02:00
|
|
|
// Arguments to pass to the shell prior to the command
|
2021-04-06 03:37:31 +02:00
|
|
|
args: [...string] | *["-c"]
|
2021-04-06 22:52:06 +02:00
|
|
|
// Map of directories to search for commands
|
|
|
|
// In POSIX shells this is used to generate the $PATH
|
|
|
|
// environment variable.
|
2021-04-06 03:37:31 +02:00
|
|
|
search: [string]: bool
|
|
|
|
search: {
|
|
|
|
"/sbin": true
|
|
|
|
"/bin": true
|
|
|
|
"/usr/sbin": true
|
|
|
|
"/usr/bin": true
|
|
|
|
"/usr/local/sbin": true
|
|
|
|
"/usr/local/bin": true
|
2021-04-03 02:51:56 +02:00
|
|
|
}
|
2021-04-06 03:37:31 +02:00
|
|
|
}
|
|
|
|
env: PATH: string | *strings.Join([ for p, v in shell.search if v {p}], ":")
|
|
|
|
|
|
|
|
#up: [
|
|
|
|
op.#Load & {from: image},
|
|
|
|
// Copy volumes with type=copy
|
2021-05-06 08:53:04 +02:00
|
|
|
for dest, o in copy {
|
2021-04-06 03:37:31 +02:00
|
|
|
op.#Copy & {
|
2021-05-06 08:53:04 +02:00
|
|
|
"dest": dest
|
|
|
|
from: o.from
|
|
|
|
// FIXME: support source path
|
2021-04-06 03:37:31 +02:00
|
|
|
}
|
|
|
|
},
|
2021-05-01 02:06:33 +02:00
|
|
|
// Execute setup commands, without volumes
|
|
|
|
for cmd in setup {
|
2021-04-06 02:27:51 +02:00
|
|
|
op.#Exec & {
|
2021-04-06 03:37:31 +02:00
|
|
|
args: [shell.path] + shell.args + [cmd]
|
2021-04-03 02:51:56 +02:00
|
|
|
"env": env
|
|
|
|
"dir": dir
|
|
|
|
"always": always
|
2021-05-01 02:06:33 +02:00
|
|
|
}
|
|
|
|
},
|
|
|
|
// Execute main command with volumes
|
|
|
|
if command != "" {
|
|
|
|
op.#Exec & {
|
|
|
|
args: [shell.path] + shell.args + [command]
|
|
|
|
"env": env
|
|
|
|
"dir": dir
|
|
|
|
"always": always
|
2021-05-06 08:53:04 +02:00
|
|
|
"mount": {
|
|
|
|
for dest, o in mount {
|
|
|
|
"\(dest)": from: o.from
|
|
|
|
// FIXME: support source path
|
2021-04-03 02:51:56 +02:00
|
|
|
}
|
2021-05-06 08:53:04 +02:00
|
|
|
for dest in cache {
|
|
|
|
"\(dest)": "cache"
|
2021-04-03 02:51:56 +02:00
|
|
|
}
|
2021-05-06 08:53:04 +02:00
|
|
|
for dest in tmpfs {
|
|
|
|
"\(dest)": "tmpfs"
|
2021-04-03 02:51:56 +02:00
|
|
|
}
|
|
|
|
}
|
2021-04-06 03:37:31 +02:00
|
|
|
}
|
|
|
|
},
|
|
|
|
]
|
2021-04-03 02:51:56 +02:00
|
|
|
}
|