commit
976478194e
|
@ -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"
|
||||
|
||||
|
|
|
@ -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
|
||||
}
|
||||
|
|
|
@ -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)
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue