summaryrefslogtreecommitdiff
path: root/pkg/domain/infra
diff options
context:
space:
mode:
authorJhon Honce <jhonce@redhat.com>2020-09-14 13:46:59 -0700
committerJhon Honce <jhonce@redhat.com>2020-09-14 13:46:59 -0700
commit146c68f3acdc01f393a6cfadf9bc98eec3e8de94 (patch)
tree4e6017e6b64d8fef0c2acb6cd0a3f13545f33b8f /pkg/domain/infra
parentfd7cdb25027bb33c33eacb99f1a02838eca5d684 (diff)
downloadpodman-146c68f3acdc01f393a6cfadf9bc98eec3e8de94.tar.gz
podman-146c68f3acdc01f393a6cfadf9bc98eec3e8de94.tar.bz2
podman-146c68f3acdc01f393a6cfadf9bc98eec3e8de94.zip
Refactor API build endpoint to be more compliant
* Refactor/Rename channel.WriteCloser() to encapsulate the channel * Refactor build endpoint to "live" stream buildah output channels over API rather then buffering output * Refactor bindings/tunnel build because endpoint changes * building tar file now in bindings rather then depending on caller * Cleanup initiating extra image engine * Remove setting fields to zero values (less noise in code) * Update tests to support remote builds Fixes #7136 Fixes #7137 Signed-off-by: Jhon Honce <jhonce@redhat.com>
Diffstat (limited to 'pkg/domain/infra')
-rw-r--r--pkg/domain/infra/abi/images.go1
-rw-r--r--pkg/domain/infra/tunnel/images.go92
2 files changed, 3 insertions, 90 deletions
diff --git a/pkg/domain/infra/abi/images.go b/pkg/domain/infra/abi/images.go
index 23aef9573..cc3ec37fb 100644
--- a/pkg/domain/infra/abi/images.go
+++ b/pkg/domain/infra/abi/images.go
@@ -535,6 +535,7 @@ func (ir *ImageEngine) Config(_ context.Context) (*config.Config, error) {
}
func (ir *ImageEngine) Build(ctx context.Context, containerFiles []string, opts entities.BuildOptions) (*entities.BuildReport, error) {
+
id, _, err := ir.Libpod.Build(ctx, opts.BuildOptions, containerFiles...)
if err != nil {
return nil, err
diff --git a/pkg/domain/infra/tunnel/images.go b/pkg/domain/infra/tunnel/images.go
index 185cc2f9a..50b8342a3 100644
--- a/pkg/domain/infra/tunnel/images.go
+++ b/pkg/domain/infra/tunnel/images.go
@@ -1,13 +1,9 @@
package tunnel
import (
- "archive/tar"
- "bytes"
"context"
- "io"
"io/ioutil"
"os"
- "path/filepath"
"strings"
"time"
@@ -18,9 +14,7 @@ import (
"github.com/containers/podman/v2/pkg/domain/entities"
"github.com/containers/podman/v2/pkg/domain/utils"
utils2 "github.com/containers/podman/v2/utils"
- "github.com/containers/storage/pkg/archive"
"github.com/pkg/errors"
- "github.com/sirupsen/logrus"
)
func (ir *ImageEngine) Exists(_ context.Context, nameOrID string) (*entities.BoolReport, error) {
@@ -311,28 +305,8 @@ func (ir *ImageEngine) Config(_ context.Context) (*config.Config, error) {
return config.Default()
}
-func (ir *ImageEngine) Build(ctx context.Context, containerFiles []string, opts entities.BuildOptions) (*entities.BuildReport, error) {
- var tarReader io.Reader
- tarfile, err := archive.Tar(opts.ContextDirectory, 0)
- if err != nil {
- return nil, err
- }
- tarReader = tarfile
- cwd, err := os.Getwd()
- if err != nil {
- return nil, err
- }
- if cwd != opts.ContextDirectory {
- fn := func(h *tar.Header, r io.Reader) (data []byte, update bool, skip bool, err error) {
- h.Name = filepath.Join(filepath.Base(opts.ContextDirectory), h.Name)
- return nil, false, false, nil
- }
- tarReader, err = transformArchive(tarfile, false, fn)
- if err != nil {
- return nil, err
- }
- }
- return images.Build(ir.ClientCxt, containerFiles, opts, tarReader)
+func (ir *ImageEngine) Build(_ context.Context, containerFiles []string, opts entities.BuildOptions) (*entities.BuildReport, error) {
+ return images.Build(ir.ClientCxt, containerFiles, opts)
}
func (ir *ImageEngine) Tree(ctx context.Context, nameOrID string, opts entities.ImageTreeOptions) (*entities.ImageTreeReport, error) {
@@ -346,65 +320,3 @@ func (ir *ImageEngine) Shutdown(_ context.Context) {
func (ir *ImageEngine) Sign(ctx context.Context, names []string, options entities.SignOptions) (*entities.SignReport, error) {
return nil, errors.New("not implemented yet")
}
-
-// Sourced from openshift image builder
-
-// TransformFileFunc is given a chance to transform an arbitrary input file.
-type TransformFileFunc func(h *tar.Header, r io.Reader) (data []byte, update bool, skip bool, err error)
-
-// filterArchive transforms the provided input archive to a new archive,
-// giving the fn a chance to transform arbitrary files.
-func filterArchive(r io.Reader, w io.Writer, fn TransformFileFunc) error {
- tr := tar.NewReader(r)
- tw := tar.NewWriter(w)
-
- var body io.Reader = tr
-
- for {
- h, err := tr.Next()
- if err == io.EOF {
- return tw.Close()
- }
- if err != nil {
- return err
- }
-
- name := h.Name
- data, ok, skip, err := fn(h, tr)
- logrus.Debugf("Transform %q -> %q: data=%t ok=%t skip=%t err=%v", name, h.Name, data != nil, ok, skip, err)
- if err != nil {
- return err
- }
- if skip {
- continue
- }
- if ok {
- h.Size = int64(len(data))
- body = bytes.NewBuffer(data)
- }
- if err := tw.WriteHeader(h); err != nil {
- return err
- }
- if _, err := io.Copy(tw, body); err != nil {
- return err
- }
- }
-}
-
-func transformArchive(r io.Reader, compressed bool, fn TransformFileFunc) (io.Reader, error) {
- var cwe error
- pr, pw := io.Pipe()
- go func() {
- if compressed {
- in, err := archive.DecompressStream(r)
- if err != nil {
- cwe = pw.CloseWithError(err)
- return
- }
- r = in
- }
- err := filterArchive(r, pw, fn)
- cwe = pw.CloseWithError(err)
- }()
- return pr, cwe
-}