diff --git a/Gopkg.lock b/Gopkg.lock index e79b16675..682af4ac9 100644 --- a/Gopkg.lock +++ b/Gopkg.lock @@ -70,7 +70,7 @@ [[projects]] branch = "master" - digest = "1:e63f820f5ef5e534ab26d187b4a68869a99881a5dae4bfa2bf3b3efc4d203502" + digest = "1:fe9f0979745e077233666427ffc0da58f2d0f323fbf91d0e53c72364e99167bd" name = "github.com/docker/docker" packages = [ "api", @@ -89,6 +89,7 @@ "api/types/time", "api/types/versions", "api/types/volume", + "builder/dockerignore", "client", "errdefs", "pkg/archive", @@ -726,6 +727,7 @@ "github.com/docker/docker/api/types/filters", "github.com/docker/docker/api/types/mount", "github.com/docker/docker/api/types/swarm", + "github.com/docker/docker/builder/dockerignore", "github.com/docker/docker/client", "github.com/docker/docker/pkg/archive", "github.com/docker/docker/pkg/stdcopy", @@ -737,6 +739,7 @@ "github.com/kelseyhightower/envconfig", "github.com/logrusorgru/aurora", "github.com/mesg-foundation/prefixer", + "github.com/mitchellh/go-homedir", "github.com/pkg/errors", "github.com/satori/go.uuid", "github.com/sirupsen/logrus", @@ -747,7 +750,6 @@ "github.com/stretchr/testify/require", "github.com/stvp/assert", "github.com/syndtr/goleveldb/leveldb", - "github.com/syndtr/goleveldb/leveldb/errors", "github.com/xeipuuv/gojsonschema", "golang.org/x/net/context", "google.golang.org/grpc", diff --git a/api/deploy_test.go b/api/deploy_test.go index c84271955..25f75505e 100644 --- a/api/deploy_test.go +++ b/api/deploy_test.go @@ -46,11 +46,6 @@ func TestDeployService(t *testing.T) { Type: DonePositive, }, <-statuses) - require.Equal(t, DeployStatus{ - Message: "[DEPRECATED] Please use .dockerignore instead of .mesgignore", - Type: DoneNegative, - }, <-statuses) - require.Equal(t, DeployStatus{ Message: "Building Docker image...", Type: Running, diff --git a/container/build.go b/container/build.go index d67a6b17b..1c1a3c241 100644 --- a/container/build.go +++ b/container/build.go @@ -6,10 +6,12 @@ import ( "errors" "fmt" "io/ioutil" + "os" "path/filepath" "strings" "github.com/docker/docker/api/types" + "github.com/docker/docker/builder/dockerignore" "github.com/docker/docker/pkg/archive" ) @@ -21,12 +23,11 @@ type BuildResponse struct { // Build builds a docker image. func (c *Container) Build(path string) (tag string, err error) { - excludeFiles := []string{} - // TODO: remove .mesgignore for a future release - for _, file := range []string{".mesgignore", ".dockerignore"} { - excludeFilesBytes, _ := ioutil.ReadFile(filepath.Join(path, file)) - excludeFiles = append(excludeFiles, strings.Fields(string(excludeFilesBytes))...) + excludeFiles, err := dockerignoreFiles(path) + if err != nil { + return "", err } + buildContext, err := archive.TarWithOptions(path, &archive.TarOptions{ Compression: archive.Gzip, ExcludePatterns: excludeFiles, @@ -46,6 +47,19 @@ func (c *Container) Build(path string) (tag string, err error) { return parseBuildResponse(response) } +// dockerignoreFiles reads exlcuded files from .dockerignore. +func dockerignoreFiles(path string) ([]string, error) { + f, err := os.Open(filepath.Join(path, ".dockerignore")) + if err != nil { + if os.IsNotExist(err) { + return nil, nil + } + return nil, err + } + defer f.Close() + return dockerignore.ReadAll(f) +} + func parseBuildResponse(response types.ImageBuildResponse) (tag string, err error) { lastOutput, err := extractLastOutputFromBuildResponse(response) if err != nil { diff --git a/service-test/task/.mesgignore b/service-test/task/.mesgignore deleted file mode 100644 index e69de29bb..000000000 diff --git a/service/service.go b/service/service.go index 258e708d0..a63d312b5 100644 --- a/service/service.go +++ b/service/service.go @@ -6,7 +6,6 @@ import ( "io" "io/ioutil" "os" - "path/filepath" "time" "github.com/cnf/structhash" @@ -95,9 +94,6 @@ func New(tarball io.Reader, options ...Option) (*Service, error) { if err := s.saveContext(tarball); err != nil { return nil, err } - if err := s.checkDeprecations(); err != nil { - return nil, err - } def, err := importer.From(s.tempPath) if err != nil { @@ -220,15 +216,6 @@ func (s *Service) deploy() error { return nil } -// checkDeprecations checks deprecated usages in service. -func (s *Service) checkDeprecations() error { - if _, err := os.Stat(filepath.Join(s.tempPath, ".mesgignore")); err == nil { - // TODO: remove for a future release - s.sendStatus("[DEPRECATED] Please use .dockerignore instead of .mesgignore", DDoneNegative) - } - return nil -} - // sendStatus sends a status message. func (s *Service) sendStatus(message string, typ DStatusType) { if s.statuses != nil { diff --git a/vendor/github.com/docker/docker/builder/dockerignore/dockerignore.go b/vendor/github.com/docker/docker/builder/dockerignore/dockerignore.go new file mode 100644 index 000000000..57f224afc --- /dev/null +++ b/vendor/github.com/docker/docker/builder/dockerignore/dockerignore.go @@ -0,0 +1,64 @@ +package dockerignore // import "github.com/docker/docker/builder/dockerignore" + +import ( + "bufio" + "bytes" + "fmt" + "io" + "path/filepath" + "strings" +) + +// ReadAll reads a .dockerignore file and returns the list of file patterns +// to ignore. Note this will trim whitespace from each line as well +// as use GO's "clean" func to get the shortest/cleanest path for each. +func ReadAll(reader io.Reader) ([]string, error) { + if reader == nil { + return nil, nil + } + + scanner := bufio.NewScanner(reader) + var excludes []string + currentLine := 0 + + utf8bom := []byte{0xEF, 0xBB, 0xBF} + for scanner.Scan() { + scannedBytes := scanner.Bytes() + // We trim UTF8 BOM + if currentLine == 0 { + scannedBytes = bytes.TrimPrefix(scannedBytes, utf8bom) + } + pattern := string(scannedBytes) + currentLine++ + // Lines starting with # (comments) are ignored before processing + if strings.HasPrefix(pattern, "#") { + continue + } + pattern = strings.TrimSpace(pattern) + if pattern == "" { + continue + } + // normalize absolute paths to paths relative to the context + // (taking care of '!' prefix) + invert := pattern[0] == '!' + if invert { + pattern = strings.TrimSpace(pattern[1:]) + } + if len(pattern) > 0 { + pattern = filepath.Clean(pattern) + pattern = filepath.ToSlash(pattern) + if len(pattern) > 1 && pattern[0] == '/' { + pattern = pattern[1:] + } + } + if invert { + pattern = "!" + pattern + } + + excludes = append(excludes, pattern) + } + if err := scanner.Err(); err != nil { + return nil, fmt.Errorf("Error reading .dockerignore: %v", err) + } + return excludes, nil +}