🔧 Extract common func into api function, also set sane defaults

This commit is contained in:
Ettore Di Giacinto
2021-12-28 18:55:59 +01:00
parent 719ef16161
commit 196cdc5cfc
8 changed files with 171 additions and 27 deletions

View File

@@ -18,7 +18,6 @@ package backend
import (
"os/exec"
"github.com/google/go-containerregistry/pkg/crane"
"github.com/mudler/luet/pkg/api/core/types"
"github.com/pkg/errors"
)
@@ -28,13 +27,6 @@ const (
DockerBackend = "docker"
)
func imageAvailable(image string) bool {
// We use crane.insecure as we just check if the image is available
// It's the daemon duty to use it or not based on the host settings
_, err := crane.Digest(image, crane.Insecure)
return err == nil
}
type Options struct {
ImageName string
SourcePath string

View File

@@ -24,6 +24,7 @@ import (
"github.com/google/go-containerregistry/pkg/v1/daemon"
"github.com/google/go-containerregistry/pkg/v1/tarball"
bus "github.com/mudler/luet/pkg/api/core/bus"
"github.com/mudler/luet/pkg/api/core/image"
"github.com/mudler/luet/pkg/api/core/types"
v1 "github.com/google/go-containerregistry/pkg/v1"
@@ -118,7 +119,7 @@ func (s *SimpleDocker) ImageExists(imagename string) bool {
}
func (*SimpleDocker) ImageAvailable(imagename string) bool {
return imageAvailable(imagename)
return image.Available(imagename)
}
func (s *SimpleDocker) RemoveImage(opts Options) error {

View File

@@ -22,6 +22,7 @@ import (
"github.com/google/go-containerregistry/pkg/crane"
v1 "github.com/google/go-containerregistry/pkg/v1"
bus "github.com/mudler/luet/pkg/api/core/bus"
"github.com/mudler/luet/pkg/api/core/image"
"github.com/mudler/luet/pkg/api/core/types"
"github.com/pkg/errors"
@@ -135,7 +136,7 @@ func (s *SimpleImg) CopyImage(src, dst string) error {
}
func (s *SimpleImg) ImageAvailable(imagename string) bool {
return imageAvailable(imagename)
return image.Available(imagename)
}
// ImageExists check if the given image is available locally