mirror of
https://github.com/mudler/luet.git
synced 2025-07-13 15:14:33 +00:00
unpack local image file with prefix file:// (#318)
Co-authored-by: Ettore Di Giacinto <mudler@users.noreply.github.com>
This commit is contained in:
parent
5ee1ff6d5a
commit
d48006af8a
1
.gitignore
vendored
1
.gitignore
vendored
@ -1,4 +1,5 @@
|
|||||||
*.swp
|
*.swp
|
||||||
|
.idea/
|
||||||
luet
|
luet
|
||||||
tests/integration/shunit2
|
tests/integration/shunit2
|
||||||
tests/integration/bin
|
tests/integration/bin
|
||||||
|
@ -20,6 +20,7 @@ import (
|
|||||||
"os"
|
"os"
|
||||||
"path/filepath"
|
"path/filepath"
|
||||||
"runtime"
|
"runtime"
|
||||||
|
"strings"
|
||||||
|
|
||||||
"github.com/docker/docker/api/types"
|
"github.com/docker/docker/api/types"
|
||||||
"github.com/docker/go-units"
|
"github.com/docker/go-units"
|
||||||
@ -34,6 +35,10 @@ import (
|
|||||||
"github.com/spf13/cobra"
|
"github.com/spf13/cobra"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
const (
|
||||||
|
filePrefix = "file://"
|
||||||
|
)
|
||||||
|
|
||||||
func pack(ctx *context.Context, p, dst, imageName, arch, OS string) error {
|
func pack(ctx *context.Context, p, dst, imageName, arch, OS string) error {
|
||||||
|
|
||||||
tempimage, err := ctx.TempFile("tempimage")
|
tempimage, err := ctx.TempFile("tempimage")
|
||||||
@ -126,7 +131,7 @@ func NewUnpackCommand() *cobra.Command {
|
|||||||
RegistryToken: registryToken,
|
RegistryToken: registryToken,
|
||||||
}
|
}
|
||||||
|
|
||||||
if !local {
|
if !local && !strings.HasPrefix(image, filePrefix) {
|
||||||
info, err := docker.DownloadAndExtractDockerImage(util.DefaultContext, image, destination, auth, verify)
|
info, err := docker.DownloadAndExtractDockerImage(util.DefaultContext, image, destination, auth, verify)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
util.DefaultContext.Error(err.Error())
|
util.DefaultContext.Error(err.Error())
|
||||||
|
@ -20,6 +20,10 @@ import (
|
|||||||
"encoding/hex"
|
"encoding/hex"
|
||||||
"net/http"
|
"net/http"
|
||||||
"os"
|
"os"
|
||||||
|
"strings"
|
||||||
|
|
||||||
|
v1 "github.com/google/go-containerregistry/pkg/v1"
|
||||||
|
"github.com/google/go-containerregistry/pkg/v1/tarball"
|
||||||
|
|
||||||
"github.com/containerd/containerd/images"
|
"github.com/containerd/containerd/images"
|
||||||
luetimages "github.com/mudler/luet/pkg/api/core/image"
|
luetimages "github.com/mudler/luet/pkg/api/core/image"
|
||||||
@ -42,6 +46,11 @@ import (
|
|||||||
"github.com/theupdateframework/notary/tuf/data"
|
"github.com/theupdateframework/notary/tuf/data"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
const (
|
||||||
|
filePrefix = "file://"
|
||||||
|
fileImageSeparator = ":/"
|
||||||
|
)
|
||||||
|
|
||||||
// See also https://github.com/docker/cli/blob/88c6089300a82d3373892adf6845a4fed1a4ba8d/cli/command/image/trust.go#L171
|
// See also https://github.com/docker/cli/blob/88c6089300a82d3373892adf6845a4fed1a4ba8d/cli/command/image/trust.go#L171
|
||||||
|
|
||||||
func verifyImage(image string, authConfig *types.AuthConfig) (string, error) {
|
func verifyImage(image string, authConfig *types.AuthConfig) (string, error) {
|
||||||
@ -196,18 +205,26 @@ func DownloadAndExtractDockerImage(ctx luettypes.Context, image, dest string, au
|
|||||||
}
|
}
|
||||||
|
|
||||||
func ExtractDockerImage(ctx luettypes.Context, local, dest string) (*images.Image, error) {
|
func ExtractDockerImage(ctx luettypes.Context, local, dest string) (*images.Image, error) {
|
||||||
|
var img v1.Image
|
||||||
if !fileHelper.Exists(dest) {
|
if !fileHelper.Exists(dest) {
|
||||||
if err := os.MkdirAll(dest, os.ModePerm); err != nil {
|
if err := os.MkdirAll(dest, os.ModePerm); err != nil {
|
||||||
return nil, errors.Wrapf(err, "cannot create destination directory")
|
return nil, errors.Wrapf(err, "cannot create destination directory")
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
ref, err := name.ParseReference(local)
|
var err error
|
||||||
if err != nil {
|
if strings.HasPrefix(local, filePrefix) {
|
||||||
return nil, err
|
parts := strings.Split(local, fileImageSeparator)
|
||||||
|
if len(parts) == 2 && parts[1] != "" {
|
||||||
|
img, err = tarball.ImageFromPath(parts[1], nil)
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
ref, err := name.ParseReference(local)
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
img, err = daemon.Image(ref)
|
||||||
}
|
}
|
||||||
|
|
||||||
img, err := daemon.Image(ref)
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user