From e25646bbc039d5b428be77a7bf9742279fec9180 Mon Sep 17 00:00:00 2001 From: Paul Kehrer Date: Thu, 18 Aug 2016 16:35:23 +0800 Subject: [PATCH] Add support for compressing build context during image build When sending a build context to a remote server it may be (significantly) advantageous to compress the build context. This commit adds support for gz compression when constructing a build context using a command like "docker build --compress ." Signed-off-by: Paul Kehrer --- command/image/build.go | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/command/image/build.go b/command/image/build.go index 51d0ea9f08..2bd80f7082 100644 --- a/command/image/build.go +++ b/command/image/build.go @@ -56,6 +56,7 @@ type buildOptions struct { forceRm bool pull bool cacheFrom []string + compress bool } // NewBuildCommand creates a new `docker build` command @@ -100,6 +101,7 @@ func NewBuildCommand(dockerCli *command.DockerCli) *cobra.Command { flags.BoolVarP(&options.quiet, "quiet", "q", false, "Suppress the build output and print image ID on success") flags.BoolVar(&options.pull, "pull", false, "Always attempt to pull a newer version of the image") flags.StringSliceVar(&options.cacheFrom, "cache-from", []string{}, "Images to consider as cache sources") + flags.BoolVar(&options.compress, "compress", false, "Compress the build context using gzip") command.AddTrustedFlags(flags, true) @@ -208,8 +210,12 @@ func runBuild(dockerCli *command.DockerCli, options buildOptions) error { includes = append(includes, ".dockerignore", relDockerfile) } + compression := archive.Uncompressed + if options.compress { + compression = archive.Gzip + } buildCtx, err = archive.TarWithOptions(contextDir, &archive.TarOptions{ - Compression: archive.Uncompressed, + Compression: compression, ExcludePatterns: excludes, IncludeFiles: includes, })