1
0
mirror of https://github.com/containers/buildah.git synced 2025-07-31 15:24:26 +03:00

Report pull/commit progress by default

Have 'from', 'commit', and 'build-using-dockerfile' report progress via
stderr (so that capturing output from 'from' and 'commit' still works as
expected) unless --quiet is used to suppress the reporting.

Closes #94.

Signed-off-by: Nalin Dahyabhai <nalin@redhat.com>

Closes: #98
Approved by: rhatdan
This commit is contained in:
Nalin Dahyabhai
2017-05-09 11:56:44 -04:00
committed by Atomic Bot
parent 6d03588e83
commit 12e582ee1a
12 changed files with 73 additions and 5 deletions

View File

@ -3,6 +3,7 @@ package buildah
import ( import (
"encoding/json" "encoding/json"
"fmt" "fmt"
"io"
"io/ioutil" "io/ioutil"
"os" "os"
"path/filepath" "path/filepath"
@ -134,6 +135,9 @@ type BuilderOptions struct {
// specified, indicating that the shared, system-wide default policy // specified, indicating that the shared, system-wide default policy
// should be used. // should be used.
SignaturePolicyPath string SignaturePolicyPath string
// ReportWriter is an io.Writer which will be used to log the reading
// of the source image from a registry, if we end up pulling the image.
ReportWriter io.Writer
} }
// ImportOptions are used to initialize a Builder. // ImportOptions are used to initialize a Builder.

View File

@ -15,7 +15,7 @@ var (
budFlags = []cli.Flag{ budFlags = []cli.Flag{
cli.BoolFlag{ cli.BoolFlag{
Name: "quiet, q", Name: "quiet, q",
Usage: "refrain from announcing build instructions", Usage: "refrain from announcing build instructions and image read/write progress",
}, },
cli.StringFlag{ cli.StringFlag{
Name: "registry", Name: "registry",
@ -203,6 +203,9 @@ func budCmd(c *cli.Context) error {
Runtime: runtime, Runtime: runtime,
RuntimeArgs: runtimeFlags, RuntimeArgs: runtimeFlags,
} }
if !quiet {
options.ReportWriter = os.Stderr
}
return imagebuildah.BuildDockerfiles(store, options, dockerfiles...) return imagebuildah.BuildDockerfiles(store, options, dockerfiles...)
} }

View File

@ -2,6 +2,7 @@ package main
import ( import (
"fmt" "fmt"
"os"
"github.com/containers/image/storage" "github.com/containers/image/storage"
"github.com/containers/image/transports/alltransports" "github.com/containers/image/transports/alltransports"
@ -20,6 +21,10 @@ var (
Name: "signature-policy", Name: "signature-policy",
Usage: "`pathname` of signature policy file (not usually used)", Usage: "`pathname` of signature policy file (not usually used)",
}, },
cli.BoolFlag{
Name: "quiet, q",
Usage: "don't output progress information when writing images",
},
} }
commitDescription = "Writes a new image using the container's read-write layer and, if it is based\n on an image, the layers of that image" commitDescription = "Writes a new image using the container's read-write layer and, if it is based\n on an image, the layers of that image"
commitCommand = cli.Command{ commitCommand = cli.Command{
@ -55,6 +60,10 @@ func commitCmd(c *cli.Context) error {
if !c.IsSet("disable-compression") || !c.Bool("disable-compression") { if !c.IsSet("disable-compression") || !c.Bool("disable-compression") {
compress = archive.Gzip compress = archive.Gzip
} }
quiet := false
if c.IsSet("quiet") {
quiet = c.Bool("quiet")
}
store, err := getStore(c) store, err := getStore(c)
if err != nil { if err != nil {
return err return err
@ -78,6 +87,9 @@ func commitCmd(c *cli.Context) error {
Compression: compress, Compression: compress,
SignaturePolicyPath: signaturePolicy, SignaturePolicyPath: signaturePolicy,
} }
if !quiet {
options.ReportWriter = os.Stderr
}
err = builder.Commit(dest, options) err = builder.Commit(dest, options)
if err != nil { if err != nil {
return fmt.Errorf("error committing container %q to %q: %v", builder.Container, image, err) return fmt.Errorf("error committing container %q to %q: %v", builder.Container, image, err)

View File

@ -2,6 +2,7 @@ package main
import ( import (
"fmt" "fmt"
"os"
"github.com/projectatomic/buildah" "github.com/projectatomic/buildah"
"github.com/urfave/cli" "github.com/urfave/cli"
@ -37,6 +38,10 @@ var (
Name: "signature-policy", Name: "signature-policy",
Usage: "`pathname` of signature policy file (not usually used)", Usage: "`pathname` of signature policy file (not usually used)",
}, },
cli.BoolFlag{
Name: "quiet, q",
Usage: "don't output progress information when pulling images",
},
} }
fromDescription = "Creates a new working container, either from scratch or using a specified\n image as a starting point" fromDescription = "Creates a new working container, either from scratch or using a specified\n image as a starting point"
@ -91,6 +96,11 @@ func fromCmd(c *cli.Context) error {
signaturePolicy = c.String("signature-policy") signaturePolicy = c.String("signature-policy")
} }
quiet := false
if c.IsSet("quiet") {
quiet = c.Bool("quiet")
}
store, err := getStore(c) store, err := getStore(c)
if err != nil { if err != nil {
return err return err
@ -103,6 +113,9 @@ func fromCmd(c *cli.Context) error {
Registry: registry, Registry: registry,
SignaturePolicyPath: signaturePolicy, SignaturePolicyPath: signaturePolicy,
} }
if !quiet {
options.ReportWriter = os.Stderr
}
builder, err := buildah.NewBuilder(store, options) builder, err := buildah.NewBuilder(store, options)
if err != nil { if err != nil {

View File

@ -2,6 +2,7 @@ package buildah
import ( import (
"fmt" "fmt"
"io"
"github.com/containers/image/copy" "github.com/containers/image/copy"
"github.com/containers/image/docker/reference" "github.com/containers/image/docker/reference"
@ -27,6 +28,9 @@ type CommitOptions struct {
// the transport to which we're writing the image gives us a way to add // the transport to which we're writing the image gives us a way to add
// them. // them.
AdditionalTags []string AdditionalTags []string
// ReportWriter is an io.Writer which will be used to log the writing
// of the new image.
ReportWriter io.Writer
} }
func expandTags(tags []string) ([]string, error) { func expandTags(tags []string) ([]string, error) {
@ -62,7 +66,7 @@ func (b *Builder) Commit(dest types.ImageReference, options CommitOptions) error
if err != nil { if err != nil {
return err return err
} }
err = copy.Image(policyContext, dest, src, getCopyOptions()) err = copy.Image(policyContext, dest, src, getCopyOptions(options.ReportWriter))
switch dest.Transport().Name() { switch dest.Transport().Name() {
case storage.Transport.Name(): case storage.Transport.Name():
tags, err := expandTags(options.AdditionalTags) tags, err := expandTags(options.AdditionalTags)

View File

@ -1,12 +1,16 @@
package buildah package buildah
import ( import (
"io"
"github.com/containers/image/copy" "github.com/containers/image/copy"
"github.com/containers/image/types" "github.com/containers/image/types"
) )
func getCopyOptions() *copy.Options { func getCopyOptions(reportWriter io.Writer) *copy.Options {
return &copy.Options{} return &copy.Options{
ReportWriter: reportWriter,
}
} }
func getSystemContext(signaturePolicyPath string) *types.SystemContext { func getSystemContext(signaturePolicyPath string) *types.SystemContext {

View File

@ -287,6 +287,8 @@ return 1
--help --help
-h -h
--disable-compression --disable-compression
--quiet
-q
" "
local options_with_args=" local options_with_args="
@ -329,6 +331,8 @@ return 1
-h -h
--pull --pull
--pull-always --pull-always
--quiet
-q
" "
local options_with_args=" local options_with_args="
@ -522,6 +526,8 @@ return 1
-h -h
--pull --pull
--pull-always --pull-always
--quiet
-q
" "
local options_with_args=" local options_with_args="

View File

@ -67,6 +67,12 @@ Adds global flags for the container rutime.
Specifies the name which will be assigned to the resulting image if the build Specifies the name which will be assigned to the resulting image if the build
process completes successfully. process completes successfully.
**--quiet**
Suppress output messages which indicate which instruction is being processed,
and of progress when pulling images from a registry, and when writing the
output image.
## EXAMPLE ## EXAMPLE
buildah bud . buildah bud .

View File

@ -23,6 +23,10 @@ Pathname of a signature policy file to use. It is not recommended that this
option be used, as the default behavior of using the system-wide default policy option be used, as the default behavior of using the system-wide default policy
(frequently */etc/containers/policy.json*) is most often preferred. (frequently */etc/containers/policy.json*) is most often preferred.
**--quiet**
When writing the output image, suppress progress output.
## EXAMPLE ## EXAMPLE
buildah commit containerID buildah commit containerID

View File

@ -40,6 +40,10 @@ Pathname of a signature policy file to use. It is not recommended that this
option be used, as the default behavior of using the system-wide default policy option be used, as the default behavior of using the system-wide default policy
(frequently */etc/containers/policy.json*) is most often preferred. (frequently */etc/containers/policy.json*) is most often preferred.
**--quiet**
If an image needs to be pulled from the registry, suppress progress output.
## EXAMPLE ## EXAMPLE
buildah from imagename --pull --registry "myregistry://" buildah from imagename --pull --registry "myregistry://"

View File

@ -87,6 +87,10 @@ type BuildOptions struct {
// specified, indicating that the shared, system-wide default policy // specified, indicating that the shared, system-wide default policy
// should be used. // should be used.
SignaturePolicyPath string SignaturePolicyPath string
// ReportWriter is an io.Writer which will be used to report the
// progress of the (possible) pulling of the source image and the
// writing of the new image.
ReportWriter io.Writer
} }
// Executor is a buildah-based implementation of the imagebuilder.Executor // Executor is a buildah-based implementation of the imagebuilder.Executor
@ -115,6 +119,7 @@ type Executor struct {
volumes imagebuilder.VolumeSet volumes imagebuilder.VolumeSet
volumeCache map[string]string volumeCache map[string]string
volumeCacheInfo map[string]os.FileInfo volumeCacheInfo map[string]os.FileInfo
reportWriter io.Writer
} }
func makeSystemContext(signaturePolicyPath string) *types.SystemContext { func makeSystemContext(signaturePolicyPath string) *types.SystemContext {
@ -388,6 +393,7 @@ func NewExecutor(store storage.Store, options BuildOptions) (*Executor, error) {
log: options.Log, log: options.Log,
out: options.Out, out: options.Out,
err: options.Err, err: options.Err,
reportWriter: options.ReportWriter,
} }
if exec.err == nil { if exec.err == nil {
exec.err = os.Stderr exec.err = os.Stderr
@ -427,6 +433,7 @@ func (b *Executor) Prepare(ib *imagebuilder.Builder, node *parser.Node, from str
PullPolicy: b.pullPolicy, PullPolicy: b.pullPolicy,
Registry: b.registry, Registry: b.registry,
SignaturePolicyPath: b.signaturePolicyPath, SignaturePolicyPath: b.signaturePolicyPath,
ReportWriter: b.reportWriter,
} }
builder, err := buildah.NewBuilder(b.store, builderOptions) builder, err := buildah.NewBuilder(b.store, builderOptions)
if err != nil { if err != nil {
@ -526,6 +533,7 @@ func (b *Executor) Commit(ib *imagebuilder.Builder) (err error) {
Compression: b.compression, Compression: b.compression,
SignaturePolicyPath: b.signaturePolicyPath, SignaturePolicyPath: b.signaturePolicyPath,
AdditionalTags: b.additionalTags, AdditionalTags: b.additionalTags,
ReportWriter: b.reportWriter,
} }
return b.builder.Commit(imageRef, options) return b.builder.Commit(imageRef, options)
} }

View File

@ -54,6 +54,6 @@ func pullImage(store storage.Store, options BuilderOptions, sc *types.SystemCont
logrus.Debugf("copying %q to %q", spec, name) logrus.Debugf("copying %q to %q", spec, name)
err = copy.Image(policyContext, destRef, srcRef, getCopyOptions()) err = copy.Image(policyContext, destRef, srcRef, getCopyOptions(options.ReportWriter))
return err return err
} }