Update c/image to v4.0.1 and buildah to 1.11.3

This requires updating all import paths throughout, and a matching
buildah update to interoperate.

I can't figure out the reason for go.mod tracking
	github.com/containers/image v3.0.2+incompatible // indirect
((go mod graph) lists it as a direct dependency of libpod, but
(go list -json -m all) lists it as an indirect dependency),
but at least looking at the vendor subdirectory, it doesn't seem
to be actually used in the built binaries.

Signed-off-by: Miloslav Trmač <mitr@redhat.com>
This commit is contained in:
Miloslav Trmač
2019-10-01 22:15:58 +02:00
parent bd08fc0e9b
commit d3f59bedb3
464 changed files with 9556 additions and 2221 deletions

View File

@@ -13,12 +13,12 @@ import (
"strings"
"github.com/containers/buildah"
"github.com/containers/image/docker/reference"
"github.com/containers/image/types"
"github.com/containers/image/v4/docker/reference"
"github.com/containers/image/v4/types"
"github.com/containers/storage"
"github.com/containers/storage/pkg/archive"
"github.com/opencontainers/runc/libcontainer/configs"
"github.com/opencontainers/runtime-spec/specs-go"
specs "github.com/opencontainers/runtime-spec/specs-go"
"github.com/openshift/imagebuilder"
"github.com/pkg/errors"
"github.com/sirupsen/logrus"

View File

@@ -12,11 +12,11 @@ import (
"github.com/containers/buildah"
"github.com/containers/buildah/util"
"github.com/containers/image/docker/reference"
is "github.com/containers/image/storage"
"github.com/containers/image/transports"
"github.com/containers/image/transports/alltransports"
"github.com/containers/image/types"
"github.com/containers/image/v4/docker/reference"
is "github.com/containers/image/v4/storage"
"github.com/containers/image/v4/transports"
"github.com/containers/image/v4/transports/alltransports"
"github.com/containers/image/v4/types"
"github.com/containers/storage"
"github.com/containers/storage/pkg/archive"
v1 "github.com/opencontainers/image-spec/specs-go/v1"
@@ -164,7 +164,7 @@ func NewExecutor(store storage.Store, options BuildOptions, mainNode *parser.Nod
stepCounter++
prefix := fmt.Sprintf("STEP %d: ", stepCounter)
suffix := "\n"
fmt.Fprintf(exec.err, prefix+format+suffix, args...)
fmt.Fprintf(exec.out, prefix+format+suffix, args...)
}
}
for arg := range options.Args {

View File

@@ -13,12 +13,12 @@ import (
"github.com/containers/buildah"
buildahdocker "github.com/containers/buildah/docker"
"github.com/containers/buildah/util"
cp "github.com/containers/image/copy"
"github.com/containers/image/docker/reference"
"github.com/containers/image/manifest"
is "github.com/containers/image/storage"
"github.com/containers/image/transports"
"github.com/containers/image/types"
cp "github.com/containers/image/v4/copy"
"github.com/containers/image/v4/docker/reference"
"github.com/containers/image/v4/manifest"
is "github.com/containers/image/v4/storage"
"github.com/containers/image/v4/transports"
"github.com/containers/image/v4/types"
"github.com/containers/storage"
"github.com/containers/storage/pkg/archive"
securejoin "github.com/cyphar/filepath-securejoin"
@@ -253,7 +253,7 @@ func (s *StageExecutor) volumeCacheRestore() error {
// don't care about the details of where in the filesystem the content actually
// goes, because we're not actually going to add it here, so this is less
// involved than Copy().
func (s *StageExecutor) digestSpecifiedContent(node *parser.Node) (string, error) {
func (s *StageExecutor) digestSpecifiedContent(node *parser.Node, argValues []string) (string, error) {
// No instruction: done.
if node == nil {
return "", nil
@@ -297,7 +297,15 @@ func (s *StageExecutor) digestSpecifiedContent(node *parser.Node) (string, error
}
}
}
for _, src := range srcs {
// If src has an argument within it, resolve it to its
// value. Otherwise just return the value found.
name, err := imagebuilder.ProcessWord(src, argValues)
if err != nil {
return "", errors.Wrapf(err, "unable to resolve source %q", src)
}
src = name
if strings.HasPrefix(src, "http://") || strings.HasPrefix(src, "https://") {
// Source is a URL. TODO: cache this content
// somewhere, so that we can avoid pulling it down
@@ -334,7 +342,14 @@ func (s *StageExecutor) digestSpecifiedContent(node *parser.Node) (string, error
}
s.builder.ContentDigester.Restart()
download := strings.ToUpper(node.Value) == "ADD"
err := s.builder.Add(destination.Value, download, options, sources...)
// If destination.Value has an argument within it, resolve it to its
// value. Otherwise just return the value found.
destValue, destErr := imagebuilder.ProcessWord(destination.Value, argValues)
if destErr != nil {
return "", errors.Wrapf(destErr, "unable to resolve destination %q", destination.Value)
}
err := s.builder.Add(destValue, download, options, sources...)
if err != nil {
return "", errors.Wrapf(err, "error dry-running %q", node.Original)
}
@@ -832,7 +847,7 @@ func (s *StageExecutor) Execute(ctx context.Context, stage imagebuilder.Stage, b
return "", nil, errors.Wrapf(err, "error building at STEP \"%s\"", step.Message)
}
// In case we added content, retrieve its digest.
addedContentDigest, err := s.digestSpecifiedContent(node)
addedContentDigest, err := s.digestSpecifiedContent(node, ib.Arguments())
if err != nil {
return "", nil, err
}
@@ -881,7 +896,7 @@ func (s *StageExecutor) Execute(ctx context.Context, stage imagebuilder.Stage, b
// cached images so far, look for one that matches what we
// expect to produce for this instruction.
if checkForLayers && !(s.executor.squash && lastInstruction && lastStage) {
addedContentDigest, err := s.digestSpecifiedContent(node)
addedContentDigest, err := s.digestSpecifiedContent(node, ib.Arguments())
if err != nil {
return "", nil, err
}
@@ -939,7 +954,7 @@ func (s *StageExecutor) Execute(ctx context.Context, stage imagebuilder.Stage, b
return "", nil, errors.Wrapf(err, "error building at STEP \"%s\"", step.Message)
}
// In case we added content, retrieve its digest.
addedContentDigest, err := s.digestSpecifiedContent(node)
addedContentDigest, err := s.digestSpecifiedContent(node, ib.Arguments())
if err != nil {
return "", nil, err
}

View File

@@ -1,6 +1,8 @@
package imagebuildah
import (
"bufio"
"bytes"
"fmt"
"io/ioutil"
"net/http"
@@ -55,7 +57,25 @@ func downloadToDirectory(url, dir string) error {
return nil
}
// TempDirForURL checks if the passed-in string looks like a URL. If it is,
func stdinToDirectory(dir string) error {
logrus.Debugf("extracting stdin to %q", dir)
r := bufio.NewReader(os.Stdin)
b, err := ioutil.ReadAll(r)
if err != nil {
return errors.Wrapf(err, "Failed to read from stdin")
}
reader := bytes.NewReader(b)
if err := chrootarchive.Untar(reader, dir, nil); err != nil {
dockerfile := filepath.Join(dir, "Dockerfile")
// Assume this is a Dockerfile
if err := ioutil.WriteFile(dockerfile, b, 0600); err != nil {
return errors.Wrapf(err, "Failed to write bytes to %q", dockerfile)
}
}
return nil
}
// TempDirForURL checks if the passed-in string looks like a URL or -. If it is,
// TempDirForURL creates a temporary directory, arranges for its contents to be
// the contents of that URL, and returns the temporary directory's path, along
// with the name of a subdirectory which should be used as the build context
@@ -66,7 +86,8 @@ func TempDirForURL(dir, prefix, url string) (name string, subdir string, err err
if !strings.HasPrefix(url, "http://") &&
!strings.HasPrefix(url, "https://") &&
!strings.HasPrefix(url, "git://") &&
!strings.HasPrefix(url, "github.com/") {
!strings.HasPrefix(url, "github.com/") &&
url != "-" {
return "", "", nil
}
name, err = ioutil.TempDir(dir, prefix)
@@ -76,7 +97,7 @@ func TempDirForURL(dir, prefix, url string) (name string, subdir string, err err
if strings.HasPrefix(url, "git://") || strings.HasSuffix(url, ".git") {
err = cloneToDirectory(url, name)
if err != nil {
if err2 := os.Remove(name); err2 != nil {
if err2 := os.RemoveAll(name); err2 != nil {
logrus.Debugf("error removing temporary directory %q: %v", name, err2)
}
return "", "", err
@@ -92,13 +113,24 @@ func TempDirForURL(dir, prefix, url string) (name string, subdir string, err err
if strings.HasPrefix(url, "http://") || strings.HasPrefix(url, "https://") {
err = downloadToDirectory(url, name)
if err != nil {
if err2 := os.Remove(name); err2 != nil {
if err2 := os.RemoveAll(name); err2 != nil {
logrus.Debugf("error removing temporary directory %q: %v", name, err2)
}
return "", subdir, err
}
return name, subdir, nil
}
if url == "-" {
err = stdinToDirectory(name)
if err != nil {
if err2 := os.RemoveAll(name); err2 != nil {
logrus.Debugf("error removing temporary directory %q: %v", name, err2)
}
return "", subdir, err
}
logrus.Debugf("Build context is at %q", name)
return name, subdir, nil
}
logrus.Debugf("don't know how to retrieve %q", url)
if err2 := os.Remove(name); err2 != nil {
logrus.Debugf("error removing temporary directory %q: %v", name, err2)