2021-05-06 08:53:04 +02:00
|
|
|
package os
|
2021-04-03 02:51:56 +02:00
|
|
|
|
|
|
|
import (
|
2021-06-23 16:31:42 +02:00
|
|
|
"alpha.dagger.io/dagger"
|
|
|
|
"alpha.dagger.io/dagger/op"
|
2021-04-09 01:39:07 +02:00
|
|
|
|
2021-06-23 16:31:42 +02:00
|
|
|
"alpha.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-06-23 12:46:56 +02:00
|
|
|
// Safely mount secrets (in cleartext) as non-persistent files
|
|
|
|
secret: [string]: dagger.#Secret
|
|
|
|
|
2021-12-14 01:09:38 +01:00
|
|
|
// Mount unix socket or windows npipes to the corresponding path
|
|
|
|
socket: [string]: dagger.#Stream
|
|
|
|
|
2021-09-01 18:48:54 +02:00
|
|
|
// Write file in the container
|
|
|
|
files: [string]: {
|
|
|
|
content: string
|
|
|
|
mode: int | *0o644
|
|
|
|
}
|
|
|
|
|
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"]
|
|
|
|
}
|
|
|
|
|
|
|
|
#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-05-26 03:56:16 +02:00
|
|
|
args: [shell.path] + shell.args + [cmd]
|
|
|
|
"env": env
|
|
|
|
"dir": dir
|
2021-05-01 02:06:33 +02:00
|
|
|
}
|
|
|
|
},
|
2021-09-01 18:48:54 +02:00
|
|
|
for dest, file in files {
|
|
|
|
op.#WriteFile & {
|
2021-09-01 18:49:21 +02:00
|
|
|
content: file.content
|
|
|
|
mode: file.mode
|
|
|
|
"dest": dest
|
2021-09-01 18:48:54 +02:00
|
|
|
}
|
|
|
|
},
|
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 {
|
2021-05-26 03:56:16 +02:00
|
|
|
"\(dest)": o
|
2021-05-06 08:53:04 +02:00
|
|
|
// FIXME: support source path
|
2021-04-03 02:51:56 +02:00
|
|
|
}
|
2021-06-23 12:46:56 +02:00
|
|
|
for dest, s in secret {
|
|
|
|
"\(dest)": secret: s
|
|
|
|
}
|
2021-06-09 15:21:30 +02:00
|
|
|
for dest, _ in cache {
|
2021-05-06 08:53:04 +02:00
|
|
|
"\(dest)": "cache"
|
2021-04-03 02:51:56 +02:00
|
|
|
}
|
2021-06-09 15:21:30 +02:00
|
|
|
for dest, _ in tmpfs {
|
2021-05-06 08:53:04 +02:00
|
|
|
"\(dest)": "tmpfs"
|
2021-04-03 02:51:56 +02:00
|
|
|
}
|
2021-12-14 01:09:38 +01:00
|
|
|
for dest, s in socket {
|
|
|
|
"\(dest)": stream: s
|
|
|
|
}
|
2021-04-03 02:51:56 +02:00
|
|
|
}
|
2021-04-06 03:37:31 +02:00
|
|
|
}
|
|
|
|
},
|
|
|
|
]
|
2021-04-03 02:51:56 +02:00
|
|
|
}
|