2
0
mirror of https://github.com/linka-cloud/d2vm.git synced 2024-11-22 15:56:24 +00:00

chore: d2vm/run: cleanup unused code, add source reference

Signed-off-by: Adphi <philippe.adrien.nousse@gmail.com>
This commit is contained in:
Adphi 2022-08-05 11:34:24 +02:00
parent bbf415854f
commit 51d6753f7e
Signed by: adphi
GPG Key ID: F2159213400E50AB
6 changed files with 4 additions and 110 deletions

1
.gitignore vendored
View File

@ -8,3 +8,4 @@ scratch
dist/
/d2vm
.goreleaser.yaml
images

1
cmd/d2vm/run/README.md Normal file
View File

@ -0,0 +1 @@
Shamelessly taken from [linuxkit](https://github.com/linuxkit/linuxkit/tree/master/src/cmd/linuxkit)

View File

@ -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)
}
}

View File

@ -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
}

3
go.mod
View File

@ -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

3
go.sum
View File

@ -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=