mirror of
https://github.com/linka-cloud/d2vm.git
synced 2025-02-16 13:55:51 +00:00
BREAKING CHANGE: remove root default password, configure it only if provided (close #7)
Signed-off-by: Adphi <philippe.adrien.nousse@gmail.com>
This commit is contained in:
parent
7ad6343e6f
commit
3940cd8975
4
Makefile
4
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)
|
||||
|
@ -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.
|
||||
|
@ -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")
|
||||
|
@ -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")
|
||||
|
@ -34,7 +34,7 @@ import (
|
||||
var (
|
||||
output = "disk0.qcow2"
|
||||
size = "1G"
|
||||
password = "root"
|
||||
password = ""
|
||||
force = false
|
||||
verbose = false
|
||||
timeFormat = ""
|
||||
|
@ -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.")
|
||||
|
||||
}
|
||||
|
||||
|
@ -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)
|
||||
}
|
||||
}
|
||||
|
@ -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 {
|
||||
|
Loading…
x
Reference in New Issue
Block a user