{do:"subdir"} to select a subdirectory in a script
Signed-off-by: Solomon Hykes <sh.github.6811@hykes.org>
This commit is contained in:
parent
0202f4447b
commit
622de21883
@ -60,7 +60,7 @@ package dagger
|
||||
#Script: [...#Op]
|
||||
|
||||
// One operation in a script
|
||||
#Op: #FetchContainer | #FetchGit | #Export | #Exec | #Local | #Copy | #Load
|
||||
#Op: #FetchContainer | #FetchGit | #Export | #Exec | #Local | #Copy | #Load | #Subdir
|
||||
|
||||
// Export a value from fs state to cue
|
||||
#Export: {
|
||||
@ -83,6 +83,11 @@ package dagger
|
||||
from: #Component | #Script
|
||||
}
|
||||
|
||||
#Subdir: {
|
||||
do: "subdir"
|
||||
dir: string | *"/"
|
||||
}
|
||||
|
||||
#Exec: {
|
||||
do: "exec"
|
||||
args: [...string]
|
||||
|
21
dagger/op.go
21
dagger/op.go
@ -94,6 +94,7 @@ func (op *Op) Action() (Action, error) {
|
||||
"#FetchGit": op.FetchGit,
|
||||
"#Local": op.Local,
|
||||
"#Load": op.Load,
|
||||
"#Subdir": op.Subdir,
|
||||
}
|
||||
for def, action := range actions {
|
||||
if err := op.Validate(def); err == nil {
|
||||
@ -108,6 +109,26 @@ func (op *Op) Validate(defs ...string) error {
|
||||
return op.v.Validate(defs...)
|
||||
}
|
||||
|
||||
func (op *Op) Subdir(ctx context.Context, fs FS, out *Fillable) (FS, error) {
|
||||
// FIXME: this could be more optimized by carrying subdir path as metadata,
|
||||
// and using it in copy, load or mount.
|
||||
|
||||
dir, err := op.Get("dir").String()
|
||||
if err != nil {
|
||||
return fs, err
|
||||
}
|
||||
return fs.Change(func(st llb.State) llb.State {
|
||||
return st.File(llb.Copy(
|
||||
fs.LLB(),
|
||||
dir,
|
||||
"/",
|
||||
&llb.CopyInfo{
|
||||
CopyDirContentsOnly: true,
|
||||
},
|
||||
))
|
||||
}), nil
|
||||
}
|
||||
|
||||
func (op *Op) Copy(ctx context.Context, fs FS, out *Fillable) (FS, error) {
|
||||
// Decode copy options
|
||||
src, err := op.Get("src").String()
|
||||
|
@ -55,7 +55,7 @@ package dagger
|
||||
#Script: [...#Op]
|
||||
|
||||
// One operation in a script
|
||||
#Op: #FetchContainer | #FetchGit | #Export | #Exec | #Local | #Copy | #Load
|
||||
#Op: #FetchContainer | #FetchGit | #Export | #Exec | #Local | #Copy | #Load | #Subdir
|
||||
|
||||
// Export a value from fs state to cue
|
||||
#Export: {
|
||||
@ -78,6 +78,11 @@ package dagger
|
||||
from: #Component | #Script
|
||||
}
|
||||
|
||||
#Subdir: {
|
||||
do: "subdir"
|
||||
dir: string | *"/"
|
||||
}
|
||||
|
||||
#Exec: {
|
||||
do: "exec"
|
||||
args: [...string]
|
||||
|
29
tests/subdir/simple/main.cue
Normal file
29
tests/subdir/simple/main.cue
Normal file
@ -0,0 +1,29 @@
|
||||
package main
|
||||
|
||||
hello: {
|
||||
string
|
||||
|
||||
#dagger: compute: [
|
||||
{
|
||||
do: "fetch-container"
|
||||
ref: "alpine"
|
||||
},
|
||||
{
|
||||
do: "exec"
|
||||
args: ["mkdir", "-p", "/tmp/foo"]
|
||||
},
|
||||
{
|
||||
do: "exec"
|
||||
args: ["sh", "-c", "echo -n world > /tmp/foo/hello"]
|
||||
},
|
||||
{
|
||||
do: "subdir"
|
||||
dir: "/tmp/foo"
|
||||
},
|
||||
{
|
||||
do: "export"
|
||||
source: "/hello"
|
||||
format: "string"
|
||||
},
|
||||
]
|
||||
}
|
@ -217,6 +217,11 @@ test::input() {
|
||||
}
|
||||
|
||||
|
||||
test::subdir() {
|
||||
test::one "Subdir: simple usage" --exit=0 --stdout='{"hello":"world"}' \
|
||||
"$dagger" "${DAGGER_BINARY_ARGS[@]}" compute "$d"/subdir/simple
|
||||
}
|
||||
|
||||
test::all(){
|
||||
local dagger="$1"
|
||||
|
||||
@ -231,6 +236,7 @@ test::all(){
|
||||
test::exec "$dagger"
|
||||
test::export "$dagger"
|
||||
test::input "$dagger"
|
||||
test::subdir "$dagger"
|
||||
}
|
||||
|
||||
case "${1:-all}" in
|
||||
|
Reference in New Issue
Block a user