From f2686beb35d51e4ef1187651b7debc501479360e Mon Sep 17 00:00:00 2001 From: krhubert Date: Wed, 30 Jan 2019 17:04:15 +0100 Subject: [PATCH] Read dockerignore in dev and deploy commands --- commands/provider/service_deployer.go | 23 ++++++++++++++++++++++- go.mod | 1 + go.sum | 2 ++ 3 files changed, 25 insertions(+), 1 deletion(-) diff --git a/commands/provider/service_deployer.go b/commands/provider/service_deployer.go index fe753d91b..23014bd12 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" ) @@ -73,8 +75,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 dcd51ac9e..02863b37d 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 f41c01848..c8e2e2449 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=