implemented "write-file" and "mkdir" ops
Signed-off-by: Sam Alba <sam.alba@gmail.com>
This commit is contained in:
parent
f76e43d512
commit
ee7bb3c3f5
@ -92,6 +92,11 @@ func (v *Value) String() (string, error) {
|
||||
return v.val.String()
|
||||
}
|
||||
|
||||
// Proxy function to the underlying cue.Value
|
||||
func (v *Value) Int64() (int64, error) {
|
||||
return v.val.Int64()
|
||||
}
|
||||
|
||||
func (v *Value) SourceUnsafe() string {
|
||||
s, _ := v.SourceString()
|
||||
return s
|
||||
|
@ -5,6 +5,7 @@ import (
|
||||
"encoding/json"
|
||||
"errors"
|
||||
"fmt"
|
||||
"io/fs"
|
||||
"strings"
|
||||
|
||||
"github.com/docker/distribution/reference"
|
||||
@ -167,6 +168,10 @@ func (p *Pipeline) doOp(ctx context.Context, op *compiler.Value) error {
|
||||
return p.Subdir(ctx, op)
|
||||
case "docker-build":
|
||||
return p.DockerBuild(ctx, op)
|
||||
case "write-file":
|
||||
return p.WriteFile(ctx, op)
|
||||
case "mkdir":
|
||||
return p.Mkdir(ctx, op)
|
||||
default:
|
||||
return fmt.Errorf("invalid operation: %s", op.JSON())
|
||||
}
|
||||
@ -679,3 +684,55 @@ func (p *Pipeline) DockerBuild(ctx context.Context, op *compiler.Value) error {
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
func (p *Pipeline) WriteFile(ctx context.Context, op *compiler.Value) error {
|
||||
content, err := op.Get("content").String()
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
dest, err := op.Get("dest").String()
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
mode, err := op.Get("mode").Int64()
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
p.fs = p.fs.Change(func(st llb.State) llb.State {
|
||||
return st.File(
|
||||
llb.Mkfile(dest, fs.FileMode(mode), []byte(content)),
|
||||
llb.WithCustomName(p.vertexNamef("WriteFile %s", dest)),
|
||||
)
|
||||
})
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
func (p *Pipeline) Mkdir(ctx context.Context, op *compiler.Value) error {
|
||||
path, err := op.Get("path").String()
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
dir, err := op.Get("dir").String()
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
mode, err := op.Get("mode").Int64()
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
p.fs = p.fs.Change(func(st llb.State) llb.State {
|
||||
return st.Dir(dir).File(
|
||||
llb.Mkdir(path, fs.FileMode(mode)),
|
||||
llb.WithCustomName(p.vertexNamef("Mkdir %s", path)),
|
||||
)
|
||||
})
|
||||
|
||||
return nil
|
||||
}
|
||||
|
@ -71,3 +71,17 @@ package dagger
|
||||
buildArg?: [string]: string
|
||||
label?: [string]: string
|
||||
}
|
||||
|
||||
#WriteFile: {
|
||||
do: "write-file"
|
||||
content: string
|
||||
dest: string
|
||||
mode: int | *0o644
|
||||
}
|
||||
|
||||
#Mkdir: {
|
||||
do: "mkdir"
|
||||
dir: *"/" | string
|
||||
path: string
|
||||
mode: int | *0o755
|
||||
}
|
||||
|
Reference in New Issue
Block a user