mirror of
https://github.com/docker/compose.git
synced 2025-07-26 23:24:05 +02:00
Merge pull request #100 from gtardif/windows_grpc
Allow server to start on tcp port or if windows, named pipe rather than unix socket
This commit is contained in:
commit
2e8251fb2d
@ -2,7 +2,6 @@ package cmd
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"context"
|
"context"
|
||||||
"net"
|
|
||||||
|
|
||||||
"github.com/pkg/errors"
|
"github.com/pkg/errors"
|
||||||
"github.com/sirupsen/logrus"
|
"github.com/sirupsen/logrus"
|
||||||
@ -39,10 +38,12 @@ func ServeCommand() *cobra.Command {
|
|||||||
func runServe(ctx context.Context, opts serveOpts) error {
|
func runServe(ctx context.Context, opts serveOpts) error {
|
||||||
s := server.New()
|
s := server.New()
|
||||||
|
|
||||||
listener, err := net.Listen("unix", opts.address)
|
listener, err := server.CreateListener(opts.address)
|
||||||
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return errors.Wrap(err, "listen unix socket")
|
return errors.Wrap(err, "listen address "+opts.address)
|
||||||
}
|
}
|
||||||
|
|
||||||
// nolint errcheck
|
// nolint errcheck
|
||||||
defer listener.Close()
|
defer listener.Close()
|
||||||
|
|
||||||
|
2
go.mod
2
go.mod
@ -11,7 +11,7 @@ require (
|
|||||||
github.com/Azure/go-autorest/autorest/date v0.2.0
|
github.com/Azure/go-autorest/autorest/date v0.2.0
|
||||||
github.com/Azure/go-autorest/autorest/to v0.3.0
|
github.com/Azure/go-autorest/autorest/to v0.3.0
|
||||||
github.com/Azure/go-autorest/autorest/validation v0.2.0 // indirect
|
github.com/Azure/go-autorest/autorest/validation v0.2.0 // indirect
|
||||||
github.com/Microsoft/go-winio v0.4.14 // indirect
|
github.com/Microsoft/go-winio v0.4.14
|
||||||
github.com/buger/goterm v0.0.0-20200322175922-2f3e71b85129
|
github.com/buger/goterm v0.0.0-20200322175922-2f3e71b85129
|
||||||
github.com/compose-spec/compose-go v0.0.0-20200423124427-63dcf8c22cae
|
github.com/compose-spec/compose-go v0.0.0-20200423124427-63dcf8c22cae
|
||||||
github.com/containerd/console v1.0.0
|
github.com/containerd/console v1.0.0
|
||||||
|
@ -30,6 +30,8 @@ package server
|
|||||||
import (
|
import (
|
||||||
"context"
|
"context"
|
||||||
"errors"
|
"errors"
|
||||||
|
"net"
|
||||||
|
"strings"
|
||||||
|
|
||||||
grpc_prometheus "github.com/grpc-ecosystem/go-grpc-prometheus"
|
grpc_prometheus "github.com/grpc-ecosystem/go-grpc-prometheus"
|
||||||
"google.golang.org/grpc"
|
"google.golang.org/grpc"
|
||||||
@ -57,6 +59,15 @@ func New() *grpc.Server {
|
|||||||
return s
|
return s
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
//CreateListener creates a listener either on tcp://, or local listener, supporting unix:// for unix socket or npipe:// for named pipes on windows
|
||||||
|
func CreateListener(address string) (net.Listener, error) {
|
||||||
|
if strings.HasPrefix(address, "tcp://") {
|
||||||
|
return net.Listen("tcp", strings.TrimPrefix(address, "tcp://"))
|
||||||
|
}
|
||||||
|
return createLocalListener(address)
|
||||||
|
}
|
||||||
|
|
||||||
func unary(ctx context.Context, req interface{}, info *grpc.UnaryServerInfo, handler grpc.UnaryHandler) (resp interface{}, err error) {
|
func unary(ctx context.Context, req interface{}, info *grpc.UnaryServerInfo, handler grpc.UnaryHandler) (resp interface{}, err error) {
|
||||||
return grpc_prometheus.UnaryServerInterceptor(ctx, req, info, handler)
|
return grpc_prometheus.UnaryServerInterceptor(ctx, req, info, handler)
|
||||||
}
|
}
|
||||||
|
16
server/socket_unix.go
Normal file
16
server/socket_unix.go
Normal file
@ -0,0 +1,16 @@
|
|||||||
|
// +build !windows
|
||||||
|
|
||||||
|
package server
|
||||||
|
|
||||||
|
import (
|
||||||
|
"errors"
|
||||||
|
"net"
|
||||||
|
"strings"
|
||||||
|
)
|
||||||
|
|
||||||
|
func createLocalListener(address string) (net.Listener, error) {
|
||||||
|
if !strings.HasPrefix(address, "unix://") {
|
||||||
|
return nil, errors.New("Cannot parse address, must start with unix:// or tcp:// : " + address)
|
||||||
|
}
|
||||||
|
return net.Listen("unix", strings.TrimPrefix(address, "unix://"))
|
||||||
|
}
|
22
server/socket_windows.go
Normal file
22
server/socket_windows.go
Normal file
@ -0,0 +1,22 @@
|
|||||||
|
// +build windows
|
||||||
|
|
||||||
|
package server
|
||||||
|
|
||||||
|
import (
|
||||||
|
"errors"
|
||||||
|
"net"
|
||||||
|
"strings"
|
||||||
|
|
||||||
|
"github.com/Microsoft/go-winio"
|
||||||
|
)
|
||||||
|
|
||||||
|
func createLocalListener(address string) (net.Listener, error) {
|
||||||
|
if !strings.HasPrefix(address, "npipe://") {
|
||||||
|
return nil, errors.New("Cannot parse address, must start with npipe:// or tcp:// : " + address)
|
||||||
|
}
|
||||||
|
return winio.ListenPipe(strings.TrimPrefix(address, "npipe://"), &winio.PipeConfig{
|
||||||
|
MessageMode: true, // Use message mode so that CloseWrite() is supported
|
||||||
|
InputBufferSize: 65536, // Use 64KB buffers to improve performance
|
||||||
|
OutputBufferSize: 65536,
|
||||||
|
})
|
||||||
|
}
|
@ -46,7 +46,7 @@ func NewCommand(command string, args ...string) *CmdContext {
|
|||||||
|
|
||||||
func dockerExecutable() string {
|
func dockerExecutable() string {
|
||||||
if runtime.GOOS == "windows" {
|
if runtime.GOOS == "windows" {
|
||||||
return "./bin/windows/docker.exe"
|
return "./bin/docker.exe"
|
||||||
}
|
}
|
||||||
return "./bin/docker"
|
return "./bin/docker"
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user