runtime: support for context imports

Signed-off-by: Andrea Luzzardi <aluzzardi@gmail.com>
This commit is contained in:
Andrea Luzzardi 2021-11-24 16:24:04 -08:00
parent 608f254449
commit 131551f9cd

37
plan/task/import.go Normal file
View File

@ -0,0 +1,37 @@
package task
import (
"context"
"fmt"
"os"
"go.dagger.io/dagger/compiler"
"go.dagger.io/dagger/plancontext"
"go.dagger.io/dagger/solver"
)
func init() {
Register("Import", func() Task { return &importTask{} })
}
type importTask struct {
}
func (c importTask) Run(ctx context.Context, pctx *plancontext.Context, _ solver.Solver, v *compiler.Value) (*compiler.Value, error) {
var dir *plancontext.Directory
if err := v.Decode(&dir); err != nil {
return nil, err
}
// Check that directory exists
if _, err := os.Stat(dir.Path); os.IsNotExist(err) {
return nil, fmt.Errorf("%q dir doesn't exist", dir.Path)
}
id := pctx.Directories.Register(dir)
return compiler.Compile("", fmt.Sprintf(
`fs: #up: [{do: "local", id: %q}]`,
id,
))
}