mirror of
https://github.com/containers/buildah.git
synced 2025-07-31 15:24:26 +03:00
Change functions that use a fmt.Errorf to wrap an err to error.Wrapf
Impove error reporting by wrapping all returned err functions with error.Wrapf Signed-off-by: Dan Walsh <dwalsh@redhat.com> Closes: #124 Approved by: nalind Signed-off-by: Dan Walsh <dwalsh@redhat.com> Closes: #125 Approved by: nalind
This commit is contained in:
27
add.go
27
add.go
@ -14,6 +14,7 @@ import (
|
||||
"github.com/Sirupsen/logrus"
|
||||
"github.com/containers/storage/pkg/archive"
|
||||
"github.com/containers/storage/pkg/chrootarchive"
|
||||
"github.com/pkg/errors"
|
||||
)
|
||||
|
||||
// addURL copies the contents of the source URL to the destination. This is
|
||||
@ -23,12 +24,12 @@ func addURL(destination, srcurl string) error {
|
||||
logrus.Debugf("saving %q to %q", srcurl, destination)
|
||||
resp, err := http.Get(srcurl)
|
||||
if err != nil {
|
||||
return fmt.Errorf("error getting %q: %v", srcurl, err)
|
||||
return errors.Wrapf(err, "error getting %q", srcurl)
|
||||
}
|
||||
defer resp.Body.Close()
|
||||
f, err := os.Create(destination)
|
||||
if err != nil {
|
||||
return fmt.Errorf("error creating %q: %v", destination, err)
|
||||
return errors.Wrapf(err, "error creating %q", destination)
|
||||
}
|
||||
if last := resp.Header.Get("Last-Modified"); last != "" {
|
||||
if mtime, err2 := time.Parse(time.RFC1123, last); err2 != nil {
|
||||
@ -44,13 +45,13 @@ func addURL(destination, srcurl string) error {
|
||||
defer f.Close()
|
||||
n, err := io.Copy(f, resp.Body)
|
||||
if err != nil {
|
||||
return fmt.Errorf("error reading contents for %q: %v", destination, err)
|
||||
return errors.Wrapf(err, "error reading contents for %q", destination)
|
||||
}
|
||||
if resp.ContentLength >= 0 && n != resp.ContentLength {
|
||||
return fmt.Errorf("error reading contents for %q: wrong length (%d != %d)", destination, n, resp.ContentLength)
|
||||
}
|
||||
if err := f.Chmod(0600); err != nil {
|
||||
return fmt.Errorf("error setting permissions on %q: %v", destination, err)
|
||||
return errors.Wrapf(err, "error setting permissions on %q", destination)
|
||||
}
|
||||
return nil
|
||||
}
|
||||
@ -73,7 +74,7 @@ func (b *Builder) Add(destination string, extract bool, source ...string) error
|
||||
dest = filepath.Join(dest, destination)
|
||||
} else {
|
||||
if err = os.MkdirAll(filepath.Join(dest, b.WorkDir()), 0755); err != nil {
|
||||
return fmt.Errorf("error ensuring directory %q exists: %v)", filepath.Join(dest, b.WorkDir()), err)
|
||||
return errors.Wrapf(err, "error ensuring directory %q exists)", filepath.Join(dest, b.WorkDir()))
|
||||
}
|
||||
dest = filepath.Join(dest, b.WorkDir(), destination)
|
||||
}
|
||||
@ -82,7 +83,7 @@ func (b *Builder) Add(destination string, extract bool, source ...string) error
|
||||
// and any files we're copying will be placed in the directory.
|
||||
if len(destination) > 0 && destination[len(destination)-1] == os.PathSeparator {
|
||||
if err = os.MkdirAll(dest, 0755); err != nil {
|
||||
return fmt.Errorf("error ensuring directory %q exists: %v)", dest, err)
|
||||
return errors.Wrapf(err, "error ensuring directory %q exists", dest)
|
||||
}
|
||||
}
|
||||
// Make sure the destination's parent directory is usable.
|
||||
@ -93,7 +94,7 @@ func (b *Builder) Add(destination string, extract bool, source ...string) error
|
||||
destfi, err := os.Stat(dest)
|
||||
if err != nil {
|
||||
if !os.IsNotExist(err) {
|
||||
return fmt.Errorf("couldn't determine what %q is: %v)", dest, err)
|
||||
return errors.Wrapf(err, "couldn't determine what %q is", dest)
|
||||
}
|
||||
destfi = nil
|
||||
}
|
||||
@ -109,7 +110,7 @@ func (b *Builder) Add(destination string, extract bool, source ...string) error
|
||||
// we'll save the contents.
|
||||
url, err := url.Parse(src)
|
||||
if err != nil {
|
||||
return fmt.Errorf("error parsing URL %q: %v", src, err)
|
||||
return errors.Wrapf(err, "error parsing URL %q", src)
|
||||
}
|
||||
d := dest
|
||||
if destfi != nil && destfi.IsDir() {
|
||||
@ -122,7 +123,7 @@ func (b *Builder) Add(destination string, extract bool, source ...string) error
|
||||
}
|
||||
srcfi, err := os.Stat(src)
|
||||
if err != nil {
|
||||
return fmt.Errorf("error reading %q: %v", src, err)
|
||||
return errors.Wrapf(err, "error reading %q", src)
|
||||
}
|
||||
if srcfi.IsDir() {
|
||||
// The source is a directory, so copy the contents of
|
||||
@ -131,11 +132,11 @@ func (b *Builder) Add(destination string, extract bool, source ...string) error
|
||||
// we'll discover why that won't work.
|
||||
d := dest
|
||||
if err := os.MkdirAll(d, 0755); err != nil {
|
||||
return fmt.Errorf("error ensuring directory %q exists: %v)", d, err)
|
||||
return errors.Wrapf(err, "error ensuring directory %q exists", d)
|
||||
}
|
||||
logrus.Debugf("copying %q to %q", src+string(os.PathSeparator)+"*", d+string(os.PathSeparator)+"*")
|
||||
if err := chrootarchive.CopyWithTar(src, d); err != nil {
|
||||
return fmt.Errorf("error copying %q to %q: %v", src, d, err)
|
||||
return errors.Wrapf(err, "error copying %q to %q", src, d)
|
||||
}
|
||||
continue
|
||||
}
|
||||
@ -150,14 +151,14 @@ func (b *Builder) Add(destination string, extract bool, source ...string) error
|
||||
// Copy the file, preserving attributes.
|
||||
logrus.Debugf("copying %q to %q", src, d)
|
||||
if err := chrootarchive.CopyFileWithTar(src, d); err != nil {
|
||||
return fmt.Errorf("error copying %q to %q: %v", src, d, err)
|
||||
return errors.Wrapf(err, "error copying %q to %q", src, d)
|
||||
}
|
||||
continue
|
||||
}
|
||||
// We're extracting an archive into the destination directory.
|
||||
logrus.Debugf("extracting contents of %q into %q", src, dest)
|
||||
if err := chrootarchive.UntarPath(src, dest); err != nil {
|
||||
return fmt.Errorf("error extracting %q into %q: %v", src, dest, err)
|
||||
return errors.Wrapf(err, "error extracting %q into %q", src, dest)
|
||||
}
|
||||
}
|
||||
return nil
|
||||
|
@ -3,6 +3,7 @@ package main
|
||||
import (
|
||||
"fmt"
|
||||
|
||||
"github.com/pkg/errors"
|
||||
"github.com/urfave/cli"
|
||||
)
|
||||
|
||||
@ -50,12 +51,12 @@ func addAndCopyCmd(c *cli.Context, extractLocalArchives bool) error {
|
||||
|
||||
builder, err := openBuilder(store, name)
|
||||
if err != nil {
|
||||
return fmt.Errorf("error reading build container %q: %v", name, err)
|
||||
return errors.Wrapf(err, "error reading build container %q", name)
|
||||
}
|
||||
|
||||
err = builder.Add(dest, extractLocalArchives, args...)
|
||||
if err != nil {
|
||||
return fmt.Errorf("error adding content to container %q: %v", builder.Container, err)
|
||||
return errors.Wrapf(err, "error adding content to container %q", builder.Container)
|
||||
}
|
||||
|
||||
return nil
|
||||
|
@ -7,6 +7,7 @@ import (
|
||||
"strings"
|
||||
|
||||
"github.com/Sirupsen/logrus"
|
||||
"github.com/pkg/errors"
|
||||
"github.com/projectatomic/buildah/imagebuildah"
|
||||
"github.com/urfave/cli"
|
||||
)
|
||||
@ -151,7 +152,7 @@ func budCmd(c *cli.Context) error {
|
||||
// The context directory could be a URL. Try to handle that.
|
||||
tempDir, subDir, err := imagebuildah.TempDirForURL("", "buildah", cliArgs[0])
|
||||
if err != nil {
|
||||
return fmt.Errorf("error prepping temporary context directory: %v", err)
|
||||
return errors.Wrapf(err, "error prepping temporary context directory")
|
||||
}
|
||||
if tempDir != "" {
|
||||
// We had to download it to a temporary directory.
|
||||
@ -166,7 +167,7 @@ func budCmd(c *cli.Context) error {
|
||||
// Nope, it was local. Use it as is.
|
||||
absDir, err := filepath.Abs(cliArgs[0])
|
||||
if err != nil {
|
||||
return fmt.Errorf("error determining path to directory %q: %v", cliArgs[0], err)
|
||||
return errors.Wrapf(err, "error determining path to directory %q", cliArgs[0])
|
||||
}
|
||||
contextDir = absDir
|
||||
}
|
||||
@ -183,12 +184,12 @@ func budCmd(c *cli.Context) error {
|
||||
}
|
||||
absFile, err := filepath.Abs(dockerfiles[i])
|
||||
if err != nil {
|
||||
return fmt.Errorf("error determining path to file %q: %v", dockerfiles[i], err)
|
||||
return errors.Wrapf(err, "error determining path to file %q", dockerfiles[i])
|
||||
}
|
||||
contextDir = filepath.Dir(absFile)
|
||||
dockerfiles[i], err = filepath.Rel(contextDir, absFile)
|
||||
if err != nil {
|
||||
return fmt.Errorf("error determining path to file %q: %v", dockerfiles[i], err)
|
||||
return errors.Wrapf(err, "error determining path to file %q", dockerfiles[i])
|
||||
}
|
||||
break
|
||||
}
|
||||
|
@ -8,6 +8,7 @@ import (
|
||||
"github.com/containers/image/storage"
|
||||
"github.com/containers/image/transports/alltransports"
|
||||
"github.com/containers/storage/pkg/archive"
|
||||
"github.com/pkg/errors"
|
||||
"github.com/projectatomic/buildah"
|
||||
"github.com/urfave/cli"
|
||||
)
|
||||
@ -87,14 +88,14 @@ func commitCmd(c *cli.Context) error {
|
||||
|
||||
builder, err := openBuilder(store, name)
|
||||
if err != nil {
|
||||
return fmt.Errorf("error reading build container %q: %v", name, err)
|
||||
return errors.Wrapf(err, "error reading build container %q", name)
|
||||
}
|
||||
|
||||
dest, err := alltransports.ParseImageName(image)
|
||||
if err != nil {
|
||||
dest2, err2 := storage.Transport.ParseStoreReference(store, image)
|
||||
if err2 != nil {
|
||||
return fmt.Errorf("error parsing target image name %q: %v", image, err)
|
||||
return errors.Wrapf(err, "error parsing target image name %q", image)
|
||||
}
|
||||
dest = dest2
|
||||
}
|
||||
@ -109,7 +110,7 @@ func commitCmd(c *cli.Context) error {
|
||||
}
|
||||
err = builder.Commit(dest, options)
|
||||
if err != nil {
|
||||
return fmt.Errorf("error committing container %q to %q: %v", builder.Container, image, err)
|
||||
return errors.Wrapf(err, "error committing container %q to %q", builder.Container, image)
|
||||
}
|
||||
|
||||
return nil
|
||||
|
@ -6,6 +6,7 @@ import (
|
||||
|
||||
is "github.com/containers/image/storage"
|
||||
"github.com/containers/storage"
|
||||
"github.com/pkg/errors"
|
||||
"github.com/projectatomic/buildah"
|
||||
"github.com/urfave/cli"
|
||||
)
|
||||
@ -46,7 +47,7 @@ func openBuilder(store storage.Store, name string) (builder *buildah.Builder, er
|
||||
}
|
||||
}
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("error reading build container: %v", err)
|
||||
return nil, errors.Wrapf(err, "error reading build container")
|
||||
}
|
||||
if builder == nil {
|
||||
return nil, fmt.Errorf("error finding build container")
|
||||
@ -64,7 +65,7 @@ func openImage(store storage.Store, name string) (builder *buildah.Builder, err
|
||||
}
|
||||
builder, err = buildah.ImportBuilderFromImage(store, options)
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("error reading image: %v", err)
|
||||
return nil, errors.Wrapf(err, "error reading image")
|
||||
}
|
||||
if builder == nil {
|
||||
return nil, fmt.Errorf("error mocking up build configuration")
|
||||
|
@ -6,6 +6,7 @@ import (
|
||||
|
||||
"github.com/Sirupsen/logrus"
|
||||
"github.com/mattn/go-shellwords"
|
||||
"github.com/pkg/errors"
|
||||
"github.com/projectatomic/buildah"
|
||||
"github.com/urfave/cli"
|
||||
)
|
||||
@ -179,7 +180,7 @@ func configCmd(c *cli.Context) error {
|
||||
|
||||
builder, err := openBuilder(store, name)
|
||||
if err != nil {
|
||||
return fmt.Errorf("error reading build container %q: %v", name, err)
|
||||
return errors.Wrapf(err, "error reading build container %q", name)
|
||||
}
|
||||
|
||||
updateConfig(builder, c)
|
||||
|
@ -3,6 +3,7 @@ package main
|
||||
import (
|
||||
"fmt"
|
||||
|
||||
"github.com/pkg/errors"
|
||||
"github.com/projectatomic/buildah"
|
||||
"github.com/urfave/cli"
|
||||
)
|
||||
@ -54,7 +55,7 @@ func containersCmd(c *cli.Context) error {
|
||||
|
||||
builders, err := openBuilders(store)
|
||||
if err != nil {
|
||||
return fmt.Errorf("error reading build containers: %v", err)
|
||||
return errors.Wrapf(err, "error reading build containers")
|
||||
}
|
||||
if len(builders) > 0 && !noheading && !quiet {
|
||||
if truncate {
|
||||
|
@ -3,6 +3,7 @@ package main
|
||||
import (
|
||||
"fmt"
|
||||
|
||||
"github.com/pkg/errors"
|
||||
"github.com/urfave/cli"
|
||||
)
|
||||
|
||||
@ -52,7 +53,7 @@ func imagesCmd(c *cli.Context) error {
|
||||
}
|
||||
images, err := store.Images()
|
||||
if err != nil {
|
||||
return fmt.Errorf("error reading images: %v", err)
|
||||
return errors.Wrapf(err, "error reading images")
|
||||
}
|
||||
|
||||
if len(images) > 0 && !noheading && !quiet {
|
||||
|
@ -6,6 +6,7 @@ import (
|
||||
"os"
|
||||
"text/template"
|
||||
|
||||
"github.com/pkg/errors"
|
||||
"github.com/projectatomic/buildah"
|
||||
"github.com/urfave/cli"
|
||||
)
|
||||
@ -81,12 +82,12 @@ func inspectCmd(c *cli.Context) error {
|
||||
case inspectTypeContainer:
|
||||
builder, err = openBuilder(store, name)
|
||||
if err != nil {
|
||||
return fmt.Errorf("error reading build container %q: %v", name, err)
|
||||
return errors.Wrapf(err, "error reading build container %q", name)
|
||||
}
|
||||
case inspectTypeImage:
|
||||
builder, err = openImage(store, name)
|
||||
if err != nil {
|
||||
return fmt.Errorf("error reading image %q: %v", name, err)
|
||||
return errors.Wrapf(err, "error reading image %q", name)
|
||||
}
|
||||
}
|
||||
|
||||
@ -96,7 +97,7 @@ func inspectCmd(c *cli.Context) error {
|
||||
|
||||
b, err := json.MarshalIndent(builder, "", " ")
|
||||
if err != nil {
|
||||
return fmt.Errorf("error encoding build container as json: %v", err)
|
||||
return errors.Wrapf(err, "error encoding build container as json")
|
||||
}
|
||||
_, err = fmt.Println(string(b))
|
||||
return err
|
||||
|
@ -3,6 +3,7 @@ package main
|
||||
import (
|
||||
"fmt"
|
||||
|
||||
"github.com/pkg/errors"
|
||||
"github.com/urfave/cli"
|
||||
)
|
||||
|
||||
@ -25,7 +26,6 @@ var (
|
||||
)
|
||||
|
||||
func mountCmd(c *cli.Context) error {
|
||||
var name string
|
||||
args := c.Args()
|
||||
if len(args) > 1 {
|
||||
return fmt.Errorf("too many arguments specified")
|
||||
@ -41,21 +41,20 @@ func mountCmd(c *cli.Context) error {
|
||||
}
|
||||
|
||||
if len(args) == 1 {
|
||||
name = args[0]
|
||||
|
||||
name := args[0]
|
||||
builder, err := openBuilder(store, name)
|
||||
if err != nil {
|
||||
return fmt.Errorf("error reading build container %q: %v", name, err)
|
||||
return errors.Wrapf(err, "error reading build container %q", name)
|
||||
}
|
||||
mountPoint, err := builder.Mount("")
|
||||
if err != nil {
|
||||
return fmt.Errorf("error mounting container %q: %v", builder.Container, err)
|
||||
return errors.Wrapf(err, "error mounting %q container %q", name, builder.Container)
|
||||
}
|
||||
fmt.Printf("%s\n", mountPoint)
|
||||
} else {
|
||||
builders, err := openBuilders(store)
|
||||
if err != nil {
|
||||
return fmt.Errorf("error reading build containers: %v", err)
|
||||
return errors.Wrapf(err, "error reading build containers")
|
||||
}
|
||||
for _, builder := range builders {
|
||||
if builder.MountPoint == "" {
|
||||
|
@ -7,6 +7,7 @@ import (
|
||||
"syscall"
|
||||
|
||||
"github.com/Sirupsen/logrus"
|
||||
"github.com/pkg/errors"
|
||||
"github.com/projectatomic/buildah"
|
||||
"github.com/urfave/cli"
|
||||
)
|
||||
@ -61,7 +62,7 @@ func runCmd(c *cli.Context) error {
|
||||
|
||||
builder, err := openBuilder(store, name)
|
||||
if err != nil {
|
||||
return fmt.Errorf("error reading build container %q: %v", name, err)
|
||||
return errors.Wrapf(err, "error reading build container %q", name)
|
||||
}
|
||||
|
||||
hostname := ""
|
||||
|
@ -3,6 +3,7 @@ package main
|
||||
import (
|
||||
"fmt"
|
||||
|
||||
"github.com/pkg/errors"
|
||||
"github.com/projectatomic/buildah/util"
|
||||
"github.com/urfave/cli"
|
||||
)
|
||||
@ -29,11 +30,11 @@ func tagCmd(c *cli.Context) error {
|
||||
}
|
||||
img, err := util.FindImage(store, args[0])
|
||||
if err != nil {
|
||||
return fmt.Errorf("error finding local image %q: %v", args[0], err)
|
||||
return errors.Wrapf(err, "error finding local image %q", args[0])
|
||||
}
|
||||
err = util.AddImageNames(store, img, args[1:])
|
||||
if err != nil {
|
||||
return fmt.Errorf("error adding names %v to image %q: %v", args[1:], args[0], err)
|
||||
return errors.Wrapf(err, "error adding names %v to image %q", args[1:], args[0])
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
@ -3,6 +3,7 @@ package main
|
||||
import (
|
||||
"fmt"
|
||||
|
||||
"github.com/pkg/errors"
|
||||
"github.com/urfave/cli"
|
||||
)
|
||||
|
||||
@ -34,12 +35,12 @@ func umountCmd(c *cli.Context) error {
|
||||
|
||||
builder, err := openBuilder(store, name)
|
||||
if err != nil {
|
||||
return fmt.Errorf("error reading build container %q: %v", name, err)
|
||||
return errors.Wrapf(err, "error reading build container %q", name)
|
||||
}
|
||||
|
||||
err = builder.Unmount()
|
||||
if err != nil {
|
||||
return fmt.Errorf("error unmounting container %q: %v", builder.Container, err)
|
||||
return errors.Wrapf(err, "error unmounting container %q", builder.Container)
|
||||
}
|
||||
|
||||
return nil
|
||||
|
10
commit.go
10
commit.go
@ -1,7 +1,6 @@
|
||||
package buildah
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"io"
|
||||
|
||||
"github.com/Sirupsen/logrus"
|
||||
@ -11,6 +10,7 @@ import (
|
||||
"github.com/containers/image/transports"
|
||||
"github.com/containers/image/types"
|
||||
"github.com/containers/storage/pkg/archive"
|
||||
"github.com/pkg/errors"
|
||||
"github.com/projectatomic/buildah/util"
|
||||
)
|
||||
|
||||
@ -52,22 +52,22 @@ func (b *Builder) Commit(dest types.ImageReference, options CommitOptions) error
|
||||
}
|
||||
src, err := b.makeContainerImageRef(options.PreferredManifestType, options.Compression)
|
||||
if err != nil {
|
||||
return fmt.Errorf("error recomputing layer digests and building metadata: %v", err)
|
||||
return errors.Wrapf(err, "error recomputing layer digests and building metadata")
|
||||
}
|
||||
err = copy.Image(policyContext, dest, src, getCopyOptions(options.ReportWriter))
|
||||
if err != nil {
|
||||
return fmt.Errorf("error copying layers and metadata: %v", err)
|
||||
return errors.Wrapf(err, "error copying layers and metadata")
|
||||
}
|
||||
if len(options.AdditionalTags) > 0 {
|
||||
switch dest.Transport().Name() {
|
||||
case storage.Transport.Name():
|
||||
img, err := storage.Transport.GetStoreImage(b.store, dest)
|
||||
if err != nil {
|
||||
return fmt.Errorf("error locating just-written image %q: %v", transports.ImageName(dest), err)
|
||||
return errors.Wrapf(err, "error locating just-written image %q", transports.ImageName(dest))
|
||||
}
|
||||
err = util.AddImageNames(b.store, img, options.AdditionalTags)
|
||||
if err != nil {
|
||||
return fmt.Errorf("error setting image names to %v: %v", append(img.Names, options.AdditionalTags...), err)
|
||||
return errors.Wrapf(err, "error setting image names to %v", append(img.Names, options.AdditionalTags...))
|
||||
}
|
||||
default:
|
||||
logrus.Warnf("don't know how to add tags to images stored in %q transport", dest.Transport().Name())
|
||||
|
@ -1,14 +1,14 @@
|
||||
package buildah
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"github.com/pkg/errors"
|
||||
)
|
||||
|
||||
// Delete removes the working container. The buildah.Builder object should not
|
||||
// be used after this method is called.
|
||||
func (b *Builder) Delete() error {
|
||||
if err := b.store.DeleteContainer(b.ContainerID); err != nil {
|
||||
return fmt.Errorf("error deleting build container: %v", err)
|
||||
return errors.Wrapf(err, "error deleting build container")
|
||||
}
|
||||
b.MountPoint = ""
|
||||
b.Container = ""
|
||||
|
17
image.go
17
image.go
@ -21,6 +21,7 @@ import (
|
||||
digest "github.com/opencontainers/go-digest"
|
||||
specs "github.com/opencontainers/image-spec/specs-go"
|
||||
"github.com/opencontainers/image-spec/specs-go/v1"
|
||||
"github.com/pkg/errors"
|
||||
"github.com/projectatomic/buildah/docker"
|
||||
)
|
||||
|
||||
@ -98,7 +99,7 @@ func (i *containerImageRef) NewImageSource(sc *types.SystemContext, manifestType
|
||||
layerID := i.container.LayerID
|
||||
layer, err := i.store.Layer(layerID)
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("unable to read layer %q: %v", layerID, err)
|
||||
return nil, errors.Wrapf(err, "unable to read layer %q", layerID)
|
||||
}
|
||||
for layer != nil {
|
||||
layers = append(append([]string{}, layerID), layers...)
|
||||
@ -109,7 +110,7 @@ func (i *containerImageRef) NewImageSource(sc *types.SystemContext, manifestType
|
||||
}
|
||||
layer, err = i.store.Layer(layerID)
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("unable to read layer %q: %v", layerID, err)
|
||||
return nil, errors.Wrapf(err, "unable to read layer %q", layerID)
|
||||
}
|
||||
}
|
||||
logrus.Debugf("layer list: %q", layers)
|
||||
@ -171,19 +172,19 @@ func (i *containerImageRef) NewImageSource(sc *types.SystemContext, manifestType
|
||||
for _, layerID := range layers {
|
||||
rc, err := i.store.Diff("", layerID)
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("error extracting layer %q: %v", layerID, err)
|
||||
return nil, errors.Wrapf(err, "error extracting layer %q", layerID)
|
||||
}
|
||||
defer rc.Close()
|
||||
uncompressed, err := archive.DecompressStream(rc)
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("error decompressing layer %q: %v", layerID, err)
|
||||
return nil, errors.Wrapf(err, "error decompressing layer %q", layerID)
|
||||
}
|
||||
defer uncompressed.Close()
|
||||
srcHasher := digest.Canonical.Digester()
|
||||
reader := io.TeeReader(uncompressed, srcHasher.Hash())
|
||||
layerFile, err := os.OpenFile(filepath.Join(path, "layer"), os.O_CREATE|os.O_WRONLY, 0600)
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("error opening file for layer %q: %v", layerID, err)
|
||||
return nil, errors.Wrapf(err, "error opening file for layer %q", layerID)
|
||||
}
|
||||
destHasher := digest.Canonical.Digester()
|
||||
counter := ioutils.NewWriteCounter(layerFile)
|
||||
@ -204,11 +205,11 @@ func (i *containerImageRef) NewImageSource(sc *types.SystemContext, manifestType
|
||||
}
|
||||
compressor, err := archive.CompressStream(multiWriter, i.compression)
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("error compressing layer %q: %v", layerID, err)
|
||||
return nil, errors.Wrapf(err, "error compressing layer %q", layerID)
|
||||
}
|
||||
size, err := io.Copy(compressor, reader)
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("error storing layer %q to file: %v", layerID, err)
|
||||
return nil, errors.Wrapf(err, "error storing layer %q to file", layerID)
|
||||
}
|
||||
compressor.Close()
|
||||
layerFile.Close()
|
||||
@ -222,7 +223,7 @@ func (i *containerImageRef) NewImageSource(sc *types.SystemContext, manifestType
|
||||
logrus.Debugf("layer %q size is %d bytes", layerID, size)
|
||||
err = os.Rename(filepath.Join(path, "layer"), filepath.Join(path, destHasher.Digest().String()))
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("error storing layer %q to file: %v", layerID, err)
|
||||
return nil, errors.Wrapf(err, "error storing layer %q to file", layerID)
|
||||
}
|
||||
olayerDescriptor := v1.Descriptor{
|
||||
MediaType: omediaType,
|
||||
|
@ -20,6 +20,7 @@ import (
|
||||
docker "github.com/fsouza/go-dockerclient"
|
||||
"github.com/opencontainers/runtime-spec/specs-go"
|
||||
"github.com/openshift/imagebuilder"
|
||||
"github.com/pkg/errors"
|
||||
"github.com/projectatomic/buildah"
|
||||
)
|
||||
|
||||
@ -200,7 +201,7 @@ func (b *Executor) Preserve(path string) error {
|
||||
archivedPath := filepath.Join(b.mountPoint, cachedPath)
|
||||
logrus.Debugf("no longer need cache of %q in %q", archivedPath, b.volumeCache[cachedPath])
|
||||
if err := os.Remove(b.volumeCache[cachedPath]); err != nil {
|
||||
return fmt.Errorf("error removing %q: %v", b.volumeCache[cachedPath], err)
|
||||
return errors.Wrapf(err, "error removing %q", b.volumeCache[cachedPath])
|
||||
}
|
||||
delete(b.volumeCache, cachedPath)
|
||||
}
|
||||
@ -218,7 +219,7 @@ func (b *Executor) volumeCacheInvalidate(path string) error {
|
||||
}
|
||||
for _, cachedPath := range invalidated {
|
||||
if err := os.Remove(b.volumeCache[cachedPath]); err != nil {
|
||||
return fmt.Errorf("error removing volume cache %q: %v", b.volumeCache[cachedPath], err)
|
||||
return errors.Wrapf(err, "error removing volume cache %q", b.volumeCache[cachedPath])
|
||||
}
|
||||
archivedPath := filepath.Join(b.mountPoint, cachedPath)
|
||||
logrus.Debugf("invalidated volume cache for %q from %q", archivedPath, b.volumeCache[cachedPath])
|
||||
@ -238,22 +239,22 @@ func (b *Executor) volumeCacheSave() error {
|
||||
continue
|
||||
}
|
||||
if !os.IsNotExist(err) {
|
||||
return fmt.Errorf("error checking for cache of %q in %q: %v", archivedPath, cacheFile, err)
|
||||
return errors.Wrapf(err, "error checking for cache of %q in %q", archivedPath, cacheFile)
|
||||
}
|
||||
logrus.Debugf("caching contents of volume %q in %q", archivedPath, cacheFile)
|
||||
cache, err := os.Create(cacheFile)
|
||||
if err != nil {
|
||||
return fmt.Errorf("error creating archive at %q: %v", cacheFile, err)
|
||||
return errors.Wrapf(err, "error creating archive at %q", cacheFile)
|
||||
}
|
||||
defer cache.Close()
|
||||
rc, err := archive.Tar(archivedPath, archive.Uncompressed)
|
||||
if err != nil {
|
||||
return fmt.Errorf("error archiving %q: %v", archivedPath, err)
|
||||
return errors.Wrapf(err, "error archiving %q", archivedPath)
|
||||
}
|
||||
defer rc.Close()
|
||||
_, err = io.Copy(cache, rc)
|
||||
if err != nil {
|
||||
return fmt.Errorf("error archiving %q to %q: %v", archivedPath, cacheFile, err)
|
||||
return errors.Wrapf(err, "error archiving %q to %q", archivedPath, cacheFile)
|
||||
}
|
||||
}
|
||||
return nil
|
||||
@ -266,28 +267,28 @@ func (b *Executor) volumeCacheRestore() error {
|
||||
logrus.Debugf("restoring contents of volume %q from %q", archivedPath, cacheFile)
|
||||
cache, err := os.Open(cacheFile)
|
||||
if err != nil {
|
||||
return fmt.Errorf("error opening archive at %q: %v", cacheFile, err)
|
||||
return errors.Wrapf(err, "error opening archive at %q", cacheFile)
|
||||
}
|
||||
defer cache.Close()
|
||||
if err := os.RemoveAll(archivedPath); err != nil {
|
||||
return fmt.Errorf("error clearing volume path %q: %v", archivedPath, err)
|
||||
return errors.Wrapf(err, "error clearing volume path %q", archivedPath)
|
||||
}
|
||||
if err := os.MkdirAll(archivedPath, 0700); err != nil {
|
||||
return fmt.Errorf("error recreating volume path %q: %v", archivedPath, err)
|
||||
return errors.Wrapf(err, "error recreating volume path %q", archivedPath)
|
||||
}
|
||||
err = archive.Untar(cache, archivedPath, nil)
|
||||
if err != nil {
|
||||
return fmt.Errorf("error extracting archive at %q: %v", archivedPath, err)
|
||||
return errors.Wrapf(err, "error extracting archive at %q", archivedPath)
|
||||
}
|
||||
if st, ok := b.volumeCacheInfo[cachedPath]; ok {
|
||||
if err := os.Chmod(archivedPath, st.Mode()); err != nil {
|
||||
return fmt.Errorf("error restoring permissions on %q: %v", archivedPath, err)
|
||||
return errors.Wrapf(err, "error restoring permissions on %q", archivedPath)
|
||||
}
|
||||
if err := os.Chown(archivedPath, 0, 0); err != nil {
|
||||
return fmt.Errorf("error setting ownership on %q: %v", archivedPath, err)
|
||||
return errors.Wrapf(err, "error setting ownership on %q", archivedPath)
|
||||
}
|
||||
if err := os.Chtimes(archivedPath, st.ModTime(), st.ModTime()); err != nil {
|
||||
return fmt.Errorf("error restoring datestamps on %q: %v", archivedPath, err)
|
||||
return errors.Wrapf(err, "error restoring datestamps on %q", archivedPath)
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -428,7 +429,7 @@ func (b *Executor) Prepare(ib *imagebuilder.Builder, node *parser.Node, from str
|
||||
base, err := ib.From(node)
|
||||
if err != nil {
|
||||
logrus.Debugf("Prepare(node.Children=%#v)", node.Children)
|
||||
return fmt.Errorf("error determining starting point for build: %v", err)
|
||||
return errors.Wrapf(err, "error determining starting point for build")
|
||||
}
|
||||
from = base
|
||||
}
|
||||
@ -445,7 +446,7 @@ func (b *Executor) Prepare(ib *imagebuilder.Builder, node *parser.Node, from str
|
||||
}
|
||||
builder, err := buildah.NewBuilder(b.store, builderOptions)
|
||||
if err != nil {
|
||||
return fmt.Errorf("error creating build container: %v", err)
|
||||
return errors.Wrapf(err, "error creating build container")
|
||||
}
|
||||
volumes := map[string]struct{}{}
|
||||
for _, v := range builder.Volumes() {
|
||||
@ -486,14 +487,14 @@ func (b *Executor) Prepare(ib *imagebuilder.Builder, node *parser.Node, from str
|
||||
if err2 := builder.Delete(); err2 != nil {
|
||||
logrus.Debugf("error deleting container which we failed to update: %v", err2)
|
||||
}
|
||||
return fmt.Errorf("error updating build context: %v", err)
|
||||
return errors.Wrapf(err, "error updating build context")
|
||||
}
|
||||
mountPoint, err := builder.Mount("")
|
||||
if err != nil {
|
||||
if err2 := builder.Delete(); err2 != nil {
|
||||
logrus.Debugf("error deleting container which we failed to mount: %v", err2)
|
||||
}
|
||||
return fmt.Errorf("error mounting new container: %v", err)
|
||||
return errors.Wrapf(err, "error mounting new container")
|
||||
}
|
||||
b.mountPoint = mountPoint
|
||||
b.builder = builder
|
||||
@ -516,7 +517,7 @@ func (b *Executor) Execute(ib *imagebuilder.Builder, node *parser.Node) error {
|
||||
for i, node := range node.Children {
|
||||
step := ib.Step()
|
||||
if err := step.Resolve(node); err != nil {
|
||||
return fmt.Errorf("error resolving step %+v: %v", *node, err)
|
||||
return errors.Wrapf(err, "error resolving step %+v", *node)
|
||||
}
|
||||
logrus.Debugf("Parsed Step: %+v", *step)
|
||||
if !b.quiet {
|
||||
@ -528,7 +529,7 @@ func (b *Executor) Execute(ib *imagebuilder.Builder, node *parser.Node) error {
|
||||
}
|
||||
err := ib.Run(step, b, requiresStart)
|
||||
if err != nil {
|
||||
return fmt.Errorf("error building at step %+v: %v", *step, err)
|
||||
return errors.Wrapf(err, "error building at step %+v", *step)
|
||||
}
|
||||
}
|
||||
return nil
|
||||
@ -551,7 +552,7 @@ func (b *Executor) Commit(ib *imagebuilder.Builder) (err error) {
|
||||
imageRef, err = is.Transport.ParseStoreReference(b.store, "@"+stringid.GenerateRandomID())
|
||||
}
|
||||
if err != nil {
|
||||
return fmt.Errorf("error parsing reference for image to be written: %v", err)
|
||||
return errors.Wrapf(err, "error parsing reference for image to be written")
|
||||
}
|
||||
config := ib.Config()
|
||||
b.builder.SetHostname(config.Hostname)
|
||||
@ -603,13 +604,13 @@ func (b *Executor) Commit(ib *imagebuilder.Builder) (err error) {
|
||||
// over each of the one or more parsed Dockerfiles.
|
||||
func (b *Executor) Build(ib *imagebuilder.Builder, node []*parser.Node) (err error) {
|
||||
if len(node) == 0 {
|
||||
return fmt.Errorf("error building: no build instructions")
|
||||
return errors.Wrapf(err, "error building: no build instructions")
|
||||
}
|
||||
first := node[0]
|
||||
from, err := ib.From(first)
|
||||
if err != nil {
|
||||
logrus.Debugf("Build(first.Children=%#v)", first.Children)
|
||||
return fmt.Errorf("error determining starting point for build: %v", err)
|
||||
return errors.Wrapf(err, "error determining starting point for build")
|
||||
}
|
||||
if err = b.Prepare(ib, first, from); err != nil {
|
||||
return err
|
||||
@ -637,17 +638,17 @@ func BuildReadClosers(store storage.Store, options BuildOptions, dockerfile ...i
|
||||
}
|
||||
builder, parsed, err := imagebuilder.NewBuilderForReader(mainFile, options.Args)
|
||||
if err != nil {
|
||||
return fmt.Errorf("error creating builder: %v", err)
|
||||
return errors.Wrapf(err, "error creating builder")
|
||||
}
|
||||
exec, err := NewExecutor(store, options)
|
||||
if err != nil {
|
||||
return fmt.Errorf("error creating build executor: %v", err)
|
||||
return errors.Wrapf(err, "error creating build executor")
|
||||
}
|
||||
nodes := []*parser.Node{parsed}
|
||||
for _, extra := range extraFiles {
|
||||
_, parsed, err := imagebuilder.NewBuilderForReader(extra, options.Args)
|
||||
if err != nil {
|
||||
return fmt.Errorf("error parsing dockerfile: %v", err)
|
||||
return errors.Wrapf(err, "error parsing dockerfile")
|
||||
}
|
||||
nodes = append(nodes, parsed)
|
||||
}
|
||||
@ -668,7 +669,7 @@ func BuildDockerfiles(store storage.Store, options BuildOptions, dockerfile ...s
|
||||
logrus.Debugf("reading remote Dockerfile %q", dfile)
|
||||
resp, err := http.Get(dfile)
|
||||
if err != nil {
|
||||
return fmt.Errorf("error getting %q: %v", dfile, err)
|
||||
return errors.Wrapf(err, "error getting %q", dfile)
|
||||
}
|
||||
if resp.ContentLength == 0 {
|
||||
resp.Body.Close()
|
||||
@ -683,23 +684,23 @@ func BuildDockerfiles(store storage.Store, options BuildOptions, dockerfile ...s
|
||||
logrus.Debugf("reading local Dockerfile %q", dfile)
|
||||
contents, err := os.Open(dfile)
|
||||
if err != nil {
|
||||
return fmt.Errorf("error reading %q: %v", dfile, err)
|
||||
return errors.Wrapf(err, "error reading %q", dfile)
|
||||
}
|
||||
dinfo, err := contents.Stat()
|
||||
if err != nil {
|
||||
contents.Close()
|
||||
return fmt.Errorf("error reading info about %q: %v", dfile, err)
|
||||
return errors.Wrapf(err, "error reading info about %q", dfile)
|
||||
}
|
||||
if dinfo.Size() == 0 {
|
||||
contents.Close()
|
||||
return fmt.Errorf("no contents in %q: %v", dfile, err)
|
||||
return errors.Wrapf(err, "no contents in %q", dfile)
|
||||
}
|
||||
rc = contents
|
||||
}
|
||||
dockerfiles = append(dockerfiles, rc)
|
||||
}
|
||||
if err := BuildReadClosers(store, options, dockerfiles...); err != nil {
|
||||
return fmt.Errorf("error building: %v", err)
|
||||
return errors.Wrapf(err, "error building")
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
@ -11,6 +11,7 @@ import (
|
||||
|
||||
"github.com/Sirupsen/logrus"
|
||||
"github.com/containers/storage/pkg/chrootarchive"
|
||||
"github.com/pkg/errors"
|
||||
"github.com/projectatomic/buildah"
|
||||
)
|
||||
|
||||
@ -27,7 +28,7 @@ func downloadToDirectory(url, dir string) error {
|
||||
logrus.Debugf("extracting %q to %q", url, dir)
|
||||
resp, err := http.Get(url)
|
||||
if err != nil {
|
||||
return fmt.Errorf("error getting %q: %v", url, err)
|
||||
return errors.Wrapf(err, "error getting %q", url)
|
||||
}
|
||||
defer resp.Body.Close()
|
||||
if resp.ContentLength == 0 {
|
||||
@ -52,7 +53,7 @@ func TempDirForURL(dir, prefix, url string) (name string, subdir string, err err
|
||||
}
|
||||
name, err = ioutil.TempDir(dir, prefix)
|
||||
if err != nil {
|
||||
return "", "", fmt.Errorf("error creating temporary directory for %q: %v", url, err)
|
||||
return "", "", errors.Wrapf(err, "error creating temporary directory for %q", url)
|
||||
}
|
||||
if strings.HasPrefix(url, "git://") {
|
||||
err = cloneToDirectory(url, name)
|
||||
|
15
import.go
15
import.go
@ -6,6 +6,7 @@ import (
|
||||
is "github.com/containers/image/storage"
|
||||
"github.com/containers/image/types"
|
||||
"github.com/containers/storage"
|
||||
"github.com/pkg/errors"
|
||||
)
|
||||
|
||||
func importBuilderDataFromImage(store storage.Store, systemContext *types.SystemContext, imageID, containerName, containerID string) (*Builder, error) {
|
||||
@ -16,20 +17,20 @@ func importBuilderDataFromImage(store storage.Store, systemContext *types.System
|
||||
if imageID != "" {
|
||||
ref, err := is.Transport.ParseStoreReference(store, "@"+imageID)
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("no such image %q: %v", "@"+imageID, err)
|
||||
return nil, errors.Wrapf(err, "no such image %q", "@"+imageID)
|
||||
}
|
||||
src, err2 := ref.NewImage(systemContext)
|
||||
if err2 != nil {
|
||||
return nil, fmt.Errorf("error instantiating image: %v", err2)
|
||||
return nil, errors.Wrapf(err2, "error instantiating image")
|
||||
}
|
||||
defer src.Close()
|
||||
config, err = src.ConfigBlob()
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("error reading image configuration: %v", err)
|
||||
return nil, errors.Wrapf(err, "error reading image configuration")
|
||||
}
|
||||
manifest, _, err = src.Manifest()
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("error reading image manifest: %v", err)
|
||||
return nil, errors.Wrapf(err, "error reading image manifest")
|
||||
}
|
||||
if img, err3 := store.Image(imageID); err3 == nil {
|
||||
if len(img.Names) > 0 {
|
||||
@ -75,7 +76,7 @@ func importBuilder(store storage.Store, options ImportOptions) (*Builder, error)
|
||||
|
||||
err = builder.Save()
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("error saving builder state: %v", err)
|
||||
return nil, errors.Wrapf(err, "error saving builder state")
|
||||
}
|
||||
|
||||
return builder, nil
|
||||
@ -88,11 +89,11 @@ func importBuilderFromImage(store storage.Store, options ImportFromImageOptions)
|
||||
|
||||
ref, err := is.Transport.ParseStoreReference(store, options.Image)
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("error parsing reference to image %q: %v", options.Image, err)
|
||||
return nil, errors.Wrapf(err, "error parsing reference to image %q", options.Image)
|
||||
}
|
||||
img, err := is.Transport.GetStoreImage(store, ref)
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("unable to locate image: %v", err)
|
||||
return nil, errors.Wrapf(err, "unable to locate image")
|
||||
}
|
||||
|
||||
systemContext := getSystemContext(options.SignaturePolicyPath)
|
||||
|
25
new.go
25
new.go
@ -8,6 +8,7 @@ import (
|
||||
is "github.com/containers/image/storage"
|
||||
"github.com/containers/storage"
|
||||
"github.com/openshift/imagebuilder"
|
||||
"github.com/pkg/errors"
|
||||
)
|
||||
|
||||
const (
|
||||
@ -67,51 +68,51 @@ func newBuilder(store storage.Store, options BuilderOptions) (*Builder, error) {
|
||||
if options.PullPolicy == PullAlways {
|
||||
err := pullImage(store, options, systemContext)
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("error pulling image %q: %v", image, err)
|
||||
return nil, errors.Wrapf(err, "error pulling image %q", image)
|
||||
}
|
||||
}
|
||||
ref, err := is.Transport.ParseStoreReference(store, image)
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("error parsing reference to image %q: %v", image, err)
|
||||
return nil, errors.Wrapf(err, "error parsing reference to image %q", image)
|
||||
}
|
||||
img, err = is.Transport.GetStoreImage(store, ref)
|
||||
if err != nil {
|
||||
if err == storage.ErrImageUnknown && options.PullPolicy != PullIfMissing {
|
||||
return nil, fmt.Errorf("no such image %q: %v", image, err)
|
||||
return nil, errors.Wrapf(err, "no such image %q", image)
|
||||
}
|
||||
err = pullImage(store, options, systemContext)
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("error pulling image %q: %v", image, err)
|
||||
return nil, errors.Wrapf(err, "error pulling image %q", image)
|
||||
}
|
||||
ref, err = is.Transport.ParseStoreReference(store, image)
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("error parsing reference to image %q: %v", image, err)
|
||||
return nil, errors.Wrapf(err, "error parsing reference to image %q", image)
|
||||
}
|
||||
img, err = is.Transport.GetStoreImage(store, ref)
|
||||
}
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("no such image %q: %v", image, err)
|
||||
return nil, errors.Wrapf(err, "no such image %q", image)
|
||||
}
|
||||
imageID = img.ID
|
||||
src, err := ref.NewImage(systemContext)
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("error instantiating image: %v", err)
|
||||
return nil, errors.Wrapf(err, "error instantiating image")
|
||||
}
|
||||
defer src.Close()
|
||||
config, err = src.ConfigBlob()
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("error reading image configuration: %v", err)
|
||||
return nil, errors.Wrapf(err, "error reading image configuration")
|
||||
}
|
||||
manifest, _, err = src.Manifest()
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("error reading image manifest: %v", err)
|
||||
return nil, errors.Wrapf(err, "error reading image manifest")
|
||||
}
|
||||
}
|
||||
|
||||
coptions := storage.ContainerOptions{}
|
||||
container, err := store.CreateContainer("", []string{name}, imageID, "", "", &coptions)
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("error creating container: %v", err)
|
||||
return nil, errors.Wrapf(err, "error creating container")
|
||||
}
|
||||
|
||||
defer func() {
|
||||
@ -138,14 +139,14 @@ func newBuilder(store storage.Store, options BuilderOptions) (*Builder, error) {
|
||||
if options.Mount {
|
||||
_, err = builder.Mount("")
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("error mounting build container: %v", err)
|
||||
return nil, errors.Wrapf(err, "error mounting build container")
|
||||
}
|
||||
}
|
||||
|
||||
builder.initConfig()
|
||||
err = builder.Save()
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("error saving builder state: %v", err)
|
||||
return nil, errors.Wrapf(err, "error saving builder state")
|
||||
}
|
||||
|
||||
return builder, nil
|
||||
|
7
pull.go
7
pull.go
@ -1,8 +1,6 @@
|
||||
package buildah
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
|
||||
"github.com/Sirupsen/logrus"
|
||||
"github.com/containers/image/copy"
|
||||
"github.com/containers/image/docker/reference"
|
||||
@ -11,6 +9,7 @@ import (
|
||||
"github.com/containers/image/transports/alltransports"
|
||||
"github.com/containers/image/types"
|
||||
"github.com/containers/storage"
|
||||
"github.com/pkg/errors"
|
||||
)
|
||||
|
||||
func pullImage(store storage.Store, options BuilderOptions, sc *types.SystemContext) error {
|
||||
@ -25,7 +24,7 @@ func pullImage(store storage.Store, options BuilderOptions, sc *types.SystemCont
|
||||
if err != nil {
|
||||
srcRef2, err2 := alltransports.ParseImageName(spec)
|
||||
if err2 != nil {
|
||||
return fmt.Errorf("error parsing image name %q: %v", spec, err2)
|
||||
return errors.Wrapf(err2, "error parsing image name %q", spec)
|
||||
}
|
||||
srcRef = srcRef2
|
||||
}
|
||||
@ -39,7 +38,7 @@ func pullImage(store storage.Store, options BuilderOptions, sc *types.SystemCont
|
||||
|
||||
destRef, err := is.Transport.ParseStoreReference(store, name)
|
||||
if err != nil {
|
||||
return fmt.Errorf("error parsing full image name %q: %v", name, err)
|
||||
return errors.Wrapf(err, "error parsing full image name %q", name)
|
||||
}
|
||||
|
||||
policy, err := signature.DefaultPolicy(sc)
|
||||
|
10
run.go
10
run.go
@ -2,7 +2,6 @@ package buildah
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
"io/ioutil"
|
||||
"os"
|
||||
"os/exec"
|
||||
@ -13,6 +12,7 @@ import (
|
||||
"github.com/containers/storage/pkg/ioutils"
|
||||
"github.com/opencontainers/runtime-spec/specs-go"
|
||||
"github.com/opencontainers/runtime-tools/generate"
|
||||
"github.com/pkg/errors"
|
||||
)
|
||||
|
||||
const (
|
||||
@ -184,7 +184,7 @@ func (b *Builder) Run(command []string, options RunOptions) error {
|
||||
}
|
||||
if !options.NetworkDisabled {
|
||||
if err = g.RemoveLinuxNamespace("network"); err != nil {
|
||||
return fmt.Errorf("error removing network namespace for run: %v)", err)
|
||||
return errors.Wrapf(err, "error removing network namespace for run")
|
||||
}
|
||||
}
|
||||
if options.User != "" {
|
||||
@ -202,13 +202,13 @@ func (b *Builder) Run(command []string, options RunOptions) error {
|
||||
spec.Process.Cwd = DefaultWorkingDir
|
||||
}
|
||||
if err = os.MkdirAll(filepath.Join(mountPoint, b.WorkDir()), 0755); err != nil {
|
||||
return fmt.Errorf("error ensuring working directory %q exists: %v)", b.WorkDir(), err)
|
||||
return errors.Wrapf(err, "error ensuring working directory %q exists", b.WorkDir())
|
||||
}
|
||||
|
||||
bindFiles := []string{"/etc/hosts", "/etc/resolv.conf"}
|
||||
err = setupMounts(spec, options.Mounts, bindFiles, b.Volumes())
|
||||
if err != nil {
|
||||
return fmt.Errorf("error resolving mountpoints for container: %v)", err)
|
||||
return errors.Wrapf(err, "error resolving mountpoints for container")
|
||||
}
|
||||
specbytes, err := json.Marshal(spec)
|
||||
if err != nil {
|
||||
@ -216,7 +216,7 @@ func (b *Builder) Run(command []string, options RunOptions) error {
|
||||
}
|
||||
err = ioutils.AtomicWriteFile(filepath.Join(path, "config.json"), specbytes, 0600)
|
||||
if err != nil {
|
||||
return fmt.Errorf("error storing runtime configuration: %v", err)
|
||||
return errors.Wrapf(err, "error storing runtime configuration")
|
||||
}
|
||||
logrus.Debugf("config = %v", string(specbytes))
|
||||
runtime := options.Runtime
|
||||
|
6
user.go
6
user.go
@ -1,12 +1,12 @@
|
||||
package buildah
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"os/user"
|
||||
"strconv"
|
||||
"strings"
|
||||
|
||||
"github.com/opencontainers/runtime-spec/specs-go"
|
||||
"github.com/pkg/errors"
|
||||
)
|
||||
|
||||
func getUser(rootdir, userspec string) (specs.User, error) {
|
||||
@ -70,9 +70,9 @@ func getUser(rootdir, userspec string) (specs.User, error) {
|
||||
return u, nil
|
||||
}
|
||||
|
||||
err := fmt.Errorf("%v determining run uid", uerr)
|
||||
err := errors.Wrapf(uerr, "error determining run uid")
|
||||
if uerr == nil {
|
||||
err = fmt.Errorf("%v determining run gid", gerr)
|
||||
err = errors.Wrapf(gerr, "error determining run gid")
|
||||
}
|
||||
return specs.User{}, err
|
||||
}
|
||||
|
@ -7,13 +7,13 @@ import (
|
||||
)
|
||||
|
||||
func lookupUserInContainer(rootdir, username string) (uint64, uint64, error) {
|
||||
return 0, 0, fmt.Errorf("user lookup not supported")
|
||||
return 0, 0, errors.Wrapf("user lookup not supported")
|
||||
}
|
||||
|
||||
func lookupGroupInContainer(rootdir, groupname string) (uint64, error) {
|
||||
return 0, fmt.Errorf("group lookup not supported")
|
||||
return 0, errors.Wrapf("group lookup not supported")
|
||||
}
|
||||
|
||||
func lookupGroupForUIDInContainer(rootdir string, userid uint64) (string, uint64, error) {
|
||||
return "", 0, fmt.Errorf("primary group lookup by uid not supported")
|
||||
return "", 0, errors.Wrapf("primary group lookup by uid not supported")
|
||||
}
|
||||
|
@ -19,6 +19,8 @@ import (
|
||||
"sync"
|
||||
"syscall"
|
||||
"unsafe"
|
||||
|
||||
"github.com/pkg/errors"
|
||||
)
|
||||
|
||||
func fopenContainerFile(rootdir, filename string) (C.pFILE, error) {
|
||||
@ -31,13 +33,13 @@ func fopenContainerFile(rootdir, filename string) (C.pFILE, error) {
|
||||
defer C.free(unsafe.Pointer(mode))
|
||||
f, err := C.fopen(cctrfile, mode)
|
||||
if f == nil || err != nil {
|
||||
return nil, fmt.Errorf("error opening %q: %v", ctrfile, err)
|
||||
return nil, errors.Wrapf(err, "error opening %q", ctrfile)
|
||||
}
|
||||
if err = syscall.Fstat(int(C.fileno(f)), &st); err != nil {
|
||||
return nil, fmt.Errorf("fstat(%q): %v", ctrfile, err)
|
||||
return nil, errors.Wrapf(err, "fstat(%q)", ctrfile)
|
||||
}
|
||||
if err = syscall.Lstat(ctrfile, &lst); err != nil {
|
||||
return nil, fmt.Errorf("lstat(%q): %v", ctrfile, err)
|
||||
return nil, errors.Wrapf(err, "lstat(%q)", ctrfile)
|
||||
}
|
||||
if st.Dev != lst.Dev || st.Ino != lst.Ino {
|
||||
return nil, fmt.Errorf("%q is not a regular file", ctrfile)
|
||||
|
11
util/util.go
11
util/util.go
@ -1,11 +1,10 @@
|
||||
package util
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
|
||||
"github.com/containers/image/docker/reference"
|
||||
is "github.com/containers/image/storage"
|
||||
"github.com/containers/storage"
|
||||
"github.com/pkg/errors"
|
||||
)
|
||||
|
||||
// ExpandTags takes unqualified names, parses them as image names, and returns
|
||||
@ -15,7 +14,7 @@ func ExpandTags(tags []string) ([]string, error) {
|
||||
for _, tag := range tags {
|
||||
name, err := reference.ParseNormalizedNamed(tag)
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("error parsing tag %q: %v", tag, err)
|
||||
return nil, errors.Wrapf(err, "error parsing tag %q", tag)
|
||||
}
|
||||
name = reference.TagNameOnly(name)
|
||||
tag = ""
|
||||
@ -31,11 +30,11 @@ func ExpandTags(tags []string) ([]string, error) {
|
||||
func FindImage(store storage.Store, image string) (*storage.Image, error) {
|
||||
ref, err := is.Transport.ParseStoreReference(store, image)
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("error parsing reference to image %q: %v", image, err)
|
||||
return nil, errors.Wrapf(err, "error parsing reference to image %q", image)
|
||||
}
|
||||
img, err := is.Transport.GetStoreImage(store, ref)
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("unable to locate image: %v", err)
|
||||
return nil, errors.Wrapf(err, "unable to locate image")
|
||||
}
|
||||
return img, nil
|
||||
}
|
||||
@ -48,7 +47,7 @@ func AddImageNames(store storage.Store, image *storage.Image, addNames []string)
|
||||
}
|
||||
err = store.SetNames(image.ID, append(image.Names, names...))
|
||||
if err != nil {
|
||||
return fmt.Errorf("error adding names (%v) to image %q: %v", names, image.ID, err)
|
||||
return errors.Wrapf(err, "error adding names (%v) to image %q", names, image.ID)
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
Reference in New Issue
Block a user