mirror of
https://github.com/linka-cloud/d2vm.git
synced 2024-11-26 17:46:24 +00:00
output defaults to raw
move image using sparsecat print command in debug mode Signed-off-by: Adphi <philippe.adrien.nousse@gmail.com>
This commit is contained in:
parent
bdee0559d4
commit
9020cb0579
@ -153,7 +153,7 @@ func NewBuilder(ctx context.Context, workdir, imgTag, disk string, size int64, o
|
|||||||
b := &builder{
|
b := &builder{
|
||||||
osRelease: osRelease,
|
osRelease: osRelease,
|
||||||
img: img,
|
img: img,
|
||||||
diskRaw: filepath.Join(workdir, disk+".raw"),
|
diskRaw: filepath.Join(workdir, disk+".d2vm.raw"),
|
||||||
diskOut: filepath.Join(workdir, disk+"."+format),
|
diskOut: filepath.Join(workdir, disk+"."+format),
|
||||||
format: f,
|
format: f,
|
||||||
size: size,
|
size: size,
|
||||||
|
@ -65,7 +65,7 @@ func init() {
|
|||||||
buildCmd.Flags().StringVarP(&file, "file", "f", "", "Name of the Dockerfile")
|
buildCmd.Flags().StringVarP(&file, "file", "f", "", "Name of the Dockerfile")
|
||||||
buildCmd.Flags().StringArrayVar(&buildArgs, "build-arg", nil, "Set build-time variables")
|
buildCmd.Flags().StringArrayVar(&buildArgs, "build-arg", nil, "Set build-time variables")
|
||||||
|
|
||||||
buildCmd.Flags().StringVarP(&output, "output", "o", output, "The output image, the extension determine the image format. Supported formats: "+strings.Join(d2vm.OutputFormats(), " "))
|
buildCmd.Flags().StringVarP(&output, "output", "o", output, "The output image, the extension determine the image format, raw will be used if none. Supported formats: "+strings.Join(d2vm.OutputFormats(), " "))
|
||||||
buildCmd.Flags().StringVarP(&password, "password", "p", "root", "Root user password")
|
buildCmd.Flags().StringVarP(&password, "password", "p", "root", "Root user password")
|
||||||
buildCmd.Flags().StringVarP(&size, "size", "s", "10G", "The output image size")
|
buildCmd.Flags().StringVarP(&size, "size", "s", "10G", "The output image size")
|
||||||
buildCmd.Flags().BoolVarP(&debug, "debug", "d", false, "Enable Debug output")
|
buildCmd.Flags().BoolVarP(&debug, "debug", "d", false, "Enable Debug output")
|
||||||
|
@ -93,7 +93,7 @@ func parseSize(s string) (int64, error) {
|
|||||||
|
|
||||||
func init() {
|
func init() {
|
||||||
convertCmd.Flags().BoolVar(&pull, "pull", false, "Always pull docker image")
|
convertCmd.Flags().BoolVar(&pull, "pull", false, "Always pull docker image")
|
||||||
convertCmd.Flags().StringVarP(&output, "output", "o", output, "The output image, the extension determine the image format. Supported formats: "+strings.Join(d2vm.OutputFormats(), " "))
|
convertCmd.Flags().StringVarP(&output, "output", "o", output, "The output image, the extension determine the image format, raw will be used if none. Supported formats: "+strings.Join(d2vm.OutputFormats(), " "))
|
||||||
convertCmd.Flags().StringVarP(&password, "password", "p", "root", "The Root user password")
|
convertCmd.Flags().StringVarP(&password, "password", "p", "root", "The Root user password")
|
||||||
convertCmd.Flags().StringVarP(&size, "size", "s", "10G", "The output image size")
|
convertCmd.Flags().StringVarP(&size, "size", "s", "10G", "The output image size")
|
||||||
convertCmd.Flags().BoolVarP(&debug, "debug", "d", false, "Enable Debug output")
|
convertCmd.Flags().BoolVarP(&debug, "debug", "d", false, "Enable Debug output")
|
||||||
|
@ -17,13 +17,13 @@ package d2vm
|
|||||||
import (
|
import (
|
||||||
"context"
|
"context"
|
||||||
"fmt"
|
"fmt"
|
||||||
"io"
|
|
||||||
"os"
|
"os"
|
||||||
"path/filepath"
|
"path/filepath"
|
||||||
"strings"
|
"strings"
|
||||||
|
|
||||||
"github.com/google/uuid"
|
"github.com/google/uuid"
|
||||||
"github.com/sirupsen/logrus"
|
"github.com/sirupsen/logrus"
|
||||||
|
"github.com/svenwiltink/sparsecat"
|
||||||
|
|
||||||
"go.linka.cloud/d2vm/pkg/docker"
|
"go.linka.cloud/d2vm/pkg/docker"
|
||||||
)
|
)
|
||||||
@ -64,6 +64,9 @@ func Convert(ctx context.Context, img string, size int64, password string, outpu
|
|||||||
|
|
||||||
logrus.Infof("creating vm image")
|
logrus.Infof("creating vm image")
|
||||||
format := strings.TrimPrefix(filepath.Ext(output), ".")
|
format := strings.TrimPrefix(filepath.Ext(output), ".")
|
||||||
|
if format == "" {
|
||||||
|
format = "raw"
|
||||||
|
}
|
||||||
b, err := NewBuilder(ctx, tmpPath, imgUUID, "", size, r, format)
|
b, err := NewBuilder(ctx, tmpPath, imgUUID, "", size, r, format)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
@ -92,7 +95,7 @@ func MoveFile(sourcePath, destPath string) error {
|
|||||||
return fmt.Errorf("failed to open dest file: %s", err)
|
return fmt.Errorf("failed to open dest file: %s", err)
|
||||||
}
|
}
|
||||||
defer outputFile.Close()
|
defer outputFile.Close()
|
||||||
_, err = io.Copy(outputFile, inputFile)
|
_, err = sparsecat.NewDecoder(sparsecat.NewEncoder(inputFile)).WriteTo(outputFile)
|
||||||
inputFile.Close()
|
inputFile.Close()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return fmt.Errorf("failed to write to output file: %s", err)
|
return fmt.Errorf("failed to write to output file: %s", err)
|
||||||
|
1
go.mod
1
go.mod
@ -37,6 +37,7 @@ require (
|
|||||||
github.com/pkg/errors v0.9.1 // indirect
|
github.com/pkg/errors v0.9.1 // indirect
|
||||||
github.com/pmezard/go-difflib v1.0.0 // indirect
|
github.com/pmezard/go-difflib v1.0.0 // indirect
|
||||||
github.com/spf13/pflag v1.0.5 // indirect
|
github.com/spf13/pflag v1.0.5 // indirect
|
||||||
|
github.com/svenwiltink/sparsecat v1.0.0 // indirect
|
||||||
github.com/vbatts/tar-split v0.11.2 // indirect
|
github.com/vbatts/tar-split v0.11.2 // indirect
|
||||||
go.uber.org/atomic v1.7.0 // indirect
|
go.uber.org/atomic v1.7.0 // indirect
|
||||||
golang.org/x/sync v0.0.0-20210220032951-036812b2e83c // indirect
|
golang.org/x/sync v0.0.0-20210220032951-036812b2e83c // indirect
|
||||||
|
2
go.sum
2
go.sum
@ -743,6 +743,8 @@ github.com/stretchr/testify v1.6.1/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/
|
|||||||
github.com/stretchr/testify v1.7.0 h1:nwc3DEeHmmLAfoZucVR881uASk0Mfjw8xYJ99tb5CcY=
|
github.com/stretchr/testify v1.7.0 h1:nwc3DEeHmmLAfoZucVR881uASk0Mfjw8xYJ99tb5CcY=
|
||||||
github.com/stretchr/testify v1.7.0/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg=
|
github.com/stretchr/testify v1.7.0/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg=
|
||||||
github.com/subosito/gotenv v1.2.0/go.mod h1:N0PQaV/YGNqwC0u51sEeR/aUtSLEXKX9iv69rRypqCw=
|
github.com/subosito/gotenv v1.2.0/go.mod h1:N0PQaV/YGNqwC0u51sEeR/aUtSLEXKX9iv69rRypqCw=
|
||||||
|
github.com/svenwiltink/sparsecat v1.0.0 h1:SBDEIImxhD//8MskqodFR9VcixWKkZAPAW35nmA4vcw=
|
||||||
|
github.com/svenwiltink/sparsecat v1.0.0/go.mod h1:TdtvJbeTZcd+3cMQpttW6MJl/iPGZT0GHmckep0hoxU=
|
||||||
github.com/syndtr/gocapability v0.0.0-20170704070218-db04d3cc01c8/go.mod h1:hkRG7XYTFWNJGYcbNJQlaLq0fg1yr4J4t/NcTQtrfww=
|
github.com/syndtr/gocapability v0.0.0-20170704070218-db04d3cc01c8/go.mod h1:hkRG7XYTFWNJGYcbNJQlaLq0fg1yr4J4t/NcTQtrfww=
|
||||||
github.com/syndtr/gocapability v0.0.0-20180916011248-d98352740cb2/go.mod h1:hkRG7XYTFWNJGYcbNJQlaLq0fg1yr4J4t/NcTQtrfww=
|
github.com/syndtr/gocapability v0.0.0-20180916011248-d98352740cb2/go.mod h1:hkRG7XYTFWNJGYcbNJQlaLq0fg1yr4J4t/NcTQtrfww=
|
||||||
github.com/syndtr/gocapability v0.0.0-20200815063812-42c35b437635/go.mod h1:hkRG7XYTFWNJGYcbNJQlaLq0fg1yr4J4t/NcTQtrfww=
|
github.com/syndtr/gocapability v0.0.0-20200815063812-42c35b437635/go.mod h1:hkRG7XYTFWNJGYcbNJQlaLq0fg1yr4J4t/NcTQtrfww=
|
||||||
|
@ -38,6 +38,7 @@ func SetDebug(debug bool) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func RunStdout(ctx context.Context, c string, args ...string) error {
|
func RunStdout(ctx context.Context, c string, args ...string) error {
|
||||||
|
fmt.Printf("\n$ %s %s\n", c, strings.Join(args, " "))
|
||||||
cmd := exec.CommandContext(ctx, c, args...)
|
cmd := exec.CommandContext(ctx, c, args...)
|
||||||
cmd.Stdout = os.Stdout
|
cmd.Stdout = os.Stdout
|
||||||
cmd.Stderr = os.Stderr
|
cmd.Stderr = os.Stderr
|
||||||
|
Loading…
Reference in New Issue
Block a user