mirror of
https://github.com/mudler/luet.git
synced 2025-09-12 13:26:16 +00:00
Use API also when pulling from helpers used in client
This commit is contained in:
@@ -81,7 +81,7 @@ var _ = Describe("Delta", func() {
|
||||
})
|
||||
|
||||
It("Extract all deltas", func() {
|
||||
tmpdir, err := Extract(
|
||||
_, tmpdir, err := Extract(
|
||||
ctx,
|
||||
img2,
|
||||
ExtractDeltaFiles(ctx, diff, []string{}, []string{}),
|
||||
@@ -96,7 +96,7 @@ var _ = Describe("Delta", func() {
|
||||
})
|
||||
|
||||
It("Extract deltas and excludes /usr/local/go", func() {
|
||||
tmpdir, err := Extract(
|
||||
_, tmpdir, err := Extract(
|
||||
ctx,
|
||||
img2,
|
||||
ExtractDeltaFiles(ctx, diff, []string{}, []string{"usr/local/go"}),
|
||||
@@ -106,7 +106,7 @@ var _ = Describe("Delta", func() {
|
||||
Expect(file.Exists(filepath.Join(tmpdir, "usr", "local", "go"))).To(BeFalse())
|
||||
})
|
||||
It("Extract deltas and excludes /usr/local/go/bin, but includes /usr/local/go", func() {
|
||||
tmpdir, err := Extract(
|
||||
_, tmpdir, err := Extract(
|
||||
ctx,
|
||||
img2,
|
||||
ExtractDeltaFiles(ctx, diff, []string{"usr/local/go"}, []string{"usr/local/go/bin"}),
|
||||
@@ -118,7 +118,7 @@ var _ = Describe("Delta", func() {
|
||||
})
|
||||
|
||||
It("Extract deltas and includes /usr/local/go", func() {
|
||||
tmpdir, err := Extract(
|
||||
_, tmpdir, err := Extract(
|
||||
ctx,
|
||||
img2,
|
||||
ExtractDeltaFiles(ctx, diff, []string{"usr/local/go"}, []string{}),
|
||||
|
@@ -166,7 +166,7 @@ func ExtractFiles(
|
||||
}
|
||||
}
|
||||
|
||||
func ExtractReader(ctx *types.Context, reader io.ReadCloser, output string, filter func(h *tar.Header) (bool, error), opts ...containerdarchive.ApplyOpt) (string, error) {
|
||||
func ExtractReader(ctx *types.Context, reader io.ReadCloser, output string, filter func(h *tar.Header) (bool, error), opts ...containerdarchive.ApplyOpt) (int64, string, error) {
|
||||
defer reader.Close()
|
||||
|
||||
perms := map[string][]int{}
|
||||
@@ -177,17 +177,17 @@ func ExtractReader(ctx *types.Context, reader io.ReadCloser, output string, filt
|
||||
perms[h.Name] = []int{h.Gid, h.Uid}
|
||||
xattrs[h.Name] = h.Xattrs
|
||||
paxrecords[h.Name] = h.PAXRecords
|
||||
|
||||
return filter(h)
|
||||
if filter != nil {
|
||||
return filter(h)
|
||||
}
|
||||
return true, nil
|
||||
}
|
||||
|
||||
if filter != nil {
|
||||
opts = append(opts, containerdarchive.WithFilter(f))
|
||||
}
|
||||
opts = append(opts, containerdarchive.WithFilter(f))
|
||||
|
||||
_, err := containerdarchive.Apply(context.Background(), output, reader, opts...)
|
||||
c, err := containerdarchive.Apply(context.Background(), output, reader, opts...)
|
||||
if err != nil {
|
||||
return "", err
|
||||
return 0, "", err
|
||||
}
|
||||
|
||||
for f, p := range perms {
|
||||
@@ -212,17 +212,17 @@ func ExtractReader(ctx *types.Context, reader io.ReadCloser, output string, filt
|
||||
}
|
||||
}
|
||||
|
||||
return output, nil
|
||||
return c, output, nil
|
||||
}
|
||||
|
||||
func Extract(ctx *types.Context, img v1.Image, filter func(h *tar.Header) (bool, error), opts ...containerdarchive.ApplyOpt) (string, error) {
|
||||
func Extract(ctx *types.Context, img v1.Image, filter func(h *tar.Header) (bool, error), opts ...containerdarchive.ApplyOpt) (int64, string, error) {
|
||||
tmpdiffs, err := ctx.Config.GetSystem().TempDir("extraction")
|
||||
if err != nil {
|
||||
return "", errors.Wrap(err, "Error met while creating tempdir for rootfs")
|
||||
return 0, "", errors.Wrap(err, "Error met while creating tempdir for rootfs")
|
||||
}
|
||||
return ExtractReader(ctx, mutate.Extract(img), tmpdiffs, filter, opts...)
|
||||
}
|
||||
|
||||
func ExtractTo(ctx *types.Context, img v1.Image, output string, filter func(h *tar.Header) (bool, error), opts ...containerdarchive.ApplyOpt) (string, error) {
|
||||
func ExtractTo(ctx *types.Context, img v1.Image, output string, filter func(h *tar.Header) (bool, error), opts ...containerdarchive.ApplyOpt) (int64, string, error) {
|
||||
return ExtractReader(ctx, mutate.Extract(img), output, filter, opts...)
|
||||
}
|
||||
|
@@ -55,7 +55,7 @@ var _ = Describe("Extract", func() {
|
||||
})
|
||||
|
||||
It("Extract all files", func() {
|
||||
tmpdir, err := Extract(
|
||||
_, tmpdir, err := Extract(
|
||||
ctx,
|
||||
img,
|
||||
ExtractFiles(ctx, "", []string{}, []string{}),
|
||||
@@ -68,7 +68,7 @@ var _ = Describe("Extract", func() {
|
||||
})
|
||||
|
||||
It("Extract specific dir", func() {
|
||||
tmpdir, err := Extract(
|
||||
_, tmpdir, err := Extract(
|
||||
ctx,
|
||||
img,
|
||||
ExtractFiles(ctx, "/usr", []string{}, []string{}),
|
||||
@@ -81,7 +81,7 @@ var _ = Describe("Extract", func() {
|
||||
})
|
||||
|
||||
It("Extract a dir with includes/excludes", func() {
|
||||
tmpdir, err := Extract(
|
||||
_, tmpdir, err := Extract(
|
||||
ctx,
|
||||
img,
|
||||
ExtractFiles(ctx, "/usr", []string{"bin"}, []string{"sbin"}),
|
||||
@@ -95,7 +95,7 @@ var _ = Describe("Extract", func() {
|
||||
})
|
||||
|
||||
It("Extract with includes/excludes", func() {
|
||||
tmpdir, err := Extract(
|
||||
_, tmpdir, err := Extract(
|
||||
ctx,
|
||||
img,
|
||||
ExtractFiles(ctx, "", []string{"/usr|/usr/bin"}, []string{"^/bin"}),
|
||||
|
@@ -68,7 +68,7 @@ type PackageArtifact struct {
|
||||
}
|
||||
|
||||
func ImageToArtifact(ctx *types.Context, img v1.Image, t compression.Implementation, output string, filter func(h *tar.Header) (bool, error)) (*PackageArtifact, error) {
|
||||
tmpdiffs, err := image.Extract(ctx, img, filter)
|
||||
_, tmpdiffs, err := image.Extract(ctx, img, filter)
|
||||
if err != nil {
|
||||
return nil, errors.Wrap(err, "Error met while creating tempdir for rootfs")
|
||||
}
|
||||
|
@@ -20,6 +20,7 @@ import (
|
||||
"os"
|
||||
"path/filepath"
|
||||
|
||||
"github.com/mudler/luet/pkg/api/core/image"
|
||||
"github.com/mudler/luet/pkg/api/core/types"
|
||||
. "github.com/mudler/luet/pkg/api/core/types/artifact"
|
||||
. "github.com/mudler/luet/pkg/compiler/backend"
|
||||
@@ -155,7 +156,19 @@ RUN echo bar > /test2`))
|
||||
Expect(err).ToNot(HaveOccurred())
|
||||
defer os.RemoveAll(result) // clean up
|
||||
|
||||
err = b.ExtractRootfs(backend.Options{ImageName: resultingImage, Destination: result}, false)
|
||||
img, err := b.ImageReference(resultingImage)
|
||||
Expect(err).ToNot(HaveOccurred())
|
||||
_, _, err = image.ExtractTo(
|
||||
ctx,
|
||||
img,
|
||||
resultingImage,
|
||||
image.ExtractFiles(
|
||||
ctx,
|
||||
"",
|
||||
[]string{},
|
||||
[]string{},
|
||||
),
|
||||
)
|
||||
Expect(err).ToNot(HaveOccurred())
|
||||
|
||||
content, err := ioutil.ReadFile(filepath.Join(result, "test"))
|
||||
@@ -197,7 +210,19 @@ RUN echo bar > /test2`))
|
||||
Expect(err).ToNot(HaveOccurred())
|
||||
defer os.RemoveAll(result) // clean up
|
||||
|
||||
err = b.ExtractRootfs(backend.Options{ImageName: resultingImage, Destination: result}, false)
|
||||
img, err := b.ImageReference(resultingImage)
|
||||
Expect(err).ToNot(HaveOccurred())
|
||||
_, _, err = image.ExtractTo(
|
||||
ctx,
|
||||
img,
|
||||
resultingImage,
|
||||
image.ExtractFiles(
|
||||
ctx,
|
||||
"",
|
||||
[]string{},
|
||||
[]string{},
|
||||
),
|
||||
)
|
||||
Expect(err).ToNot(HaveOccurred())
|
||||
|
||||
Expect(fileHelper.DirectoryIsEmpty(result)).To(BeFalse())
|
||||
|
Reference in New Issue
Block a user