126
stdlib/os/container.cue
Normal file
126
stdlib/os/container.cue
Normal file
@@ -0,0 +1,126 @@
|
||||
package os
|
||||
|
||||
import (
|
||||
"strings"
|
||||
|
||||
"dagger.io/dagger"
|
||||
"dagger.io/dagger/op"
|
||||
|
||||
"dagger.io/alpine"
|
||||
)
|
||||
|
||||
// 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
|
||||
|
||||
// Built-in container implementation, using buildkit
|
||||
#Container: {
|
||||
|
||||
// Container image
|
||||
image: dagger.#Artifact | *#DefaultImage
|
||||
// {
|
||||
// // Optionally fetch a remote image
|
||||
// // eg. "index.docker.io/alpine"
|
||||
// from: string
|
||||
// image: #up: [op.#FetchContainer & { "ref": from }]
|
||||
// } | {}
|
||||
|
||||
// Independently cacheable setup commands
|
||||
setup: [...string]
|
||||
|
||||
// Command to execute
|
||||
command: string | *""
|
||||
|
||||
// Environment variables shared by all commands
|
||||
env: [string]: string
|
||||
|
||||
// Directory in which the command is executed
|
||||
dir: string | *"/"
|
||||
|
||||
// If true, the command is never cached.
|
||||
// (false by default).
|
||||
always: true | *false
|
||||
|
||||
// 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]: {
|
||||
// FIXME(perf) should be #Artifact. See https://github.com/dagger/dagger/issues/445
|
||||
from: {...}
|
||||
// FIXME: support source path
|
||||
}
|
||||
|
||||
// Mount persistent cache directories
|
||||
cache: [string]: true
|
||||
|
||||
// Mount temporary directories
|
||||
tmpfs: [string]: true
|
||||
|
||||
// Configure the shell which executes all commands.
|
||||
shell: {
|
||||
// Path of the shell to execute
|
||||
path: string | *"/bin/sh"
|
||||
// Arguments to pass to the shell prior to the command
|
||||
args: [...string] | *["-c"]
|
||||
// Map of directories to search for commands
|
||||
// In POSIX shells this is used to generate the $PATH
|
||||
// environment variable.
|
||||
search: [string]: bool
|
||||
search: {
|
||||
"/sbin": true
|
||||
"/bin": true
|
||||
"/usr/sbin": true
|
||||
"/usr/bin": true
|
||||
"/usr/local/sbin": true
|
||||
"/usr/local/bin": true
|
||||
}
|
||||
}
|
||||
env: PATH: string | *strings.Join([ for p, v in shell.search if v {p}], ":")
|
||||
|
||||
#up: [
|
||||
op.#Load & {from: image},
|
||||
// Copy volumes with type=copy
|
||||
for dest, o in copy {
|
||||
op.#Copy & {
|
||||
"dest": dest
|
||||
from: o.from
|
||||
// FIXME: support source path
|
||||
}
|
||||
},
|
||||
// Execute setup commands, without volumes
|
||||
for cmd in setup {
|
||||
op.#Exec & {
|
||||
args: [shell.path] + shell.args + [cmd]
|
||||
"env": env
|
||||
"dir": dir
|
||||
"always": always
|
||||
}
|
||||
},
|
||||
// Execute main command with volumes
|
||||
if command != "" {
|
||||
op.#Exec & {
|
||||
args: [shell.path] + shell.args + [command]
|
||||
"env": env
|
||||
"dir": dir
|
||||
"always": always
|
||||
"mount": {
|
||||
for dest, o in mount {
|
||||
"\(dest)": from: o.from
|
||||
// FIXME: support source path
|
||||
}
|
||||
for dest in cache {
|
||||
"\(dest)": "cache"
|
||||
}
|
||||
for dest in tmpfs {
|
||||
"\(dest)": "tmpfs"
|
||||
}
|
||||
}
|
||||
}
|
||||
},
|
||||
]
|
||||
}
|
@@ -1,13 +1,23 @@
|
||||
package os
|
||||
|
||||
import (
|
||||
"dagger.io/io"
|
||||
|
||||
"dagger.io/dagger"
|
||||
"dagger.io/dagger/op"
|
||||
)
|
||||
|
||||
#Dir: io.#Dir & {
|
||||
#Dir: {
|
||||
from: dagger.#Artifact
|
||||
path: string | *"/"
|
||||
|
||||
#up: [
|
||||
op.#Load & {"from": from},
|
||||
op.#Subdir & {
|
||||
dir: path
|
||||
},
|
||||
]
|
||||
}
|
||||
|
||||
#ReadDir: {
|
||||
from: dagger.#Artifact
|
||||
path: string
|
||||
|
||||
@@ -32,34 +42,3 @@ import (
|
||||
]
|
||||
}
|
||||
}
|
||||
|
||||
#File: {
|
||||
from: dagger.#Artifact
|
||||
path: string
|
||||
|
||||
io.#Reader & {
|
||||
read: {
|
||||
format: _
|
||||
data: {
|
||||
_
|
||||
#up: [
|
||||
op.#Load & {"from": from},
|
||||
op.#Export & {source: path, "format": format},
|
||||
]
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
io.#Writer & {
|
||||
write: *null | {
|
||||
data: _
|
||||
#up: [
|
||||
op.#Load & {"from": from},
|
||||
op.#WriteFile & {
|
||||
dest: path
|
||||
contents: data
|
||||
},
|
||||
]
|
||||
}
|
||||
}
|
||||
}
|
36
stdlib/os/file.cue
Normal file
36
stdlib/os/file.cue
Normal file
@@ -0,0 +1,36 @@
|
||||
package os
|
||||
|
||||
import (
|
||||
"dagger.io/dagger"
|
||||
"dagger.io/dagger/op"
|
||||
)
|
||||
|
||||
// Built-in file implementation, using buildkit
|
||||
#File: {
|
||||
from: dagger.#Artifact
|
||||
path: string
|
||||
|
||||
read: {
|
||||
// FIXME: support different data schemas for different formats
|
||||
format: "string"
|
||||
data: {
|
||||
string
|
||||
#up: [
|
||||
op.#Load & {"from": from},
|
||||
op.#Export & {source: path, "format": format},
|
||||
]
|
||||
}
|
||||
}
|
||||
|
||||
write: *null | {
|
||||
// FIXME: support encoding in different formats
|
||||
data: string
|
||||
#up: [
|
||||
op.#Load & {"from": from},
|
||||
op.#WriteFile & {
|
||||
dest: path
|
||||
contents: data
|
||||
},
|
||||
]
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user