diff --git a/commands/provider/service_deployer.go b/commands/provider/service_deployer.go index 2eff4001e..c308f0df1 100644 --- a/commands/provider/service_deployer.go +++ b/commands/provider/service_deployer.go @@ -3,9 +3,11 @@ package provider import ( "context" "errors" + "fmt" "io" "github.com/asaskevich/govalidator" + "github.com/docker/cli/cli/command/image/build" "github.com/docker/docker/pkg/archive" "github.com/mesg-foundation/core/protobuf/coreapi" ) @@ -77,8 +79,27 @@ func (p *ServiceProvider) ServiceDeploy(path string, env map[string]string, stat } func deployServiceSendServiceContext(path string, env map[string]string, stream coreapi.Core_DeployServiceClient) error { + contextDir, relDockerfile, err := build.GetContextFromLocalDir(path, build.DefaultDockerfileName) + if err != nil { + return err + } + + excludes, err := build.ReadDockerignore(contextDir) + if err != nil { + return err + } + + if err := build.ValidateContextDirectory(contextDir, excludes); err != nil { + return fmt.Errorf("error checking context: %s", err) + } + + // And canonicalize dockerfile name to a platform-independent one + relDockerfile = archive.CanonicalTarNameForPath(relDockerfile) + excludes = build.TrimBuildFilesFromExcludes(excludes, relDockerfile, false) + archive, err := archive.TarWithOptions(path, &archive.TarOptions{ - Compression: archive.Gzip, + Compression: archive.Gzip, + ExcludePatterns: excludes, }) if err != nil { return err diff --git a/go.mod b/go.mod index cc9e07ecf..0389f7c48 100644 --- a/go.mod +++ b/go.mod @@ -11,6 +11,7 @@ require ( github.com/briandowns/spinner v0.0.0-20180822135157-9f016caa1359 github.com/cnf/structhash v0.0.0-20180104161610-62a607eb0224 github.com/containerd/continuity v0.0.0-20180712174259-0377f7d76720 // indirect + github.com/docker/cli v0.0.0-20190129171106-b258f458cc8d github.com/docker/distribution v0.0.0-20180720172123-0dae0957e5fe // indirect github.com/docker/docker v0.0.0-20180803200506-eeea12db7a65 github.com/docker/go-connections v0.0.0-20180212134524-7beb39f0b969 // indirect diff --git a/go.sum b/go.sum index 654024ebe..166804edc 100644 --- a/go.sum +++ b/go.sum @@ -22,6 +22,8 @@ github.com/davecgh/go-spew v1.1.0 h1:ZDRjVQ15GmhC3fiQ8ni8+OwkZQO4DARzQgrnXU1Liz8 github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c= github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= +github.com/docker/cli v0.0.0-20190129171106-b258f458cc8d h1:n+Le3bCrmzFqx0uw8xOmQr4ZkDfRftw+8DuprUbKfps= +github.com/docker/cli v0.0.0-20190129171106-b258f458cc8d/go.mod h1:JLrzqnKDaYBop7H2jaqPtU4hHvMKP+vjCwu2uszcLI8= github.com/docker/distribution v0.0.0-20180720172123-0dae0957e5fe h1:ZRQNMB7Sw5jf9g/0imDbI+vTFNk4J7qBdtFI5/zf1kg= github.com/docker/distribution v0.0.0-20180720172123-0dae0957e5fe/go.mod h1:J2gT2udsDAN96Uj4KfcMRqY0/ypR+oyYUYmja8H+y+w= github.com/docker/docker v0.0.0-20180803200506-eeea12db7a65 h1:WeqSIzsb30/sarqEph9RS+6xw8rmRpCACwV8+cJ1Rkc=