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 (
"encoding/json"
"fmt"
"io"
"io/ioutil"
"os"
"path/filepath"
@ -134,6 +135,9 @@ type BuilderOptions struct {
// specified, indicating that the shared, system-wide default policy
// should be used.
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.

View File

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

View File

@ -2,6 +2,7 @@ package main
import (
"fmt"
"os"
"github.com/containers/image/storage"
"github.com/containers/image/transports/alltransports"
@ -20,6 +21,10 @@ var (
Name: "signature-policy",
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"
commitCommand = cli.Command{
@ -55,6 +60,10 @@ func commitCmd(c *cli.Context) error {
if !c.IsSet("disable-compression") || !c.Bool("disable-compression") {
compress = archive.Gzip
}
quiet := false
if c.IsSet("quiet") {
quiet = c.Bool("quiet")
}
store, err := getStore(c)
if err != nil {
return err
@ -78,6 +87,9 @@ func commitCmd(c *cli.Context) error {
Compression: compress,
SignaturePolicyPath: signaturePolicy,
}
if !quiet {
options.ReportWriter = os.Stderr
}
err = builder.Commit(dest, options)
if err != nil {
return fmt.Errorf("error committing container %q to %q: %v", builder.Container, image, err)

View File

@ -2,6 +2,7 @@ package main
import (
"fmt"
"os"
"github.com/projectatomic/buildah"
"github.com/urfave/cli"
@ -37,6 +38,10 @@ var (
Name: "signature-policy",
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"
@ -91,6 +96,11 @@ func fromCmd(c *cli.Context) error {
signaturePolicy = c.String("signature-policy")
}
quiet := false
if c.IsSet("quiet") {
quiet = c.Bool("quiet")
}
store, err := getStore(c)
if err != nil {
return err
@ -103,6 +113,9 @@ func fromCmd(c *cli.Context) error {
Registry: registry,
SignaturePolicyPath: signaturePolicy,
}
if !quiet {
options.ReportWriter = os.Stderr
}
builder, err := buildah.NewBuilder(store, options)
if err != nil {

View File

@ -2,6 +2,7 @@ package buildah
import (
"fmt"
"io"
"github.com/containers/image/copy"
"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
// them.
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) {
@ -62,7 +66,7 @@ func (b *Builder) Commit(dest types.ImageReference, options CommitOptions) error
if err != nil {
return err
}
err = copy.Image(policyContext, dest, src, getCopyOptions())
err = copy.Image(policyContext, dest, src, getCopyOptions(options.ReportWriter))
switch dest.Transport().Name() {
case storage.Transport.Name():
tags, err := expandTags(options.AdditionalTags)

View File

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

View File

@ -287,6 +287,8 @@ return 1
--help
-h
--disable-compression
--quiet
-q
"
local options_with_args="
@ -329,6 +331,8 @@ return 1
-h
--pull
--pull-always
--quiet
-q
"
local options_with_args="
@ -522,6 +526,8 @@ return 1
-h
--pull
--pull-always
--quiet
-q
"
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
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
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
(frequently */etc/containers/policy.json*) is most often preferred.
**--quiet**
When writing the output image, suppress progress output.
## EXAMPLE
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
(frequently */etc/containers/policy.json*) is most often preferred.
**--quiet**
If an image needs to be pulled from the registry, suppress progress output.
## EXAMPLE
buildah from imagename --pull --registry "myregistry://"

View File

@ -87,6 +87,10 @@ type BuildOptions struct {
// specified, indicating that the shared, system-wide default policy
// should be used.
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
@ -115,6 +119,7 @@ type Executor struct {
volumes imagebuilder.VolumeSet
volumeCache map[string]string
volumeCacheInfo map[string]os.FileInfo
reportWriter io.Writer
}
func makeSystemContext(signaturePolicyPath string) *types.SystemContext {
@ -388,6 +393,7 @@ func NewExecutor(store storage.Store, options BuildOptions) (*Executor, error) {
log: options.Log,
out: options.Out,
err: options.Err,
reportWriter: options.ReportWriter,
}
if exec.err == nil {
exec.err = os.Stderr
@ -427,6 +433,7 @@ func (b *Executor) Prepare(ib *imagebuilder.Builder, node *parser.Node, from str
PullPolicy: b.pullPolicy,
Registry: b.registry,
SignaturePolicyPath: b.signaturePolicyPath,
ReportWriter: b.reportWriter,
}
builder, err := buildah.NewBuilder(b.store, builderOptions)
if err != nil {
@ -526,6 +533,7 @@ func (b *Executor) Commit(ib *imagebuilder.Builder) (err error) {
Compression: b.compression,
SignaturePolicyPath: b.signaturePolicyPath,
AdditionalTags: b.additionalTags,
ReportWriter: b.reportWriter,
}
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)
err = copy.Image(policyContext, destRef, srcRef, getCopyOptions())
err = copy.Image(policyContext, destRef, srcRef, getCopyOptions(options.ReportWriter))
return err
}