소스 검색

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

Add support for compressing build context during image build
Alexander Morozov 8 년 전
부모
커밋
f08a450ad3
5개의 변경된 파일15개의 추가작업 그리고 2개의 파일을 삭제
  1. 7 1
      cli/command/image/build.go
  2. 2 1
      contrib/completion/bash/docker
  3. 1 0
      contrib/completion/zsh/_docker
  4. 1 0
      docs/reference/commandline/build.md
  5. 4 0
      man/docker-build.1.md

+ 7 - 1
cli/command/image/build.go

@@ -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,
 		})
 		})

+ 2 - 1
contrib/completion/bash/docker

@@ -758,6 +758,7 @@ _docker_build() {
 	"
 	"
 
 
 	local boolean_options="
 	local boolean_options="
+		--compress
 		--disable-content-trust=false
 		--disable-content-trust=false
 		--force-rm
 		--force-rm
 		--help
 		--help
@@ -1301,7 +1302,7 @@ _docker_info() {
 			return
 			return
 			;;
 			;;
 	esac
 	esac
-    
+
 	case "$cur" in
 	case "$cur" in
 		-*)
 		-*)
 			COMPREPLY=( $( compgen -W "--format -f --help" -- "$cur" ) )
 			COMPREPLY=( $( compgen -W "--format -f --help" -- "$cur" ) )

+ 1 - 0
contrib/completion/zsh/_docker

@@ -1509,6 +1509,7 @@ __docker_subcommand() {
                 $opts_build_create_run \
                 $opts_build_create_run \
                 $opts_build_create_run_update \
                 $opts_build_create_run_update \
                 "($help)*--build-arg[Build-time variables]:<varname>=<value>: " \
                 "($help)*--build-arg[Build-time variables]:<varname>=<value>: " \
+                "($help)--compress[Compress the build context using gzip]" \
                 "($help -f --file)"{-f=,--file=}"[Name of the Dockerfile]:Dockerfile:_files" \
                 "($help -f --file)"{-f=,--file=}"[Name of the Dockerfile]:Dockerfile:_files" \
                 "($help)--force-rm[Always remove intermediate containers]" \
                 "($help)--force-rm[Always remove intermediate containers]" \
                 "($help)*--label=[Set metadata for an image]:label=value: " \
                 "($help)*--label=[Set metadata for an image]:label=value: " \

+ 1 - 0
docs/reference/commandline/build.md

@@ -19,6 +19,7 @@ Options:
       --build-arg value         Set build-time variables (default [])
       --build-arg value         Set build-time variables (default [])
       --cache-from value        Images to consider as cache sources (default [])
       --cache-from value        Images to consider as cache sources (default [])
       --cgroup-parent string    Optional parent cgroup for the container
       --cgroup-parent string    Optional parent cgroup for the container
+      --compress                Compress the build context using gzip
       --cpu-period int          Limit the CPU CFS (Completely Fair Scheduler) period
       --cpu-period int          Limit the CPU CFS (Completely Fair Scheduler) period
       --cpu-quota int           Limit the CPU CFS (Completely Fair Scheduler) quota
       --cpu-quota int           Limit the CPU CFS (Completely Fair Scheduler) quota
   -c, --cpu-shares int          CPU shares (relative weight)
   -c, --cpu-shares int          CPU shares (relative weight)

+ 4 - 0
man/docker-build.1.md

@@ -16,6 +16,7 @@ docker-build - Build a new image from the source code at PATH
 [**--label**[=*[]*]]
 [**--label**[=*[]*]]
 [**--no-cache**]
 [**--no-cache**]
 [**--pull**]
 [**--pull**]
+[**--compress**]
 [**-q**|**--quiet**]
 [**-q**|**--quiet**]
 [**--rm**[=*true*]]
 [**--rm**[=*true*]]
 [**-t**|**--tag**[=*[]*]]
 [**-t**|**--tag**[=*[]*]]
@@ -84,6 +85,9 @@ set as the **URL**, the repository is cloned locally and then sent as the contex
 **--pull**=*true*|*false*
 **--pull**=*true*|*false*
    Always attempt to pull a newer version of the image. The default is *false*.
    Always attempt to pull a newer version of the image. The default is *false*.
 
 
+**--compress**=*true*|*false*
+    Compress the build context using gzip. The default is *false*.
+
 **-q**, **--quiet**=*true*|*false*
 **-q**, **--quiet**=*true*|*false*
    Suppress the build output and print image ID on success. The default is *false*.
    Suppress the build output and print image ID on success. The default is *false*.