{do:"subdir"} to select a subdirectory in a script

Signed-off-by: Solomon Hykes <sh.github.6811@hykes.org>
This commit is contained in:
Solomon Hykes
2021-02-04 19:38:05 +00:00
parent 0202f4447b
commit 622de21883
5 changed files with 68 additions and 2 deletions

View File

@@ -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]

View File

@@ -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()

View File

@@ -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]