mirror of
https://github.com/mudler/luet.git
synced 2025-09-08 18:49:39 +00:00
Add crane-based methods for extraction
- create a new api package to encapsulate image manipulation - use new api method to calculate delta Fixes #258 Fixes #204 Fixes #90
This commit is contained in:
@@ -20,6 +20,8 @@ import (
|
||||
"os/exec"
|
||||
"strings"
|
||||
|
||||
"github.com/google/go-containerregistry/pkg/crane"
|
||||
v1 "github.com/google/go-containerregistry/pkg/v1"
|
||||
"github.com/mudler/luet/pkg/api/core/types"
|
||||
bus "github.com/mudler/luet/pkg/bus"
|
||||
|
||||
@@ -70,6 +72,29 @@ func (s *SimpleImg) RemoveImage(opts Options) error {
|
||||
return nil
|
||||
}
|
||||
|
||||
func (s *SimpleImg) ImageReference(a string) (v1.Image, error) {
|
||||
|
||||
f, err := s.ctx.Config.GetSystem().TempFile("snapshot")
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
buildarg := []string{"save", a, "-o", f.Name()}
|
||||
s.ctx.Spinner()
|
||||
defer s.ctx.SpinnerStop()
|
||||
|
||||
out, err := exec.Command("img", buildarg...).CombinedOutput()
|
||||
if err != nil {
|
||||
return nil, errors.Wrap(err, "Failed saving image: "+string(out))
|
||||
}
|
||||
|
||||
img, err := crane.Load(f.Name())
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
return img, nil
|
||||
}
|
||||
|
||||
func (s *SimpleImg) DownloadImage(opts Options) error {
|
||||
name := opts.ImageName
|
||||
bus.Manager.Publish(bus.EventImagePrePull, opts)
|
||||
|
Reference in New Issue
Block a user