Skip to content

Commit

Permalink
BREAKING CHANGE: remove root default password, configure it only if p…
Browse files Browse the repository at this point in the history
…rovided (close #7)

Signed-off-by: Adphi <[email protected]>
  • Loading branch information
Adphi committed Sep 12, 2022
1 parent 7ad6343 commit 3940cd8
Show file tree
Hide file tree
Showing 8 changed files with 17 additions and 18 deletions.
4 changes: 2 additions & 2 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
2 changes: 0 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
2 changes: 1 addition & 1 deletion cmd/d2vm/build.go
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand Down
2 changes: 1 addition & 1 deletion cmd/d2vm/convert.go
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand Down
2 changes: 1 addition & 1 deletion cmd/d2vm/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ import (
var (
output = "disk0.qcow2"
size = "1G"
password = "root"
password = ""
force = false
verbose = false
timeFormat = ""
Expand Down
4 changes: 2 additions & 2 deletions cmd/d2vm/run/qemu.go
Original file line number Diff line number Diff line change
Expand Up @@ -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.")
Expand All @@ -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.")

}

Expand Down
16 changes: 10 additions & 6 deletions cmd/d2vm/run/vbox.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -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)
}
}
Expand Down
3 changes: 0 additions & 3 deletions dockerfile.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down

0 comments on commit 3940cd8

Please sign in to comment.