From 3940cd89752f9f9df071ed5c455aae976d545e58 Mon Sep 17 00:00:00 2001 From: Adphi Date: Mon, 12 Sep 2022 11:19:51 +0200 Subject: [PATCH] BREAKING CHANGE: remove root default password, configure it only if provided (close #7) Signed-off-by: Adphi --- Makefile | 4 ++-- README.md | 2 -- cmd/d2vm/build.go | 2 +- cmd/d2vm/convert.go | 2 +- cmd/d2vm/main.go | 2 +- cmd/d2vm/run/qemu.go | 4 ++-- cmd/d2vm/run/vbox.go | 16 ++++++++++------ dockerfile.go | 3 --- 8 files changed, 17 insertions(+), 18 deletions(-) diff --git a/Makefile b/Makefile index 5adb8e1..0800a77 100644 --- a/Makefile +++ b/Makefile @@ -114,10 +114,10 @@ examples: build-dev @mkdir -p examples/build @for f in $$(find examples -type f -name '*Dockerfile' -maxdepth 1); do \ echo "Building $$f"; \ - ./d2vm build -o examples/build/$$(basename $$f|cut -d'.' -f1).qcow2 -f $$f examples; \ + ./d2vm build -o examples/build/$$(basename $$f|cut -d'.' -f1).qcow2 -p root -f $$f examples --force; \ done @echo "Building examples/full/Dockerfile" - @./d2vm build -o examples/build/full.qcow2 --build-arg=USER=adphi --build-arg=PASSWORD=adphi examples/full + @./d2vm build -o examples/build/full.qcow2 --build-arg=USER=adphi --build-arg=PASSWORD=adphi examples/full --force cli-docs: .build @rm -rf $(CLI_REFERENCE_PATH) diff --git a/README.md b/README.md index 048518d..48603a3 100644 --- a/README.md +++ b/README.md @@ -239,8 +239,6 @@ RUN apt update && apt install -y openssh-server && \ ``` -When building the vm image, *d2vm* will create a root password, so there is no need to configure it now. - Build the vm image: The *build* command take most of its flags and arguments from the *docker build* command. diff --git a/cmd/d2vm/build.go b/cmd/d2vm/build.go index 868da52..602115a 100644 --- a/cmd/d2vm/build.go +++ b/cmd/d2vm/build.go @@ -117,7 +117,7 @@ func init() { 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, 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", "", "Optional root user password") buildCmd.Flags().StringVarP(&size, "size", "s", "10G", "The output image size") buildCmd.Flags().BoolVar(&force, "force", false, "Override output image") buildCmd.Flags().StringVar(&cmdLineExtra, "append-to-cmdline", "", "Extra kernel cmdline arguments to append to the generated one") diff --git a/cmd/d2vm/convert.go b/cmd/d2vm/convert.go index 5c6bb49..80d36a7 100644 --- a/cmd/d2vm/convert.go +++ b/cmd/d2vm/convert.go @@ -111,7 +111,7 @@ func parseSize(s string) (int64, error) { func init() { 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, 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", "", "Optional root user password") convertCmd.Flags().StringVarP(&size, "size", "s", "10G", "The output image size") convertCmd.Flags().BoolVarP(&force, "force", "f", false, "Override output qcow2 image") convertCmd.Flags().StringVar(&cmdLineExtra, "append-to-cmdline", "", "Extra kernel cmdline arguments to append to the generated one") diff --git a/cmd/d2vm/main.go b/cmd/d2vm/main.go index 5950808..60240ba 100644 --- a/cmd/d2vm/main.go +++ b/cmd/d2vm/main.go @@ -34,7 +34,7 @@ import ( var ( output = "disk0.qcow2" size = "1G" - password = "root" + password = "" force = false verbose = false timeFormat = "" diff --git a/cmd/d2vm/run/qemu.go b/cmd/d2vm/run/qemu.go index 5406e3a..a27d672 100644 --- a/cmd/d2vm/run/qemu.go +++ b/cmd/d2vm/run/qemu.go @@ -71,7 +71,7 @@ func init() { // Paths and settings for disks flags.Var(&disks, "disk", "Disk config, may be repeated. [file=]path[,size=1G][,format=qcow2]") - flags.StringVar(&data, "data", "", "String of metadata to pass to VM; error to specify both -data and -data-file") + flags.StringVar(&data, "data", "", "String of metadata to pass to VM") // VM configuration flags.StringVar(&accel, "accel", defaultAccel, "Choose acceleration mode. Use 'tcg' to disable it.") @@ -91,7 +91,7 @@ func init() { // USB devices flags.BoolVar(&usbEnabled, "usb", false, "Enable USB controller") - flags.Var(&deviceFlags, "device", "Add USB host device(s). Format driver[,prop=value][,...] -- add device, like -device on the qemu command line.") + flags.Var(&deviceFlags, "device", "Add USB host device(s). Format driver[,prop=value][,...] -- add device, like --device on the qemu command line.") } diff --git a/cmd/d2vm/run/vbox.go b/cmd/d2vm/run/vbox.go index 2d4b6f3..575540f 100644 --- a/cmd/d2vm/run/vbox.go +++ b/cmd/d2vm/run/vbox.go @@ -93,7 +93,7 @@ func vbox(ctx context.Context, path string) error { } // remove machine in case it already exists - cleanup(vboxmanage, name) + cleanup(vboxmanage, name, false) _, out, err := manage(vboxmanage, "createvm", "--name", name, "--register") if err != nil { @@ -273,22 +273,26 @@ func vbox(ctx context.Context, path string) error { return <-errs } -func cleanup(vboxmanage string, name string) { - if _, _, err := manage(vboxmanage, "controlvm", name, "poweroff"); err != nil { +func cleanup(vboxmanage string, name string, logErrs ...bool) { + logErr := true + if len(logErrs) > 0 { + logErr = logErrs[0] + } + if _, _, err := manage(vboxmanage, "controlvm", name, "poweroff"); err != nil && logErr { log.Errorf("controlvm poweroff error: %v", err) } _, out, err := manage(vboxmanage, "storageattach", name, "--storagectl", "IDE Controller", "--port", "1", "--device", "0", "--type", "hdd", "--medium", "emptydrive") - if err != nil { + if err != nil && logErr { log.Errorf("storageattach error: %v\n%s", err, out) } for i := range disks { id := strconv.Itoa(i) _, out, err := manage(vboxmanage, "storageattach", name, "--storagectl", "SATA", "--port", "0", "--device", id, "--type", "hdd", "--medium", "emptydrive") - if err != nil { + if err != nil && logErr { log.Errorf("storageattach error: %v\n%s", err, out) } } - if _, out, err = manage(vboxmanage, "unregistervm", name, "--delete"); err != nil { + if _, out, err = manage(vboxmanage, "unregistervm", name, "--delete"); err != nil && logErr { log.Errorf("unregistervm error: %v\n%s", err, out) } } diff --git a/dockerfile.go b/dockerfile.go index ac59253..8491b3d 100644 --- a/dockerfile.go +++ b/dockerfile.go @@ -72,9 +72,6 @@ func (d Dockerfile) Render(w io.Writer) error { } func NewDockerfile(release OSRelease, img, password string, networkManager NetworkManager) (Dockerfile, error) { - if password == "" { - password = "root" - } d := Dockerfile{Release: release, Image: img, Password: password, NetworkManager: networkManager} var net NetworkManager switch release.ID {