engine: Task PreRun Hook
Tasks now have a PreRun hook that gets called before buildkit kicks in. Allows to support local access without special casing. Signed-off-by: Andrea Luzzardi <aluzzardi@gmail.com>
This commit is contained in:
@@ -2,6 +2,9 @@ package task
|
||||
|
||||
import (
|
||||
"context"
|
||||
"errors"
|
||||
"fmt"
|
||||
"os"
|
||||
|
||||
"github.com/moby/buildkit/client/llb"
|
||||
"github.com/rs/zerolog/log"
|
||||
@@ -17,6 +20,20 @@ func init() {
|
||||
type inputDirectoryTask struct {
|
||||
}
|
||||
|
||||
func (c *inputDirectoryTask) PreRun(ctx context.Context, pctx *plancontext.Context, v *compiler.Value) error {
|
||||
path, err := v.Lookup("path").AbsPath()
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
if _, err := os.Stat(path); errors.Is(err, os.ErrNotExist) {
|
||||
return fmt.Errorf("path %q does not exist", path)
|
||||
}
|
||||
pctx.LocalDirs.Add(path)
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
func (c *inputDirectoryTask) Run(ctx context.Context, pctx *plancontext.Context, s solver.Solver, v *compiler.Value) (*compiler.Value, error) {
|
||||
path, err := v.Lookup("path").AbsPath()
|
||||
if err != nil {
|
||||
|
@@ -29,6 +29,12 @@ type Task interface {
|
||||
Run(ctx context.Context, pctx *plancontext.Context, s solver.Solver, v *compiler.Value) (*compiler.Value, error)
|
||||
}
|
||||
|
||||
type PreRunner interface {
|
||||
Task
|
||||
|
||||
PreRun(ctx context.Context, pctx *plancontext.Context, v *compiler.Value) error
|
||||
}
|
||||
|
||||
// Register a task type and initializer
|
||||
func Register(typ string, f NewFunc) {
|
||||
tasks.Store(typ, f)
|
||||
|
Reference in New Issue
Block a user