implemented services unix and npipe complete with test

Signed-off-by: Richard Jones <richard@dagger.io>
This commit is contained in:
Richard Jones
2021-12-10 16:06:14 -07:00
parent ba984c4d03
commit 2569e76eeb
4 changed files with 79 additions and 2 deletions

45
plan/task/service.go Normal file
View File

@@ -0,0 +1,45 @@
package task
import (
"context"
"errors"
"cuelang.org/go/cue"
"github.com/rs/zerolog/log"
"go.dagger.io/dagger/compiler"
"go.dagger.io/dagger/plancontext"
"go.dagger.io/dagger/solver"
)
func init() {
Register("Service", func() Task { return &serviceTask{} })
}
type serviceTask struct {
}
func (c serviceTask) Run(ctx context.Context, pctx *plancontext.Context, s solver.Solver, v *compiler.Value) (*compiler.Value, error) {
unix, _ := v.LookupPath(cue.ParsePath("unix")).String()
npipe, _ := v.LookupPath(cue.ParsePath("npipe")).String()
if unix == "" && npipe == "" {
return nil, errors.New("invalid service")
}
lg := log.Ctx(ctx).Debug()
if unix != "" {
lg.Str("unix", unix)
} else if npipe != "" {
lg.Str("npipe", npipe)
}
lg.Msg("loading service")
service := pctx.Services.New(unix, npipe)
out := compiler.NewValue()
if err := out.FillPath(cue.ParsePath("service"), service.MarshalCUE()); err != nil {
return nil, err
}
return out, nil
}