This repository has been archived on 2024-04-08. You can view files and clone it, but cannot push or open issues or pull requests.
dagger/plan/task/import.go

38 lines
760 B
Go
Raw Normal View History

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,
))
}