From b4f8ac0cba9052cacb98a45d3450cd7c7ce34a2d Mon Sep 17 00:00:00 2001 From: Tonis Tiigi Date: Mon, 10 Jul 2017 23:55:04 -0700 Subject: [PATCH] remove unused code Signed-off-by: Tonis Tiigi --- control/control_standalone.go | 77 ------------------------------ control/control_standalone_test.go | 9 ++++ examples/buildkit2/buildkit.go | 8 ---- 3 files changed, 9 insertions(+), 85 deletions(-) diff --git a/control/control_standalone.go b/control/control_standalone.go index 7a974242..f47baae4 100644 --- a/control/control_standalone.go +++ b/control/control_standalone.go @@ -4,13 +4,9 @@ package control import ( "context" - "io" - "io/ioutil" "os" "path/filepath" - "github.com/containerd/containerd/archive" - "github.com/containerd/containerd/archive/compression" "github.com/containerd/containerd/content" "github.com/containerd/containerd/differ" "github.com/containerd/containerd/mount" @@ -18,10 +14,7 @@ import ( ctdsnapshot "github.com/containerd/containerd/snapshot" "github.com/containerd/containerd/snapshot/overlay" "github.com/moby/buildkit/worker/runcworker" - digest "github.com/opencontainers/go-digest" - ocispec "github.com/opencontainers/image-spec/specs-go/v1" "github.com/pkg/errors" - netcontext "golang.org/x/net/context" // TODO: fix ) func NewStandalone(root string) (*Controller, error) { @@ -75,76 +68,6 @@ func newStandalonePullDeps(root string) (*pullDeps, error) { }, nil } -// this should be exposed by containerd -type localApplier struct { - root string - content content.Store -} - -func (a *localApplier) Apply(ctx netcontext.Context, desc ocispec.Descriptor, mounts []mount.Mount) (ocispec.Descriptor, error) { - dir, err := ioutil.TempDir(a.root, "extract-") - if err != nil { - return ocispec.Descriptor{}, errors.Wrap(err, "failed to create temporary directory") - } - defer os.RemoveAll(dir) - if err := mount.MountAll(mounts, dir); err != nil { - return ocispec.Descriptor{}, errors.Wrap(err, "failed to mount") - } - defer mount.Unmount(dir, 0) - - r, err := a.content.Reader(ctx, desc.Digest) - if err != nil { - return ocispec.Descriptor{}, errors.Wrap(err, "failed to get reader from content store") - } - defer r.Close() - - // TODO: only decompress stream if media type is compressed - ds, err := compression.DecompressStream(r) - if err != nil { - return ocispec.Descriptor{}, err - } - defer ds.Close() - - digester := digest.Canonical.Digester() - rc := &readCounter{ - r: io.TeeReader(ds, digester.Hash()), - } - - if _, err := archive.Apply(ctx, dir, rc); err != nil { - return ocispec.Descriptor{}, err - } - - // Read any trailing data - if _, err := io.Copy(ioutil.Discard, rc); err != nil { - return ocispec.Descriptor{}, err - } - - return ocispec.Descriptor{ - MediaType: ocispec.MediaTypeImageLayer, - Digest: digester.Digest(), - Size: rc.c, - }, nil -} - -type readCounter struct { - r io.Reader - c int64 -} - -func (rc *readCounter) Read(p []byte) (n int, err error) { - n, err = rc.r.Read(p) - rc.c += int64(n) - return -} - -type nopCloser struct { - io.Writer -} - -func (n *nopCloser) Close() error { - return nil -} - // this should be supported by containerd. currently packages are unusable without wrapping const dummyNs = "buildkit" diff --git a/control/control_standalone_test.go b/control/control_standalone_test.go index 0c9919cc..7eaf4775 100644 --- a/control/control_standalone_test.go +++ b/control/control_standalone_test.go @@ -4,6 +4,7 @@ package control import ( "bytes" + "io" "io/ioutil" "os" "path/filepath" @@ -152,3 +153,11 @@ func TestControl(t *testing.T) { assert.Equal(t, 1, len(du2)-len(du)) } + +type nopCloser struct { + io.Writer +} + +func (n *nopCloser) Close() error { + return nil +} diff --git a/examples/buildkit2/buildkit.go b/examples/buildkit2/buildkit.go index b3efb643..17ba6fe5 100644 --- a/examples/buildkit2/buildkit.go +++ b/examples/buildkit2/buildkit.go @@ -85,14 +85,6 @@ func buildkit(opt buildOpt) *llb.State { return r.With(copyAll(builddStandalone, "/bin")) } -// goFromGit is a helper for cloning a git repo, checking out a tag and copying -// source directory into -func goFromGit(repo, tag string) llb.StateOption { - return func(s *llb.State) *llb.State { - return s.Run(llb.Shlexf("mkdir -p /go/src/%s", repo)).With(copyFrom(llb.Git(repo, tag), "/.", "/go/src/"+repo+"/")).Reset(s).Dirf("/go/src/%s", repo) - } -} - func copyAll(src *llb.State, destPath string) llb.StateOption { return copyFrom(src, "/.", destPath) }