Move connecting socket to client: network
Signed-off-by: Helder Correia <174525+helderco@users.noreply.github.com>
This commit is contained in:
parent
75a3ae4204
commit
d771699df9
@ -7,7 +7,7 @@ import (
|
|||||||
)
|
)
|
||||||
|
|
||||||
dagger.#Plan & {
|
dagger.#Plan & {
|
||||||
client: filesystem: "/var/run/docker.sock": read: contents: dagger.#Socket
|
client: network: "unix:///var/run/docker.sock": connect: dagger.#Socket
|
||||||
|
|
||||||
actions: {
|
actions: {
|
||||||
build: docker.#Build & {
|
build: docker.#Build & {
|
||||||
@ -16,7 +16,7 @@ dagger.#Plan & {
|
|||||||
|
|
||||||
load: cli.#Load & {
|
load: cli.#Load & {
|
||||||
image: build.output
|
image: build.output
|
||||||
host: client.filesystem."/var/run/docker.sock".read.contents
|
host: client.network."unix:///var/run/docker.sock".connect
|
||||||
tag: "myimage"
|
tag: "myimage"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -6,10 +6,10 @@ import (
|
|||||||
)
|
)
|
||||||
|
|
||||||
dagger.#Plan & {
|
dagger.#Plan & {
|
||||||
client: filesystem: "/var/run/docker.sock": read: contents: dagger.#Socket
|
client: network: "unix:///var/run/docker.sock": connect: dagger.#Socket
|
||||||
|
|
||||||
actions: run: cli.#Run & {
|
actions: run: cli.#Run & {
|
||||||
host: client.filesystem."/var/run/docker.sock".read.contents
|
host: client.network."unix:///var/run/docker.sock".connect
|
||||||
command: name: "info"
|
command: name: "info"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1,5 +1,5 @@
|
|||||||
dagger.#Plan & {
|
dagger.#Plan & {
|
||||||
client: filesystem: "/var/run/docker.sock": read: contents: dagger.#Socket
|
client: network: "unix:///var/run/docker.sock": connect: dagger.#Socket
|
||||||
|
|
||||||
actions: {
|
actions: {
|
||||||
image: alpine.#Build & {
|
image: alpine.#Build & {
|
||||||
@ -9,7 +9,7 @@ dagger.#Plan & {
|
|||||||
input: image.output
|
input: image.output
|
||||||
mounts: docker: {
|
mounts: docker: {
|
||||||
dest: "/var/run/docker.sock"
|
dest: "/var/run/docker.sock"
|
||||||
contents: client.filesystem."/var/run/docker.sock".read.contents
|
contents: client.network."unix:///var/run/docker.sock".connect
|
||||||
}
|
}
|
||||||
command: {
|
command: {
|
||||||
name: "docker"
|
name: "docker"
|
||||||
|
@ -1,8 +1,5 @@
|
|||||||
dagger.#Plan & {
|
dagger.#Plan & {
|
||||||
client: filesystem: "//./pipe/docker_engine": read: {
|
client: network: "npipe:////./pipe/docker_engine": connect: dagger.#Socket
|
||||||
contents: dagger.#Socket
|
|
||||||
type: "npipe"
|
|
||||||
}
|
|
||||||
|
|
||||||
actions: {
|
actions: {
|
||||||
image: alpine.#Build & {
|
image: alpine.#Build & {
|
||||||
@ -12,7 +9,7 @@ dagger.#Plan & {
|
|||||||
input: image.output
|
input: image.output
|
||||||
mounts: docker: {
|
mounts: docker: {
|
||||||
dest: "/var/run/docker.sock"
|
dest: "/var/run/docker.sock"
|
||||||
contents: client.filesystem."//./pipe/docker_engine".read.contents
|
contents: client.network."npipe:////./pipe/docker_engine".connect
|
||||||
}
|
}
|
||||||
command: {
|
command: {
|
||||||
name: "docker"
|
name: "docker"
|
||||||
|
@ -23,6 +23,11 @@ package dagger
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Access client network endpoints
|
||||||
|
network: [address=#Address]: _#clientNetwork & {
|
||||||
|
"address": address
|
||||||
|
}
|
||||||
|
|
||||||
// Access client environment variables
|
// Access client environment variables
|
||||||
env: _#clientEnv
|
env: _#clientEnv
|
||||||
|
|
||||||
@ -65,13 +70,6 @@ _#clientFilesystemRead: {
|
|||||||
// Filename patterns to exclude
|
// Filename patterns to exclude
|
||||||
// Example: ["node_modules"]
|
// Example: ["node_modules"]
|
||||||
exclude?: [...string]
|
exclude?: [...string]
|
||||||
} | {
|
|
||||||
// CUE type defines expected content:
|
|
||||||
// #Socket: unix socket or npipe
|
|
||||||
contents: #Socket
|
|
||||||
|
|
||||||
// Type of service
|
|
||||||
type: *"unix" | "npipe"
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -93,6 +91,22 @@ _#clientFilesystemWrite: {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
_#clientNetwork: {
|
||||||
|
$dagger: task: _name: "ClientNetwork"
|
||||||
|
|
||||||
|
// URL to the socket
|
||||||
|
// Example: unix:///var/run/docker.sock
|
||||||
|
address: #Address
|
||||||
|
|
||||||
|
{
|
||||||
|
// unix socket or npipe
|
||||||
|
connect: #Socket
|
||||||
|
// } | {
|
||||||
|
// // FIXME: not yet implemented
|
||||||
|
// listen: #Socket
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
_#clientEnv: {
|
_#clientEnv: {
|
||||||
$dagger: task: _name: "ClientEnv"
|
$dagger: task: _name: "ClientEnv"
|
||||||
|
|
||||||
|
@ -34,4 +34,5 @@ package dagger
|
|||||||
}
|
}
|
||||||
|
|
||||||
// A network service address
|
// A network service address
|
||||||
#Address: string & =~"^(tcp://|unix://|udp://).*"
|
#Address: string & =~"^(unix://|npipe://).+"
|
||||||
|
// TODO: #Address: string & =~"^(tcp://|unix://|npipe://|udp://).+"
|
||||||
|
@ -10,7 +10,7 @@ import (
|
|||||||
)
|
)
|
||||||
|
|
||||||
dagger.#Plan & {
|
dagger.#Plan & {
|
||||||
client: filesystem: "/var/run/docker.sock": read: contents: dagger.#Socket
|
client: network: "unix:///var/run/docker.sock": connect: dagger.#Socket
|
||||||
|
|
||||||
actions: test: {
|
actions: test: {
|
||||||
_cli: alpine.#Build & {
|
_cli: alpine.#Build & {
|
||||||
@ -30,14 +30,14 @@ dagger.#Plan & {
|
|||||||
|
|
||||||
load: cli.#Load & {
|
load: cli.#Load & {
|
||||||
image: _image.output
|
image: _image.output
|
||||||
host: client.filesystem."/var/run/docker.sock".read.contents
|
host: client.network."unix:///var/run/docker.sock".connect
|
||||||
tag: "dagger:load"
|
tag: "dagger:load"
|
||||||
}
|
}
|
||||||
|
|
||||||
verify: bash.#Run & {
|
verify: bash.#Run & {
|
||||||
input: _cli.output
|
input: _cli.output
|
||||||
mounts: docker: {
|
mounts: docker: {
|
||||||
contents: client.filesystem."/var/run/docker.sock".read.contents
|
contents: client.network."unix:///var/run/docker.sock".connect
|
||||||
dest: "/var/run/docker.sock"
|
dest: "/var/run/docker.sock"
|
||||||
}
|
}
|
||||||
env: {
|
env: {
|
||||||
|
@ -9,11 +9,11 @@ import (
|
|||||||
)
|
)
|
||||||
|
|
||||||
dagger.#Plan & {
|
dagger.#Plan & {
|
||||||
client: filesystem: "/var/run/docker.sock": read: contents: dagger.#Socket
|
client: network: "unix:///var/run/docker.sock": connect: dagger.#Socket
|
||||||
|
|
||||||
actions: test: {
|
actions: test: {
|
||||||
run: cli.#Run & {
|
run: cli.#Run & {
|
||||||
host: client.filesystem."/var/run/docker.sock".read.contents
|
host: client.network."unix:///var/run/docker.sock".connect
|
||||||
command: name: "info"
|
command: name: "info"
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -33,7 +33,7 @@ dagger.#Plan & {
|
|||||||
}
|
}
|
||||||
run: cli.#Run & {
|
run: cli.#Run & {
|
||||||
input: _cli.output
|
input: _cli.output
|
||||||
host: client.filesystem."/var/run/docker.sock".read.contents
|
host: client.network."unix:///var/run/docker.sock".connect
|
||||||
command: {
|
command: {
|
||||||
name: "docker"
|
name: "docker"
|
||||||
args: ["info"]
|
args: ["info"]
|
||||||
|
@ -79,11 +79,6 @@ func (t clientFilesystemReadTask) readContents(ctx context.Context, pctx *planco
|
|||||||
return t.readFS(ctx, pctx, s, v, path)
|
return t.readFS(ctx, pctx, s, v, path)
|
||||||
}
|
}
|
||||||
|
|
||||||
if plancontext.IsServiceValue(contents) {
|
|
||||||
lg.Debug().Str("path", path).Msg("loading local service")
|
|
||||||
return t.readService(pctx, v, path)
|
|
||||||
}
|
|
||||||
|
|
||||||
if plancontext.IsSecretValue(contents) {
|
if plancontext.IsSecretValue(contents) {
|
||||||
lg.Debug().Str("path", path).Msg("loading local secret file")
|
lg.Debug().Str("path", path).Msg("loading local secret file")
|
||||||
return t.readSecret(pctx, path)
|
return t.readSecret(pctx, path)
|
||||||
@ -156,27 +151,6 @@ func (t clientFilesystemReadTask) readFS(ctx context.Context, pctx *plancontext.
|
|||||||
return fs.MarshalCUE(), nil
|
return fs.MarshalCUE(), nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (t clientFilesystemReadTask) readService(pctx *plancontext.Context, v *compiler.Value, path string) (*compiler.Value, error) {
|
|
||||||
typ, err := v.Lookup("type").String()
|
|
||||||
if err != nil {
|
|
||||||
return nil, err
|
|
||||||
}
|
|
||||||
|
|
||||||
var unix, npipe string
|
|
||||||
|
|
||||||
switch typ {
|
|
||||||
case "unix":
|
|
||||||
unix = path
|
|
||||||
case "npipe":
|
|
||||||
npipe = path
|
|
||||||
default:
|
|
||||||
return nil, fmt.Errorf("invalid socket type %q", typ)
|
|
||||||
}
|
|
||||||
|
|
||||||
service := pctx.Services.New(unix, npipe)
|
|
||||||
return service.MarshalCUE(), nil
|
|
||||||
}
|
|
||||||
|
|
||||||
func (t clientFilesystemReadTask) readSecret(pctx *plancontext.Context, path string) (*compiler.Value, error) {
|
func (t clientFilesystemReadTask) readSecret(pctx *plancontext.Context, path string) (*compiler.Value, error) {
|
||||||
contents, err := t.readString(path)
|
contents, err := t.readString(path)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
64
plan/task/clientnetwork.go
Normal file
64
plan/task/clientnetwork.go
Normal file
@ -0,0 +1,64 @@
|
|||||||
|
package task
|
||||||
|
|
||||||
|
import (
|
||||||
|
"context"
|
||||||
|
"errors"
|
||||||
|
"fmt"
|
||||||
|
"net/url"
|
||||||
|
"os"
|
||||||
|
|
||||||
|
"github.com/rs/zerolog/log"
|
||||||
|
"go.dagger.io/dagger/compiler"
|
||||||
|
"go.dagger.io/dagger/plancontext"
|
||||||
|
"go.dagger.io/dagger/solver"
|
||||||
|
)
|
||||||
|
|
||||||
|
func init() {
|
||||||
|
Register("ClientNetwork", func() Task { return &clientNetwork{} })
|
||||||
|
}
|
||||||
|
|
||||||
|
type clientNetwork struct {
|
||||||
|
}
|
||||||
|
|
||||||
|
func (t clientNetwork) Run(ctx context.Context, pctx *plancontext.Context, s solver.Solver, v *compiler.Value) (*compiler.Value, error) {
|
||||||
|
lg := log.Ctx(ctx)
|
||||||
|
|
||||||
|
addr, err := v.Lookup("address").String()
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
|
||||||
|
u, err := url.Parse(addr)
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
|
||||||
|
lg.Debug().Str("type", u.Scheme).Str("path", u.Path).Msg("loading local socket")
|
||||||
|
|
||||||
|
if _, err := os.Stat(u.Path); errors.Is(err, os.ErrNotExist) {
|
||||||
|
return nil, fmt.Errorf("path %q does not exist", u.Path)
|
||||||
|
}
|
||||||
|
|
||||||
|
var unix, npipe string
|
||||||
|
|
||||||
|
switch u.Scheme {
|
||||||
|
case "unix":
|
||||||
|
unix = u.Path
|
||||||
|
case "npipe":
|
||||||
|
npipe = u.Path
|
||||||
|
default:
|
||||||
|
return nil, fmt.Errorf("invalid service type %q", u.Scheme)
|
||||||
|
}
|
||||||
|
|
||||||
|
connect := v.Lookup("connect")
|
||||||
|
|
||||||
|
if !plancontext.IsServiceValue(connect) {
|
||||||
|
return nil, fmt.Errorf("wrong type %q", connect.Kind())
|
||||||
|
}
|
||||||
|
|
||||||
|
service := pctx.Services.New(unix, npipe)
|
||||||
|
|
||||||
|
return compiler.NewValue().FillFields(map[string]interface{}{
|
||||||
|
"connect": service.MarshalCUE(),
|
||||||
|
})
|
||||||
|
}
|
@ -104,14 +104,6 @@ setup() {
|
|||||||
assert_output --partial "unexpected concrete value"
|
assert_output --partial "unexpected concrete value"
|
||||||
}
|
}
|
||||||
|
|
||||||
@test "plan/client/filesystem/read/service" {
|
|
||||||
cd "$TESTDIR"
|
|
||||||
"$DAGGER" "do" -p ./plan/client/filesystem/read/service/valid.cue test
|
|
||||||
|
|
||||||
run "$DAGGER" "do" -p ./plan/client/filesystem/read/service/invalid.cue test
|
|
||||||
assert_failure
|
|
||||||
}
|
|
||||||
|
|
||||||
@test "plan/client/filesystem/write fs" {
|
@test "plan/client/filesystem/write fs" {
|
||||||
cd "$TESTDIR/plan/client/filesystem/write"
|
cd "$TESTDIR/plan/client/filesystem/write"
|
||||||
|
|
||||||
@ -158,6 +150,14 @@ setup() {
|
|||||||
rm -f test.txt
|
rm -f test.txt
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@test "plan/client/network" {
|
||||||
|
cd "$TESTDIR"
|
||||||
|
"$DAGGER" "do" -p ./plan/client/network/valid.cue test
|
||||||
|
|
||||||
|
run "$DAGGER" "do" -p ./plan/client/network/invalid.cue test
|
||||||
|
assert_failure
|
||||||
|
}
|
||||||
|
|
||||||
@test "plan/client/env usage" {
|
@test "plan/client/env usage" {
|
||||||
cd "${TESTDIR}"
|
cd "${TESTDIR}"
|
||||||
|
|
||||||
|
@ -6,7 +6,7 @@ import (
|
|||||||
)
|
)
|
||||||
|
|
||||||
dagger.#Plan & {
|
dagger.#Plan & {
|
||||||
client: filesystem: "/var/run/docker.soc": read: contents: dagger.#Socket
|
client: network: "unix:///var/run/docker.soc": connect: dagger.#Socket
|
||||||
|
|
||||||
actions: {
|
actions: {
|
||||||
image: core.#Pull & {
|
image: core.#Pull & {
|
||||||
@ -22,7 +22,7 @@ dagger.#Plan & {
|
|||||||
input: imageWithDocker.output
|
input: imageWithDocker.output
|
||||||
mounts: docker: {
|
mounts: docker: {
|
||||||
dest: "/var/run/docker.sock"
|
dest: "/var/run/docker.sock"
|
||||||
contents: client.filesystem."/var/run/docker.soc".read.contents
|
contents: client.network."unix:///var/run/docker.soc".connect
|
||||||
}
|
}
|
||||||
args: ["docker", "info"]
|
args: ["docker", "info"]
|
||||||
}
|
}
|
@ -6,7 +6,7 @@ import (
|
|||||||
)
|
)
|
||||||
|
|
||||||
dagger.#Plan & {
|
dagger.#Plan & {
|
||||||
client: filesystem: "/var/run/docker.sock": read: contents: dagger.#Socket
|
client: network: "unix:///var/run/docker.sock": connect: dagger.#Socket
|
||||||
|
|
||||||
actions: {
|
actions: {
|
||||||
image: core.#Pull & {
|
image: core.#Pull & {
|
||||||
@ -22,7 +22,7 @@ dagger.#Plan & {
|
|||||||
input: imageWithDocker.output
|
input: imageWithDocker.output
|
||||||
mounts: docker: {
|
mounts: docker: {
|
||||||
dest: "/var/run/docker.sock"
|
dest: "/var/run/docker.sock"
|
||||||
contents: client.filesystem."/var/run/docker.sock".read.contents
|
contents: client.network."unix:///var/run/docker.sock".connect
|
||||||
}
|
}
|
||||||
args: ["docker", "info"]
|
args: ["docker", "info"]
|
||||||
}
|
}
|
@ -6,7 +6,7 @@ import (
|
|||||||
)
|
)
|
||||||
|
|
||||||
dagger.#Plan & {
|
dagger.#Plan & {
|
||||||
client: filesystem: "//./pipe/docker_engine": read: contents: dagger.#Socket
|
client: network: "npipe:////./pipe/docker_engine": connect: dagger.#Socket
|
||||||
|
|
||||||
actions: {
|
actions: {
|
||||||
image: core.#Pull & {
|
image: core.#Pull & {
|
||||||
@ -22,7 +22,7 @@ dagger.#Plan & {
|
|||||||
input: imageWithDocker.output
|
input: imageWithDocker.output
|
||||||
mounts: docker: {
|
mounts: docker: {
|
||||||
dest: "/var/run/docker.sock"
|
dest: "/var/run/docker.sock"
|
||||||
contents: client.filesystem."//./pipe/docker_engine".read.contents
|
contents: client.network."npipe:////./pipe/docker_engine".connect
|
||||||
}
|
}
|
||||||
args: ["docker", "info"]
|
args: ["docker", "info"]
|
||||||
}
|
}
|
@ -6,7 +6,7 @@ import (
|
|||||||
)
|
)
|
||||||
|
|
||||||
dagger.#Plan & {
|
dagger.#Plan & {
|
||||||
client: filesystem: "/var/run/docker.sock": read: contents: dagger.#Socket
|
client: network: "unix:///var/run/docker.sock": connect: dagger.#Socket
|
||||||
|
|
||||||
actions: {
|
actions: {
|
||||||
image: core.#Pull & {
|
image: core.#Pull & {
|
||||||
@ -22,7 +22,7 @@ dagger.#Plan & {
|
|||||||
input: imageWithDocker.output
|
input: imageWithDocker.output
|
||||||
mounts: docker: {
|
mounts: docker: {
|
||||||
dest: "/var/run/docker.sock"
|
dest: "/var/run/docker.sock"
|
||||||
contents: client.filesystem."/var/run/docker.sock".read.contents
|
contents: client.network."unix:///var/run/docker.sock".connect
|
||||||
}
|
}
|
||||||
args: ["docker", "info"]
|
args: ["docker", "info"]
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user