diff --git a/plan/task/service.go b/plan/task/service.go new file mode 100644 index 00000000..09e31cb8 --- /dev/null +++ b/plan/task/service.go @@ -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 +} diff --git a/stdlib/europa/dagger/engine/plan.cue b/stdlib/europa/dagger/engine/plan.cue index 1d9b776e..a5ac386a 100644 --- a/stdlib/europa/dagger/engine/plan.cue +++ b/stdlib/europa/dagger/engine/plan.cue @@ -38,4 +38,14 @@ package engine envvar: string } } + + services: [string]: { + service: #Service + _type: "Service" + { + unix: string + } | { + npipe: string + } + } } diff --git a/tests/plan.bats b/tests/plan.bats index d2c16fd6..0f5c35cc 100644 --- a/tests/plan.bats +++ b/tests/plan.bats @@ -7,6 +7,12 @@ setup() { @test "plan: hello" { # Europa loader handles the cwd differently, therefore we need to CD into the tree at or below the parent of cue.mod cd "$TESTDIR" - run "$DAGGER" --europa up ./plan/hello-europa - assert_success + "$DAGGER" --europa up ./plan/hello-europa +} + +@test "plan: unix socket" { + cd "$TESTDIR" + "$DAGGER" --europa up ./plan/hello-europa + run curl http://localhost:8080 + assert_output --partial "Hello World" } \ No newline at end of file diff --git a/tests/plan/context/services/unix/main.cue b/tests/plan/context/services/unix/main.cue new file mode 100644 index 00000000..7c33e0a0 --- /dev/null +++ b/tests/plan/context/services/unix/main.cue @@ -0,0 +1,16 @@ +package main + +import ( + "alpha.dagger.io/dagger/engine" + "alpha.dagger.io/docker" +) + +engine.#Plan & { + context: services: dockerSocket: unix: "/var/run/docker.sock" + actions: nginx: docker.#Run & { + ref: "nginxdemos/nginx-hello" + name: "nginx-hello" + ports: ["8080:8080"] + socket: context.services.dockerSocket.service + } +}