mirror of
https://github.com/mudler/luet.git
synced 2025-09-04 00:34:41 +00:00
Compare commits
7 Commits
Author | SHA1 | Date | |
---|---|---|---|
|
ba0551caab | ||
|
44e66cc729 | ||
|
80412e2e5d | ||
|
df2be8acfe | ||
|
a2d91a2aee | ||
|
bb88fe7e9c | ||
|
702a9f17db |
@@ -30,7 +30,7 @@ var cfgFile string
|
|||||||
var Verbose bool
|
var Verbose bool
|
||||||
|
|
||||||
const (
|
const (
|
||||||
LuetCLIVersion = "0.20.8"
|
LuetCLIVersion = "0.20.11"
|
||||||
LuetEnvPrefix = "LUET"
|
LuetEnvPrefix = "LUET"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
55
cmd/util.go
55
cmd/util.go
@@ -19,9 +19,14 @@ import (
|
|||||||
"fmt"
|
"fmt"
|
||||||
"os"
|
"os"
|
||||||
"path/filepath"
|
"path/filepath"
|
||||||
|
"runtime"
|
||||||
|
|
||||||
"github.com/docker/docker/api/types"
|
"github.com/docker/docker/api/types"
|
||||||
"github.com/docker/go-units"
|
"github.com/docker/go-units"
|
||||||
|
"github.com/mudler/luet/pkg/api/core/image"
|
||||||
|
luettypes "github.com/mudler/luet/pkg/api/core/types"
|
||||||
|
fileHelper "github.com/mudler/luet/pkg/helpers/file"
|
||||||
|
"github.com/pkg/errors"
|
||||||
|
|
||||||
"github.com/mudler/luet/cmd/util"
|
"github.com/mudler/luet/cmd/util"
|
||||||
"github.com/mudler/luet/pkg/helpers/docker"
|
"github.com/mudler/luet/pkg/helpers/docker"
|
||||||
@@ -29,6 +34,55 @@ import (
|
|||||||
"github.com/spf13/cobra"
|
"github.com/spf13/cobra"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
func pack(ctx *luettypes.Context, p, dst, imageName, arch, OS string) error {
|
||||||
|
|
||||||
|
tempimage, err := ctx.Config.GetSystem().TempFile("tempimage")
|
||||||
|
if err != nil {
|
||||||
|
return errors.Wrap(err, "error met while creating tempdir for "+p)
|
||||||
|
}
|
||||||
|
defer os.RemoveAll(tempimage.Name()) // clean up
|
||||||
|
|
||||||
|
if err := image.CreateTar(p, tempimage.Name(), imageName, arch, OS); err != nil {
|
||||||
|
return errors.Wrap(err, "could not create image from tar")
|
||||||
|
}
|
||||||
|
|
||||||
|
return fileHelper.CopyFile(tempimage.Name(), dst)
|
||||||
|
}
|
||||||
|
|
||||||
|
func NewPackCommand() *cobra.Command {
|
||||||
|
|
||||||
|
c := &cobra.Command{
|
||||||
|
Use: "pack image src.tar dst.tar",
|
||||||
|
Short: "Pack a standard tar archive as a container image",
|
||||||
|
Long: `Pack creates a tar which can be loaded as an image from a standard flat tar archive, for e.g. with docker load.
|
||||||
|
It doesn't need the docker daemon to run, and allows to override default os/arch:
|
||||||
|
|
||||||
|
luet util pack --os arm64 image:tag src.tar dst.tar
|
||||||
|
`,
|
||||||
|
Args: cobra.MinimumNArgs(3),
|
||||||
|
Run: func(cmd *cobra.Command, args []string) {
|
||||||
|
|
||||||
|
image := args[0]
|
||||||
|
src := args[1]
|
||||||
|
dst := args[2]
|
||||||
|
|
||||||
|
arch, _ := cmd.Flags().GetString("arch")
|
||||||
|
os, _ := cmd.Flags().GetString("os")
|
||||||
|
|
||||||
|
err := pack(util.DefaultContext, src, dst, image, arch, os)
|
||||||
|
if err != nil {
|
||||||
|
util.DefaultContext.Fatal(err.Error())
|
||||||
|
}
|
||||||
|
util.DefaultContext.Info("Image packed as", image)
|
||||||
|
},
|
||||||
|
}
|
||||||
|
|
||||||
|
c.Flags().String("arch", runtime.GOARCH, "Image architecture")
|
||||||
|
c.Flags().String("os", runtime.GOOS, "Image OS")
|
||||||
|
|
||||||
|
return c
|
||||||
|
}
|
||||||
|
|
||||||
func NewUnpackCommand() *cobra.Command {
|
func NewUnpackCommand() *cobra.Command {
|
||||||
|
|
||||||
c := &cobra.Command{
|
c := &cobra.Command{
|
||||||
@@ -102,5 +156,6 @@ func init() {
|
|||||||
|
|
||||||
utilGroup.AddCommand(
|
utilGroup.AddCommand(
|
||||||
NewUnpackCommand(),
|
NewUnpackCommand(),
|
||||||
|
NewPackCommand(),
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
@@ -19,6 +19,7 @@ import (
|
|||||||
"io"
|
"io"
|
||||||
"os"
|
"os"
|
||||||
|
|
||||||
|
containerdCompression "github.com/containerd/containerd/archive/compression"
|
||||||
"github.com/google/go-containerregistry/pkg/name"
|
"github.com/google/go-containerregistry/pkg/name"
|
||||||
v1 "github.com/google/go-containerregistry/pkg/v1"
|
v1 "github.com/google/go-containerregistry/pkg/v1"
|
||||||
"github.com/google/go-containerregistry/pkg/v1/empty"
|
"github.com/google/go-containerregistry/pkg/v1/empty"
|
||||||
@@ -27,13 +28,13 @@ import (
|
|||||||
"github.com/pkg/errors"
|
"github.com/pkg/errors"
|
||||||
)
|
)
|
||||||
|
|
||||||
func imageFromTar(imagename, architecture, OS string, r io.Reader) (name.Reference, v1.Image, error) {
|
func imageFromTar(imagename, architecture, OS string, opener func() (io.ReadCloser, error)) (name.Reference, v1.Image, error) {
|
||||||
newRef, err := name.ParseReference(imagename)
|
newRef, err := name.ParseReference(imagename)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, nil, err
|
return nil, nil, err
|
||||||
}
|
}
|
||||||
|
|
||||||
layer, err := tarball.LayerFromReader(r)
|
layer, err := tarball.LayerFromOpener(opener)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, nil, err
|
return nil, nil, err
|
||||||
}
|
}
|
||||||
@@ -67,28 +68,30 @@ func imageFromTar(imagename, architecture, OS string, r io.Reader) (name.Referen
|
|||||||
|
|
||||||
// CreateTar a imagetarball from a standard tarball
|
// CreateTar a imagetarball from a standard tarball
|
||||||
func CreateTar(srctar, dstimageTar, imagename, architecture, OS string) error {
|
func CreateTar(srctar, dstimageTar, imagename, architecture, OS string) error {
|
||||||
f, err := os.Open(srctar)
|
|
||||||
if err != nil {
|
|
||||||
return errors.Wrap(err, "Cannot open "+srctar)
|
|
||||||
}
|
|
||||||
defer f.Close()
|
|
||||||
|
|
||||||
return CreateTarReader(f, dstimageTar, imagename, architecture, OS)
|
|
||||||
}
|
|
||||||
|
|
||||||
// CreateTarReader a imagetarball from a standard tarball
|
|
||||||
func CreateTarReader(r io.Reader, dstimageTar, imagename, architecture, OS string) error {
|
|
||||||
dstFile, err := os.Create(dstimageTar)
|
dstFile, err := os.Create(dstimageTar)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return errors.Wrap(err, "Cannot create "+dstimageTar)
|
return errors.Wrap(err, "Cannot create "+dstimageTar)
|
||||||
}
|
}
|
||||||
defer dstFile.Close()
|
defer dstFile.Close()
|
||||||
|
|
||||||
newRef, img, err := imageFromTar(imagename, architecture, OS, r)
|
newRef, img, err := imageFromTar(imagename, architecture, OS, func() (io.ReadCloser, error) {
|
||||||
|
f, err := os.Open(srctar)
|
||||||
|
if err != nil {
|
||||||
|
return nil, errors.Wrap(err, "Cannot open "+srctar)
|
||||||
|
}
|
||||||
|
decompressed, err := containerdCompression.DecompressStream(f)
|
||||||
|
if err != nil {
|
||||||
|
return nil, errors.Wrap(err, "Cannot open "+srctar)
|
||||||
|
}
|
||||||
|
|
||||||
|
return decompressed, nil
|
||||||
|
})
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
// NOTE: We might also stream that back to the daemon with daemon.Write(tag, img)
|
// NOTE: We might also stream that back to the daemon with daemon.Write(tag, img)
|
||||||
return tarball.Write(newRef, img, dstFile)
|
return tarball.Write(newRef, img, dstFile)
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@@ -47,7 +47,7 @@ var _ = Describe("Create", func() {
|
|||||||
img, err := b.ImageReference("alpine", false)
|
img, err := b.ImageReference("alpine", false)
|
||||||
Expect(err).ToNot(HaveOccurred())
|
Expect(err).ToNot(HaveOccurred())
|
||||||
|
|
||||||
_, dir, err := Extract(ctx, img, false, nil)
|
_, dir, err := Extract(ctx, img, nil)
|
||||||
Expect(err).ToNot(HaveOccurred())
|
Expect(err).ToNot(HaveOccurred())
|
||||||
|
|
||||||
defer os.RemoveAll(dir)
|
defer os.RemoveAll(dir)
|
||||||
@@ -69,7 +69,7 @@ var _ = Describe("Create", func() {
|
|||||||
img, err = b.ImageReference("testimage", false)
|
img, err = b.ImageReference("testimage", false)
|
||||||
Expect(err).ToNot(HaveOccurred())
|
Expect(err).ToNot(HaveOccurred())
|
||||||
|
|
||||||
_, dir, err = Extract(ctx, img, false, nil)
|
_, dir, err = Extract(ctx, img, nil)
|
||||||
Expect(err).ToNot(HaveOccurred())
|
Expect(err).ToNot(HaveOccurred())
|
||||||
|
|
||||||
defer os.RemoveAll(dir)
|
defer os.RemoveAll(dir)
|
||||||
|
@@ -74,7 +74,6 @@ var _ = Describe("Delta", func() {
|
|||||||
_, tmpdir, err := Extract(
|
_, tmpdir, err := Extract(
|
||||||
ctx,
|
ctx,
|
||||||
img2,
|
img2,
|
||||||
true,
|
|
||||||
f,
|
f,
|
||||||
)
|
)
|
||||||
Expect(err).ToNot(HaveOccurred())
|
Expect(err).ToNot(HaveOccurred())
|
||||||
@@ -94,7 +93,6 @@ var _ = Describe("Delta", func() {
|
|||||||
_, tmpdir, err := Extract(
|
_, tmpdir, err := Extract(
|
||||||
ctx,
|
ctx,
|
||||||
img2,
|
img2,
|
||||||
true,
|
|
||||||
f,
|
f,
|
||||||
)
|
)
|
||||||
Expect(err).ToNot(HaveOccurred())
|
Expect(err).ToNot(HaveOccurred())
|
||||||
@@ -109,7 +107,6 @@ var _ = Describe("Delta", func() {
|
|||||||
_, tmpdir, err := Extract(
|
_, tmpdir, err := Extract(
|
||||||
ctx,
|
ctx,
|
||||||
img2,
|
img2,
|
||||||
true,
|
|
||||||
f,
|
f,
|
||||||
)
|
)
|
||||||
Expect(err).ToNot(HaveOccurred())
|
Expect(err).ToNot(HaveOccurred())
|
||||||
@@ -124,7 +121,6 @@ var _ = Describe("Delta", func() {
|
|||||||
_, tmpdir, err := Extract(
|
_, tmpdir, err := Extract(
|
||||||
ctx,
|
ctx,
|
||||||
img2,
|
img2,
|
||||||
true,
|
|
||||||
f,
|
f,
|
||||||
)
|
)
|
||||||
Expect(err).ToNot(HaveOccurred())
|
Expect(err).ToNot(HaveOccurred())
|
||||||
|
@@ -19,14 +19,11 @@ import (
|
|||||||
"archive/tar"
|
"archive/tar"
|
||||||
"context"
|
"context"
|
||||||
"io"
|
"io"
|
||||||
"io/fs"
|
|
||||||
"os"
|
"os"
|
||||||
"path/filepath"
|
"path/filepath"
|
||||||
"strings"
|
"strings"
|
||||||
"syscall"
|
|
||||||
|
|
||||||
containerdarchive "github.com/containerd/containerd/archive"
|
containerdarchive "github.com/containerd/containerd/archive"
|
||||||
"github.com/docker/docker/pkg/system"
|
|
||||||
v1 "github.com/google/go-containerregistry/pkg/v1"
|
v1 "github.com/google/go-containerregistry/pkg/v1"
|
||||||
"github.com/google/go-containerregistry/pkg/v1/mutate"
|
"github.com/google/go-containerregistry/pkg/v1/mutate"
|
||||||
"github.com/mudler/luet/pkg/api/core/types"
|
"github.com/mudler/luet/pkg/api/core/types"
|
||||||
@@ -196,7 +193,7 @@ func ExtractFiles(
|
|||||||
// ExtractReader perform the extracting action over the io.ReadCloser
|
// ExtractReader perform the extracting action over the io.ReadCloser
|
||||||
// it extracts the files over output. Accepts a filter as an option
|
// it extracts the files over output. Accepts a filter as an option
|
||||||
// and additional containerd Options
|
// and additional containerd Options
|
||||||
func ExtractReader(ctx *types.Context, reader io.ReadCloser, output string, keepPerms bool, filter func(h *tar.Header) (bool, error), opts ...containerdarchive.ApplyOpt) (int64, 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()
|
defer reader.Close()
|
||||||
|
|
||||||
// If no filter is specified, grab all.
|
// If no filter is specified, grab all.
|
||||||
@@ -204,36 +201,7 @@ func ExtractReader(ctx *types.Context, reader io.ReadCloser, output string, keep
|
|||||||
filter = func(h *tar.Header) (bool, error) { return true, nil }
|
filter = func(h *tar.Header) (bool, error) { return true, nil }
|
||||||
}
|
}
|
||||||
|
|
||||||
// Keep records of permissions as we walk the tar
|
opts = append(opts, containerdarchive.WithFilter(filter))
|
||||||
type permData struct {
|
|
||||||
PAX, Xattrs map[string]string
|
|
||||||
Uid, Gid int
|
|
||||||
Name string
|
|
||||||
FileMode fs.FileMode
|
|
||||||
}
|
|
||||||
|
|
||||||
permstore, err := ctx.Config.System.TempDir("permstore")
|
|
||||||
if err != nil {
|
|
||||||
return 0, "", err
|
|
||||||
}
|
|
||||||
perms := NewCache(permstore, 50*1024*1024, 10000)
|
|
||||||
|
|
||||||
f := func(h *tar.Header) (bool, error) {
|
|
||||||
res, err := filter(h)
|
|
||||||
if res {
|
|
||||||
perms.SetValue(h.Name, permData{
|
|
||||||
PAX: h.PAXRecords,
|
|
||||||
Uid: h.Uid, Gid: h.Gid,
|
|
||||||
Xattrs: h.Xattrs,
|
|
||||||
Name: h.Name,
|
|
||||||
FileMode: h.FileInfo().Mode(),
|
|
||||||
})
|
|
||||||
//perms = append(perms, })
|
|
||||||
}
|
|
||||||
return res, err
|
|
||||||
}
|
|
||||||
|
|
||||||
opts = append(opts, containerdarchive.WithFilter(f))
|
|
||||||
|
|
||||||
// Handle the extraction
|
// Handle the extraction
|
||||||
c, err := containerdarchive.Apply(context.Background(), output, reader, opts...)
|
c, err := containerdarchive.Apply(context.Background(), output, reader, opts...)
|
||||||
@@ -241,46 +209,19 @@ func ExtractReader(ctx *types.Context, reader io.ReadCloser, output string, keep
|
|||||||
return 0, "", err
|
return 0, "", err
|
||||||
}
|
}
|
||||||
|
|
||||||
// Reconstruct permissions
|
|
||||||
if keepPerms {
|
|
||||||
ctx.Debug("Reconstructing permissions")
|
|
||||||
perms.All(func(cr CacheResult) {
|
|
||||||
p := &permData{}
|
|
||||||
cr.Unmarshal(p)
|
|
||||||
ff := filepath.Join(output, p.Name)
|
|
||||||
if _, err := os.Lstat(ff); err == nil {
|
|
||||||
if err := os.Lchown(ff, p.Uid, p.Gid); err != nil {
|
|
||||||
ctx.Warning(err, "failed chowning file")
|
|
||||||
}
|
|
||||||
ctx.Debug("Set", p.Name, p.FileMode)
|
|
||||||
if err := os.Chmod(ff, p.FileMode); err != nil {
|
|
||||||
ctx.Warning(err, "failed chmod file")
|
|
||||||
}
|
|
||||||
}
|
|
||||||
for _, attrs := range []map[string]string{p.Xattrs, p.PAX} {
|
|
||||||
for k, attr := range attrs {
|
|
||||||
if err := system.Lsetxattr(ff, k, []byte(attr), 0); err != nil {
|
|
||||||
if errors.Is(err, syscall.ENOTSUP) {
|
|
||||||
ctx.Debug("ignored xattr %s in archive", ff)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
})
|
|
||||||
}
|
|
||||||
return c, output, nil
|
return c, output, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
// Extract is just syntax sugar around ExtractReader. It extracts an image into a dir
|
// Extract is just syntax sugar around ExtractReader. It extracts an image into a dir
|
||||||
func Extract(ctx *types.Context, img v1.Image, keepPerms bool, filter func(h *tar.Header) (bool, error), opts ...containerdarchive.ApplyOpt) (int64, 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")
|
tmpdiffs, err := ctx.Config.GetSystem().TempDir("extraction")
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return 0, "", 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, keepPerms, filter, opts...)
|
return ExtractReader(ctx, mutate.Extract(img), tmpdiffs, filter, opts...)
|
||||||
}
|
}
|
||||||
|
|
||||||
// ExtractTo is just syntax sugar around ExtractReader
|
// ExtractTo is just syntax sugar around ExtractReader
|
||||||
func ExtractTo(ctx *types.Context, img v1.Image, output string, keepPerms bool, filter func(h *tar.Header) (bool, error), opts ...containerdarchive.ApplyOpt) (int64, 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, keepPerms, filter, opts...)
|
return ExtractReader(ctx, mutate.Extract(img), output, filter, opts...)
|
||||||
}
|
}
|
||||||
|
@@ -58,7 +58,6 @@ var _ = Describe("Extract", func() {
|
|||||||
_, tmpdir, err := Extract(
|
_, tmpdir, err := Extract(
|
||||||
ctx,
|
ctx,
|
||||||
img,
|
img,
|
||||||
true,
|
|
||||||
ExtractFiles(ctx, "", []string{}, []string{}),
|
ExtractFiles(ctx, "", []string{}, []string{}),
|
||||||
)
|
)
|
||||||
Expect(err).ToNot(HaveOccurred())
|
Expect(err).ToNot(HaveOccurred())
|
||||||
@@ -72,7 +71,6 @@ var _ = Describe("Extract", func() {
|
|||||||
_, tmpdir, err := Extract(
|
_, tmpdir, err := Extract(
|
||||||
ctx,
|
ctx,
|
||||||
img,
|
img,
|
||||||
true,
|
|
||||||
ExtractFiles(ctx, "/usr", []string{}, []string{}),
|
ExtractFiles(ctx, "/usr", []string{}, []string{}),
|
||||||
)
|
)
|
||||||
Expect(err).ToNot(HaveOccurred())
|
Expect(err).ToNot(HaveOccurred())
|
||||||
@@ -86,7 +84,6 @@ var _ = Describe("Extract", func() {
|
|||||||
_, tmpdir, err := Extract(
|
_, tmpdir, err := Extract(
|
||||||
ctx,
|
ctx,
|
||||||
img,
|
img,
|
||||||
true,
|
|
||||||
ExtractFiles(ctx, "/usr", []string{"bin"}, []string{"sbin"}),
|
ExtractFiles(ctx, "/usr", []string{"bin"}, []string{"sbin"}),
|
||||||
)
|
)
|
||||||
Expect(err).ToNot(HaveOccurred())
|
Expect(err).ToNot(HaveOccurred())
|
||||||
@@ -101,7 +98,6 @@ var _ = Describe("Extract", func() {
|
|||||||
_, tmpdir, err := Extract(
|
_, tmpdir, err := Extract(
|
||||||
ctx,
|
ctx,
|
||||||
img,
|
img,
|
||||||
true,
|
|
||||||
ExtractFiles(ctx, "", []string{"/usr|/usr/bin"}, []string{"^/bin"}),
|
ExtractFiles(ctx, "", []string{"/usr|/usr/bin"}, []string{"^/bin"}),
|
||||||
)
|
)
|
||||||
Expect(err).ToNot(HaveOccurred())
|
Expect(err).ToNot(HaveOccurred())
|
||||||
|
@@ -70,8 +70,8 @@ type PackageArtifact struct {
|
|||||||
Runtime *pkg.DefaultPackage `json:"runtime,omitempty"`
|
Runtime *pkg.DefaultPackage `json:"runtime,omitempty"`
|
||||||
}
|
}
|
||||||
|
|
||||||
func ImageToArtifact(ctx *types.Context, img v1.Image, t compression.Implementation, output string, keepPerms bool, filter func(h *tar.Header) (bool, error)) (*PackageArtifact, error) {
|
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, keepPerms, filter)
|
_, tmpdiffs, err := image.Extract(ctx, img, filter)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, errors.Wrap(err, "Error met while creating tempdir for rootfs")
|
return nil, errors.Wrap(err, "Error met while creating tempdir for rootfs")
|
||||||
}
|
}
|
||||||
@@ -211,16 +211,6 @@ type ImageBuilder interface {
|
|||||||
|
|
||||||
// GenerateFinalImage takes an artifact and builds a Docker image with its content
|
// GenerateFinalImage takes an artifact and builds a Docker image with its content
|
||||||
func (a *PackageArtifact) GenerateFinalImage(ctx *types.Context, imageName string, b ImageBuilder, keepPerms bool) error {
|
func (a *PackageArtifact) GenerateFinalImage(ctx *types.Context, imageName string, b ImageBuilder, keepPerms bool) error {
|
||||||
archiveFile, err := os.Open(a.Path)
|
|
||||||
if err != nil {
|
|
||||||
return errors.Wrap(err, "Cannot open "+a.Path)
|
|
||||||
}
|
|
||||||
defer archiveFile.Close()
|
|
||||||
|
|
||||||
decompressed, err := containerdCompression.DecompressStream(archiveFile)
|
|
||||||
if err != nil {
|
|
||||||
return errors.Wrap(err, "Cannot open "+a.Path)
|
|
||||||
}
|
|
||||||
|
|
||||||
tempimage, err := ctx.Config.GetSystem().TempFile("tempimage")
|
tempimage, err := ctx.Config.GetSystem().TempFile("tempimage")
|
||||||
if err != nil {
|
if err != nil {
|
||||||
@@ -228,7 +218,7 @@ func (a *PackageArtifact) GenerateFinalImage(ctx *types.Context, imageName strin
|
|||||||
}
|
}
|
||||||
defer os.RemoveAll(tempimage.Name()) // clean up
|
defer os.RemoveAll(tempimage.Name()) // clean up
|
||||||
|
|
||||||
if err := image.CreateTarReader(decompressed, tempimage.Name(), imageName, runtime.GOARCH, runtime.GOOS); err != nil {
|
if err := image.CreateTar(a.Path, tempimage.Name(), imageName, runtime.GOARCH, runtime.GOOS); err != nil {
|
||||||
return errors.Wrap(err, "could not create image from tar")
|
return errors.Wrap(err, "could not create image from tar")
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -570,7 +560,7 @@ func (a *PackageArtifact) Unpack(ctx *types.Context, dst string, keepPerms bool)
|
|||||||
// // tarModifier.Modifier()
|
// // tarModifier.Modifier()
|
||||||
// return true, nil
|
// return true, nil
|
||||||
// },
|
// },
|
||||||
_, _, err = image.ExtractReader(ctx, replacerArchive, dst, ctx.Config.GetGeneral().SameOwner, nil)
|
_, _, err = image.ExtractReader(ctx, replacerArchive, dst, nil)
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@@ -161,7 +161,6 @@ RUN echo bar > /test2`))
|
|||||||
ctx,
|
ctx,
|
||||||
img,
|
img,
|
||||||
result,
|
result,
|
||||||
false,
|
|
||||||
nil,
|
nil,
|
||||||
)
|
)
|
||||||
Expect(err).ToNot(HaveOccurred())
|
Expect(err).ToNot(HaveOccurred())
|
||||||
@@ -210,7 +209,6 @@ RUN echo bar > /test2`))
|
|||||||
ctx,
|
ctx,
|
||||||
img,
|
img,
|
||||||
result,
|
result,
|
||||||
false,
|
|
||||||
nil,
|
nil,
|
||||||
)
|
)
|
||||||
Expect(err).ToNot(HaveOccurred())
|
Expect(err).ToNot(HaveOccurred())
|
||||||
|
@@ -255,7 +255,6 @@ func (cs *LuetCompiler) unpackFs(concurrency int, keepPermissions bool, p *compi
|
|||||||
_, rootfs, err := image.Extract(
|
_, rootfs, err := image.Extract(
|
||||||
cs.Options.Context,
|
cs.Options.Context,
|
||||||
img,
|
img,
|
||||||
keepPermissions,
|
|
||||||
image.ExtractFiles(
|
image.ExtractFiles(
|
||||||
cs.Options.Context,
|
cs.Options.Context,
|
||||||
p.GetPackageDir(),
|
p.GetPackageDir(),
|
||||||
@@ -338,7 +337,6 @@ func (cs *LuetCompiler) unpackDelta(concurrency int, keepPermissions bool, p *co
|
|||||||
ref2,
|
ref2,
|
||||||
cs.Options.CompressionType,
|
cs.Options.CompressionType,
|
||||||
p.Rel(fmt.Sprintf("%s%s", p.GetPackage().GetFingerPrint(), ".package.tar")),
|
p.Rel(fmt.Sprintf("%s%s", p.GetPackage().GetFingerPrint(), ".package.tar")),
|
||||||
keepPermissions,
|
|
||||||
filter,
|
filter,
|
||||||
)
|
)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
@@ -494,7 +492,9 @@ func (cs *LuetCompiler) genArtifact(p *compilerspec.LuetCompilationSpec, builder
|
|||||||
}
|
}
|
||||||
cs.Options.Context.Success(pkgTag, " :white_check_mark: done (empty virtual package)")
|
cs.Options.Context.Success(pkgTag, " :white_check_mark: done (empty virtual package)")
|
||||||
if cs.Options.PushFinalImages {
|
if cs.Options.PushFinalImages {
|
||||||
cs.pushFinalArtifact(a, p, keepPermissions)
|
if err := cs.pushFinalArtifact(a, p, keepPermissions); err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
}
|
}
|
||||||
return a, nil
|
return a, nil
|
||||||
}
|
}
|
||||||
@@ -528,7 +528,9 @@ func (cs *LuetCompiler) genArtifact(p *compilerspec.LuetCompilationSpec, builder
|
|||||||
cs.Options.Context.Success(pkgTag, " :white_check_mark: Done building")
|
cs.Options.Context.Success(pkgTag, " :white_check_mark: Done building")
|
||||||
|
|
||||||
if cs.Options.PushFinalImages {
|
if cs.Options.PushFinalImages {
|
||||||
cs.pushFinalArtifact(a, p, keepPermissions)
|
if err := cs.pushFinalArtifact(a, p, keepPermissions); err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return a, nil
|
return a, nil
|
||||||
@@ -553,7 +555,7 @@ func (cs *LuetCompiler) pushFinalArtifact(a *artifact.PackageArtifact, p *compil
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Then the image ID
|
// Then the image ID
|
||||||
metadataImageID := fmt.Sprintf("%s:%s", cs.Options.PushFinalImagesRepository, a.CompileSpec.GetPackage().GetMetadataFilePath())
|
metadataImageID := fmt.Sprintf("%s:%s", cs.Options.PushFinalImagesRepository, helpers.SanitizeImageString(a.CompileSpec.GetPackage().GetMetadataFilePath()))
|
||||||
if !cs.Backend.ImageAvailable(metadataImageID) || cs.Options.PushFinalImagesForce {
|
if !cs.Backend.ImageAvailable(metadataImageID) || cs.Options.PushFinalImagesForce {
|
||||||
cs.Options.Context.Info("Generating metadata image for", a.CompileSpec.Package.HumanReadableString(), metadataImageID)
|
cs.Options.Context.Info("Generating metadata image for", a.CompileSpec.Package.HumanReadableString(), metadataImageID)
|
||||||
|
|
||||||
|
@@ -899,7 +899,7 @@ var _ = Describe("Compiler", func() {
|
|||||||
|
|
||||||
img, err := b.ImageReference(fmt.Sprintf("%s:%s", imageName, artifacts[0].Runtime.ImageID()), true)
|
img, err := b.ImageReference(fmt.Sprintf("%s:%s", imageName, artifacts[0].Runtime.ImageID()), true)
|
||||||
Expect(err).ToNot(HaveOccurred())
|
Expect(err).ToNot(HaveOccurred())
|
||||||
_, path, err := image.Extract(ctx, img, false, nil)
|
_, path, err := image.Extract(ctx, img, nil)
|
||||||
Expect(err).ToNot(HaveOccurred())
|
Expect(err).ToNot(HaveOccurred())
|
||||||
defer os.RemoveAll(path) // clean up
|
defer os.RemoveAll(path) // clean up
|
||||||
|
|
||||||
@@ -907,7 +907,7 @@ var _ = Describe("Compiler", func() {
|
|||||||
|
|
||||||
img, err = b.ImageReference(fmt.Sprintf("%s:%s", imageName, artifacts[1].Runtime.GetMetadataFilePath()), true)
|
img, err = b.ImageReference(fmt.Sprintf("%s:%s", imageName, artifacts[1].Runtime.GetMetadataFilePath()), true)
|
||||||
Expect(err).ToNot(HaveOccurred())
|
Expect(err).ToNot(HaveOccurred())
|
||||||
_, path, err = image.Extract(ctx, img, false, nil)
|
_, path, err = image.Extract(ctx, img, nil)
|
||||||
Expect(err).ToNot(HaveOccurred())
|
Expect(err).ToNot(HaveOccurred())
|
||||||
defer os.RemoveAll(path) // clean up
|
defer os.RemoveAll(path) // clean up
|
||||||
|
|
||||||
|
@@ -174,7 +174,6 @@ func DownloadAndExtractDockerImage(ctx *luettypes.Context, image, dest string, a
|
|||||||
ctx,
|
ctx,
|
||||||
img,
|
img,
|
||||||
dest,
|
dest,
|
||||||
true,
|
|
||||||
nil,
|
nil,
|
||||||
)
|
)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
@@ -204,7 +204,6 @@ func (d *dockerRepositoryGenerator) Generate(r *LuetSystemRepository, imagePrefi
|
|||||||
d.context,
|
d.context,
|
||||||
img,
|
img,
|
||||||
repoTemp,
|
repoTemp,
|
||||||
d.context.Config.GetGeneral().SameOwner,
|
|
||||||
nil,
|
nil,
|
||||||
)
|
)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
Reference in New Issue
Block a user