2
0
mirror of https://github.com/linka-cloud/d2vm.git synced 2025-12-14 15:03:12 +00:00

d2vm: flatten docker image using github.com/google/go-containerregistry

This allows to preserve files like /etc/hostname or /etc/resolv.conf that will otherwise be overriden by running the container to extract rootfs

wip img entrypoint script

Signed-off-by: Adphi <philippe.adrien.nousse@gmail.com>
This commit is contained in:
2022-04-24 15:49:01 +02:00
parent 0c9bfb6dd8
commit 20ba409039
7 changed files with 1664 additions and 65 deletions

View File

@@ -60,24 +60,13 @@ func Convert(ctx context.Context, img string, size int64, password string, outpu
return err
}
defer docker.Cmd(ctx, "image", "rm", imgUUID)
archive := imgUUID + ".tar"
archivePath := filepath.Join(tmpPath, archive)
logrus.Infof("creating root file system archive")
if err := docker.Cmd(ctx, "run", "-d", "--name", imgUUID, imgUUID); err != nil {
return err
}
if err := docker.Cmd(ctx, "export", "--output", archivePath, imgUUID); err != nil {
return err
}
if err := docker.Cmd(ctx, "rm", "-f", imgUUID); err != nil {
return err
}
logrus.Infof("creating vm image")
b, err := NewBuilder(tmpPath, archivePath, "", size, r, format)
logrus.Infof("creating vm image")
b, err := NewBuilder(ctx, tmpPath, imgUUID, "", size, r, format)
if err != nil {
return err
}
defer b.Close()
if err := b.Build(ctx); err != nil {
return err
}