mirror of
https://github.com/mudler/luet.git
synced 2025-09-02 15:54:39 +00:00
Backend nows must expose a way to unpack rootfs of images
This commit is contained in:
@@ -17,9 +17,16 @@ package backend
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
"io/ioutil"
|
||||
"os"
|
||||
"os/exec"
|
||||
"path/filepath"
|
||||
"strings"
|
||||
|
||||
capi "github.com/mudler/docker-companion/api"
|
||||
|
||||
"github.com/mudler/luet/pkg/compiler"
|
||||
"github.com/mudler/luet/pkg/helpers"
|
||||
. "github.com/mudler/luet/pkg/logger"
|
||||
|
||||
"github.com/pkg/errors"
|
||||
@@ -94,6 +101,71 @@ func (*SimpleDocker) ExportImage(opts compiler.CompilerBackendOptions) error {
|
||||
return nil
|
||||
}
|
||||
|
||||
type ManifestEntry struct {
|
||||
Layers []string `json:"Layers"`
|
||||
}
|
||||
|
||||
func (*SimpleDocker) ExtractRootfs(opts compiler.CompilerBackendOptions, keepPerms bool) error {
|
||||
src := opts.SourcePath
|
||||
dst := opts.Destination
|
||||
|
||||
rootfs, err := ioutil.TempDir(os.TempDir(), "rootfs")
|
||||
if err != nil {
|
||||
return errors.Wrap(err, "Error met while creating tempdir for rootfs")
|
||||
}
|
||||
defer os.RemoveAll(rootfs) // clean up
|
||||
|
||||
// TODO: Following as option if archive as output?
|
||||
// archive, err := ioutil.TempDir(os.TempDir(), "archive")
|
||||
// if err != nil {
|
||||
// return nil, errors.Wrap(err, "Error met while creating tempdir for rootfs")
|
||||
// }
|
||||
// defer os.RemoveAll(archive) // clean up
|
||||
|
||||
err = helpers.Untar(src, rootfs, keepPerms)
|
||||
if err != nil {
|
||||
return errors.Wrap(err, "Error met while unpacking rootfs")
|
||||
}
|
||||
|
||||
manifest, err := helpers.Read(filepath.Join(rootfs, "manifest.json"))
|
||||
if err != nil {
|
||||
return errors.Wrap(err, "Error met while reading image manifest")
|
||||
}
|
||||
|
||||
// Unpack all layers
|
||||
var manifestData []ManifestEntry
|
||||
|
||||
if err := json.Unmarshal([]byte(manifest), &manifestData); err != nil {
|
||||
return errors.Wrap(err, "Error met while unmarshalling manifest")
|
||||
}
|
||||
|
||||
layers_sha := []string{}
|
||||
|
||||
if len(manifestData) != 1 {
|
||||
return errors.New("Manifest should have one entry")
|
||||
}
|
||||
for _, l := range manifestData[0].Layers {
|
||||
layers_sha = append(layers_sha, strings.Replace(l, "/layer.tar", "", -1))
|
||||
}
|
||||
|
||||
export, err := capi.CreateExport(rootfs)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
err = export.UnPackLayers(layers_sha, dst, "")
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
// err = helpers.Tar(archive, dst)
|
||||
// if err != nil {
|
||||
// return nil, errors.Wrap(err, "Error met while creating package archive")
|
||||
// }
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
// container-diff diff daemon://luet/base alpine --type=file -j
|
||||
// [
|
||||
// {
|
||||
|
@@ -91,6 +91,9 @@ func (*SimpleImg) ExportImage(opts compiler.CompilerBackendOptions) error {
|
||||
}
|
||||
|
||||
// TODO: Dup in docker, refactor common code in helpers for shared parts
|
||||
func (*SimpleImg) ExtractRootfs(opts compiler.CompilerBackendOptions, keepPerms bool) error {
|
||||
return errors.New("Not implemented")
|
||||
}
|
||||
|
||||
// TODO: Use container-diff (https://github.com/GoogleContainerTools/container-diff) for checking out layer diffs
|
||||
// Changes uses container-diff (https://github.com/GoogleContainerTools/container-diff) for retrieving out layer diffs
|
||||
|
@@ -40,6 +40,7 @@ type CompilerBackend interface {
|
||||
RemoveImage(CompilerBackendOptions) error
|
||||
Changes(fromImage, toImage string) ([]ArtifactLayer, error)
|
||||
ImageDefinitionToTar(CompilerBackendOptions) error
|
||||
ExtractRootfs(opts CompilerBackendOptions, keepPerms bool) error
|
||||
}
|
||||
|
||||
type Artifact interface {
|
||||
|
Reference in New Issue
Block a user