Skip to content

Commit

Permalink
d2vm/run: hetzner: convert image to raw if needed
Browse files Browse the repository at this point in the history
Signed-off-by: Adphi <[email protected]>
  • Loading branch information
Adphi committed Sep 10, 2022
1 parent 0192f32 commit 4720b1c
Showing 1 changed file with 18 additions and 1 deletion.
19 changes: 18 additions & 1 deletion cmd/d2vm/run/hetzner.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ import (
"net"
"os"
"os/exec"
"path/filepath"
"runtime"
"time"

Expand All @@ -31,6 +32,8 @@ import (
"github.com/sirupsen/logrus"
"github.com/spf13/cobra"
"github.com/svenwiltink/sparsecat"

exec2 "go.linka.cloud/d2vm/pkg/exec"
)

const (
Expand Down Expand Up @@ -80,7 +83,21 @@ func runHetzner(ctx context.Context, imgPath string, stdin io.Reader, stderr io.
return err
}
if i.Format != "raw" {
return fmt.Errorf("image format must be raw")
logrus.Warnf("image format is %s, expected raw", i.Format)
rawPath := filepath.Join(os.TempDir(), "d2vm", "run", filepath.Base(imgPath)+".raw")
if err := os.MkdirAll(filepath.Dir(rawPath), 0755); err != nil {
return err
}
defer os.RemoveAll(rawPath)
logrus.Infof("converting image to raw: %s", rawPath)
if err := exec2.Run(ctx, "qemu-img", "convert", "-O", "raw", imgPath, rawPath); err != nil {
return err
}
imgPath = rawPath
i, err = ImgInfo(ctx, imgPath)
if err != nil {
return err
}
}
src, err := os.Open(imgPath)
if err != nil {
Expand Down

0 comments on commit 4720b1c

Please sign in to comment.