Merge pull request #25837 from reaperhulk/support-compressing-build-context

Add support for compressing build context during image build
This commit is contained in:
Alexander Morozov 2016-10-05 12:57:46 -07:00 committed by GitHub
commit 8691f7c542
1 changed files with 7 additions and 1 deletions

View File

@ -56,6 +56,7 @@ type buildOptions struct {
forceRm bool forceRm bool
pull bool pull bool
cacheFrom []string cacheFrom []string
compress bool
} }
// NewBuildCommand creates a new `docker build` command // NewBuildCommand creates a new `docker build` command
@ -101,6 +102,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.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.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.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) command.AddTrustedFlags(flags, true)
@ -209,8 +211,12 @@ func runBuild(dockerCli *command.DockerCli, options buildOptions) error {
includes = append(includes, ".dockerignore", relDockerfile) includes = append(includes, ".dockerignore", relDockerfile)
} }
compression := archive.Uncompressed
if options.compress {
compression = archive.Gzip
}
buildCtx, err = archive.TarWithOptions(contextDir, &archive.TarOptions{ buildCtx, err = archive.TarWithOptions(contextDir, &archive.TarOptions{
Compression: archive.Uncompressed, Compression: compression,
ExcludePatterns: excludes, ExcludePatterns: excludes,
IncludeFiles: includes, IncludeFiles: includes,
}) })