From 51d6753f7e9220bb4de27ebc27e0735d4cea0cf0 Mon Sep 17 00:00:00 2001 From: Adphi Date: Fri, 5 Aug 2022 11:34:24 +0200 Subject: [PATCH] chore: d2vm/run: cleanup unused code, add source reference Signed-off-by: Adphi --- .gitignore | 1 + cmd/d2vm/run/README.md | 1 + cmd/d2vm/run/metadata.go | 77 ---------------------------------------- cmd/d2vm/run/util.go | 29 --------------- go.mod | 3 +- go.sum | 3 +- 6 files changed, 4 insertions(+), 110 deletions(-) create mode 100644 cmd/d2vm/run/README.md delete mode 100644 cmd/d2vm/run/metadata.go diff --git a/.gitignore b/.gitignore index 9b8164a..ba84458 100644 --- a/.gitignore +++ b/.gitignore @@ -8,3 +8,4 @@ scratch dist/ /d2vm .goreleaser.yaml +images diff --git a/cmd/d2vm/run/README.md b/cmd/d2vm/run/README.md new file mode 100644 index 0000000..0dc516e --- /dev/null +++ b/cmd/d2vm/run/README.md @@ -0,0 +1 @@ +Shamelessly taken from [linuxkit](https://github.com/linuxkit/linuxkit/tree/master/src/cmd/linuxkit) diff --git a/cmd/d2vm/run/metadata.go b/cmd/d2vm/run/metadata.go deleted file mode 100644 index 8ff4371..0000000 --- a/cmd/d2vm/run/metadata.go +++ /dev/null @@ -1,77 +0,0 @@ -package run - -import ( - "fmt" - "os" - "path/filepath" - - "github.com/rn/iso9660wrap" - log "github.com/sirupsen/logrus" -) - -// WriteMetadataISO writes a metadata ISO file in a format usable by pkg/metadata -func WriteMetadataISO(path string, content []byte) error { - outfh, err := os.OpenFile(path, os.O_CREATE|os.O_WRONLY, 0644) - if err != nil { - return err - } - defer outfh.Close() - - return iso9660wrap.WriteBuffer(outfh, content, "config") -} - -func metadataCreateUsage() { - invoked := filepath.Base(os.Args[0]) - fmt.Printf("USAGE: %s metadata create [file.iso] [metadata]\n\n", invoked) - - fmt.Printf("'file.iso' is the file to create.\n") - fmt.Printf("'metadata' will be written to '/config' in the ISO.\n") - fmt.Printf("This is compatible with the d2vm/metadata package\n") -} - -func metadataCreate(args []string) { - if len(args) != 2 { - metadataCreateUsage() - os.Exit(1) - } - switch args[0] { - case "help", "-h", "-help", "--help": - metadataCreateUsage() - os.Exit(0) - } - - isoImage := args[0] - metadata := args[1] - - if err := WriteMetadataISO(isoImage, []byte(metadata)); err != nil { - log.Fatal("Failed to write user data ISO: ", err) - } -} - -func metadataUsage() { - invoked := filepath.Base(os.Args[0]) - fmt.Printf("USAGE: %s metadata COMMAND [options]\n\n", invoked) - fmt.Printf("Commands:\n") - fmt.Printf(" create Create a metadata ISO\n") -} - -func metadata(args []string) { - if len(args) < 1 { - metadataUsage() - os.Exit(1) - } - switch args[0] { - case "help", "-h", "-help", "--help": - metadataUsage() - os.Exit(0) - } - - switch args[0] { - case "create": - metadataCreate(args[1:]) - default: - fmt.Printf("%q is not a valid metadata command.\n\n", args[0]) - metadataUsage() - os.Exit(1) - } -} diff --git a/cmd/d2vm/run/util.go b/cmd/d2vm/run/util.go index 9215fba..c6ea9b5 100644 --- a/cmd/d2vm/run/util.go +++ b/cmd/d2vm/run/util.go @@ -17,9 +17,7 @@ package run import ( "bufio" "fmt" - "io/ioutil" "os" - "path/filepath" "strconv" "strings" ) @@ -276,30 +274,3 @@ func NewPublishedPort(publish string) (PublishedPort, error) { p.Protocol = protocol return p, nil } - -// CreateMetadataISO writes the provided meta data to an iso file in the given state directory -func CreateMetadataISO(state, data string, dataPath string) ([]string, error) { - var d []byte - - // if we have neither data nor dataPath, nothing to return - switch { - case data != "" && dataPath != "": - return nil, fmt.Errorf("Cannot specify options for both data and dataPath") - case data == "" && dataPath == "": - return []string{}, nil - case data != "": - d = []byte(data) - case dataPath != "": - var err error - d, err = ioutil.ReadFile(dataPath) - if err != nil { - return nil, fmt.Errorf("Cannot read user data from path %s: %v", dataPath, err) - } - } - - isoPath := filepath.Join(state, "data.iso") - if err := WriteMetadataISO(isoPath, d); err != nil { - return nil, fmt.Errorf("Cannot write user data ISO: %v", err) - } - return []string{isoPath}, nil -} diff --git a/go.mod b/go.mod index 242d11c..7e7c6a9 100644 --- a/go.mod +++ b/go.mod @@ -8,10 +8,10 @@ require ( github.com/google/go-containerregistry v0.8.0 github.com/google/uuid v1.3.0 github.com/joho/godotenv v1.4.0 - github.com/rn/iso9660wrap v0.0.0-20171120145750-baf8d62ad315 github.com/sirupsen/logrus v1.8.1 github.com/spf13/cobra v1.4.0 github.com/stretchr/testify v1.7.0 + github.com/svenwiltink/sparsecat v1.0.0 go.uber.org/multierr v1.8.0 ) @@ -37,7 +37,6 @@ require ( github.com/pkg/errors v0.9.1 // indirect github.com/pmezard/go-difflib v1.0.0 // 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 go.uber.org/atomic v1.7.0 // indirect golang.org/x/sync v0.0.0-20210220032951-036812b2e83c // indirect diff --git a/go.sum b/go.sum index 64e566d..c37bb8b 100644 --- a/go.sum +++ b/go.sum @@ -680,8 +680,6 @@ github.com/prometheus/procfs v0.1.3/go.mod h1:lV6e/gmhEcM9IjHGsFOCxxuZ+z1YqCvr4O github.com/prometheus/procfs v0.2.0/go.mod h1:lV6e/gmhEcM9IjHGsFOCxxuZ+z1YqCvr4OA4YeYWdaU= github.com/prometheus/procfs v0.6.0/go.mod h1:cz+aTbrPOrUb4q7XlbU9ygM+/jj0fzG6c1xBZuNvfVA= github.com/prometheus/tsdb v0.7.1/go.mod h1:qhTCs0VvXwvX/y3TZrWD7rabWM+ijKTux40TwIPHuXU= -github.com/rn/iso9660wrap v0.0.0-20171120145750-baf8d62ad315 h1:DjbO/+j3556fy07xoEM/MyLYN3WwwYyt4dHRC5U+KN8= -github.com/rn/iso9660wrap v0.0.0-20171120145750-baf8d62ad315/go.mod h1:qrZfINtl+sTGgS3elQWqWsD2Ke4Il5jDzBr2Q+lzuuE= github.com/rogpeppe/fastuuid v0.0.0-20150106093220-6724a57986af/go.mod h1:XWv6SoW27p1b0cqNHllgS5HIMJraePCO15w5zCzIWYg= github.com/rogpeppe/fastuuid v1.2.0/go.mod h1:jVj6XXZzXRy/MSR5jhDC/2q6DgLz+nrA6LYCDYWNEvQ= github.com/rogpeppe/go-internal v1.3.0/go.mod h1:M8bDsm7K2OlrFYOpmOWEs/qY81heoFRclV5y23lUDJ4= @@ -1032,6 +1030,7 @@ golang.org/x/sys v0.0.0-20210423082822-04245dca01da/go.mod h1:h1NjWce9XRLGQEsW7w golang.org/x/sys v0.0.0-20210426230700-d19ff857e887/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= golang.org/x/sys v0.0.0-20210510120138-977fb7262007/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.org/x/sys v0.0.0-20210514084401-e8d321eab015/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= +golang.org/x/sys v0.0.0-20210601080250-7ecdf8ef093b/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.org/x/sys v0.0.0-20210603125802-9665404d3644/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.org/x/sys v0.0.0-20210615035016-665e8c7367d1/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.org/x/sys v0.0.0-20210616094352-59db8d763f22/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=