Merge pull request #1204 from talentedmrjones/europa-services-unix

EUROPA: services unix and npipe
This commit is contained in:
Richard Jones 2021-12-15 11:05:28 -07:00 committed by GitHub
commit 645642ee83
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
8 changed files with 229 additions and 3 deletions

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

@ -0,0 +1,58 @@
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) {
var unix, npipe string
var stringErr error
unixV := v.Lookup("unix")
npipeV := v.Lookup("npipe")
if unixV.Exists() && unixV.IsConcrete() {
unix, stringErr = unixV.String()
}
if npipeV.Exists() && npipeV.IsConcrete() {
npipe, stringErr = npipeV.String()
}
if stringErr != nil {
return nil, stringErr
}
if unix == "" && npipe == "" {
return nil, errors.New("invalid service")
}
lg := log.Ctx(ctx)
if unix != "" {
lg.Debug().Str("unix", unix).Msg("loading service")
} else if npipe != "" {
lg.Debug().Str("npipe", npipe).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
}

View File

@ -38,4 +38,14 @@ package engine
envvar: string envvar: string
} }
} }
services: [string]: {
service: #Service
_type: "Service"
{
unix: string
} | {
npipe: string
}
}
} }

View File

@ -4,9 +4,37 @@ setup() {
common_setup common_setup
} }
@test "plan: hello" { @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 # Europa loader handles the cwd differently, therefore we need to CD into the tree at or below the parent of cue.mod
cd "$TESTDIR" cd "$TESTDIR"
run "$DAGGER" --europa up ./plan/hello-europa "$DAGGER" --europa up ./plan/hello-europa
assert_success }
@test "plan/context/services invalid schema" {
cd "$TESTDIR"
run "$DAGGER" --europa up ./plan/context/services/invalid_schema.cue
assert_failure
}
@test "plan/context/services invalid value" {
cd "$TESTDIR"
run "$DAGGER" --europa up ./plan/context/services/invalid_value.cue
assert_failure
}
@test "plan/context/services incomplete unix" {
cd "$TESTDIR"
run "$DAGGER" --europa up ./plan/context/services/incomplete_unix.cue
assert_failure
}
@test "plan/context/services incomplete service" {
cd "$TESTDIR"
run "$DAGGER" --europa up ./plan/context/services/incomplete_service.cue
assert_output --partial "pipeline was partially executed because of missing inputs"
}
@test "plan/context/services unix" {
cd "$TESTDIR"
"$DAGGER" --europa up ./plan/context/services/unix.cue
} }

View File

@ -0,0 +1,26 @@
package main
import (
"alpha.dagger.io/europa/dagger/engine"
"alpha.dagger.io/dagger/op"
"alpha.dagger.io/alpine"
)
engine.#Plan & {
// should fail
context: services: dockerSocket: {}
actions: test: #up: [
op.#Load & {
from: alpine.#Image & {
package: "docker-cli": true
}
},
op.#Exec & {
always: true
mount: "/var/run/docker.sock": stream: context.services.dockerSocket.service
args: ["docker", "info"]
},
]
}

View File

@ -0,0 +1,26 @@
package main
import (
"alpha.dagger.io/europa/dagger/engine"
"alpha.dagger.io/dagger/op"
"alpha.dagger.io/alpine"
)
engine.#Plan & {
// should succeed
context: services: dockerSocket: unix: string
actions: test: #up: [
op.#Load & {
from: alpine.#Image & {
package: "docker-cli": true
}
},
op.#Exec & {
always: true
mount: "/var/run/docker.sock": stream: context.services.dockerSocket.service
args: ["docker", "info"]
},
]
}

View File

@ -0,0 +1,26 @@
package main
import (
"alpha.dagger.io/europa/dagger/engine"
"alpha.dagger.io/dagger/op"
"alpha.dagger.io/alpine"
)
engine.#Plan & {
// should fail because of misspelled key
context: services: dockerSocket: unx: "/var/run/docker.soc"
actions: test: #up: [
op.#Load & {
from: alpine.#Image & {
package: "docker-cli": true
}
},
op.#Exec & {
always: true
mount: "/var/run/docker.sock": stream: context.services.dockerSocket.service
args: ["docker", "info"]
},
]
}

View File

@ -0,0 +1,26 @@
package main
import (
"alpha.dagger.io/europa/dagger/engine"
"alpha.dagger.io/dagger/op"
"alpha.dagger.io/alpine"
)
engine.#Plan & {
// should fail because of misspelled value
context: services: dockerSocket: unix: "/var/run/docker.soc"
actions: test: #up: [
op.#Load & {
from: alpine.#Image & {
package: "docker-cli": true
}
},
op.#Exec & {
always: true
mount: "/var/run/docker.sock": stream: context.services.dockerSocket.service
args: ["docker", "info"]
},
]
}

View File

@ -0,0 +1,26 @@
package main
import (
"alpha.dagger.io/europa/dagger/engine"
"alpha.dagger.io/dagger/op"
"alpha.dagger.io/alpine"
)
engine.#Plan & {
// should succeed
context: services: dockerSocket: unix: "/var/run/docker.sock"
actions: test: #up: [
op.#Load & {
from: alpine.#Image & {
package: "docker-cli": true
}
},
op.#Exec & {
always: true
mount: "/var/run/docker.sock": stream: context.services.dockerSocket.service
args: ["docker", "info"]
},
]
}