diff --git a/README.md b/README.md index 973826e..4c636b0 100644 --- a/README.md +++ b/README.md @@ -1,21 +1,98 @@ -# Docker machine qemu driver +# [QEMU](http://www.qemu.org/) Driver Plugin for `docker-machine` -I needed a non-libvirt qemu driver, so this is it. +Please note that this is a fork of [CandySunPlus/docker-machine-driver-qemu](https://github.com/CandySunPlus/docker-machine-driver-qemu) which includes a commit for QEMU 6.x support. +This repo is in turn just a fork of the original repo [machine-drivers/docker-machine-driver-qemu](https://github.com/machine-drivers/docker-machine-driver-qemu) which seems unmaintained as the last release was made in 2017 and PRs like the one by CandySunPlus have not been merged. -from @SvenDowideit +This fork aims to add installation instructions for future reference. -Its initial use is going to be for running the [Rancher OS](https://github.com/rancher/os) tests, but maybe you'll find a use for it too. +## Docker Engine Version +Since this plugin uses the now deprecated [Boot2Docker(https://github.com/boot2docker/boot2docker) the version installed by default is the last released +before deprecation of said project which is 19.03.12. -from @fventuri +The project now recommends to instead install [Docker Desktop](https://www.docker.com/products/docker-desktop). -#### QEMU +`docker version` output when following the [installation Instructions](#installation-instructions): + +``` +Server: Docker Engine - Community + Engine: + Version: 19.03.12 + API version: 1.40 (minimum version 1.12) + Go version: go1.13.10 + Git commit: 48a66213fe + Built: Mon Jun 22 15:49:35 2020 + OS/Arch: linux/amd64 + Experimental: false + containerd: + Version: v1.2.13 + GitCommit: 7ad184331fa3e55e52b890ea95e65ba581ae3429 + runc: + Version: 1.0.0-rc10 + GitCommit: dc9208a3303feef5b3839f4323d9beb36df0a9dd + docker-init: + Version: 0.18.0 + GitCommit: fec3683 +``` + +## Installation Instructions + +These installation instructions should work on Linux as well as on macOS. + +Clone this repo to a location of choice and change into the cloned directory: + +``` +git clone https://github.com/totoroot/docker-machine-driver-qemu /tmp/docker-machine-driver-qemu && cd /tmp/docker-machine-driver-qemu +``` + +Make the binary of the plugin and copy it to a location in your PATH: + +```sh +make default +cp bin/docker-machine-driver-qemu /usr/local/bin/docker-machine-driver-qemu +``` + +Depending on your user's permissions chose you might need to copy it with elevated permissions: + +```sh +sudo install /tmp/docker-machine-driver-qemu /usr/local/bin/docker-machine-driver-qemu +``` + +Verify that binary is in your PATH: + +```sh +which docker-machine-driver-qemu +``` + +Note that the available arguments for `docker-machine` using the QEMU driver are listed [below](#qemu-options). + +Create a docker-machine VM named "qemu-default" with QEMU driver: + +```sh +docker-machine create --driver=qemu qemu-default +``` + +Evaluate environment variables for VM: + +```sh +eval $(docker-machine env qemu-default) +``` + +Verify `docker` works as it should: + +```sh +docker version +``` + +## QEMU Options Create machines locally using [QEMU](http://www.qemu.org/). This driver requires QEMU to be installed on your host. - $ docker-machine create --driver=qemu qemu-test +```sh +docker-machine create --driver=qemu qemu-default +``` Options: diff --git a/cmd/main.go b/cmd/main.go index 7a17e44..524ffb5 100644 --- a/cmd/main.go +++ b/cmd/main.go @@ -1,8 +1,9 @@ package main import ( + qemu "docker-machine-driver-qemu" + "github.com/docker/machine/libmachine/drivers/plugin" - "github.com/jigtools/docker-machine-driver-qemu" ) func main() { diff --git a/go.mod b/go.mod new file mode 100644 index 0000000..e6c74f8 --- /dev/null +++ b/go.mod @@ -0,0 +1,11 @@ +module docker-machine-driver-qemu + +go 1.16 + +require ( + github.com/docker/docker v20.10.7+incompatible // indirect + github.com/docker/machine v0.16.2 + github.com/moby/term v0.0.0-20210619224110-3f7ff695adc6 // indirect + github.com/stretchr/testify v1.7.0 // indirect + golang.org/x/crypto v0.0.0-20210616213533-5ff15b29337e // indirect +) diff --git a/go.sum b/go.sum new file mode 100644 index 0000000..f51bafc --- /dev/null +++ b/go.sum @@ -0,0 +1,47 @@ +github.com/Azure/go-ansiterm v0.0.0-20210617225240-d185dfc1b5a1 h1:UQHMgLO+TxOElx5B5HZ4hJQsoJ/PvUvKRhJHDQXO8P8= +github.com/Azure/go-ansiterm v0.0.0-20210617225240-d185dfc1b5a1/go.mod h1:xomTg63KZ2rFqZQzSB4Vz2SUXa1BpHTVz9L5PTmPC4E= +github.com/creack/pty v1.1.11 h1:07n33Z8lZxZ2qwegKbObQohDhXDQxiMMz1NOUGYlesw= +github.com/creack/pty v1.1.11/go.mod h1:oKZEueFk5CKHvIhNR5MUki03XCEU+Q6VDXinZuGJ33E= +github.com/davecgh/go-spew v1.1.0 h1:ZDRjVQ15GmhC3fiQ8ni8+OwkZQO4DARzQgrnXU1Liz8= +github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= +github.com/docker/docker v20.10.7+incompatible h1:Z6O9Nhsjv+ayUEeI1IojKbYcsGdgYSNqxe1s2MYzUhQ= +github.com/docker/docker v20.10.7+incompatible/go.mod h1:eEKB0N0r5NX/I1kEveEz05bcu8tLC/8azJZsviup8Sk= +github.com/docker/machine v0.16.2 h1:jyF9k3Zg+oIGxxSdYKPScyj3HqFZ6FjgA/3sblcASiU= +github.com/docker/machine v0.16.2/go.mod h1:I8mPNDeK1uH+JTcUU7X0ZW8KiYz0jyAgNaeSJ1rCfDI= +github.com/google/go-cmp v0.3.0/go.mod h1:8QqcDgzrUqlUb/G2PQTWiueGozuR1884gddMywk6iLU= +github.com/google/go-cmp v0.4.0 h1:xsAVV57WRhGj6kEIi8ReJzQlHHqcBYCElAvkovg3B/4= +github.com/google/go-cmp v0.4.0/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE= +github.com/moby/term v0.0.0-20210619224110-3f7ff695adc6 h1:dcztxKSvZ4Id8iPpHERQBbIJfabdt4wUm5qy3wOL2Zc= +github.com/moby/term v0.0.0-20210619224110-3f7ff695adc6/go.mod h1:E2VnQOmVuvZB6UYnnDB0qG5Nq/1tD9acaOpo6xmt0Kw= +github.com/pkg/errors v0.8.1/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0= +github.com/pkg/errors v0.9.1 h1:FEBLx1zS214owpjy7qsBeixbURkuhQAwrK5UwLGTwt4= +github.com/pkg/errors v0.9.1/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0= +github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM= +github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4= +github.com/spf13/pflag v1.0.3/go.mod h1:DYY7MBk1bdzusC3SYhjObp+wFpr4gzcvqqNjLnInEg4= +github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME= +github.com/stretchr/testify v1.7.0 h1:nwc3DEeHmmLAfoZucVR881uASk0Mfjw8xYJ99tb5CcY= +github.com/stretchr/testify v1.7.0/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg= +golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w= +golang.org/x/crypto v0.0.0-20210616213533-5ff15b29337e h1:gsTQYXdTw2Gq7RBsWvlQ91b+aEQ6bXFUngBGuR8sPpI= +golang.org/x/crypto v0.0.0-20210616213533-5ff15b29337e/go.mod h1:GvvjBRRGRdwPK5ydBHafDWAxML/pGHZbMvKqRZ5+Abc= +golang.org/x/net v0.0.0-20190311183353-d8887717615a/go.mod h1:t9HGtf8HONx5eT2rtn7q6eTqICYqUVnKs3thJo3Qplg= +golang.org/x/net v0.0.0-20210226172049-e18ecbb05110/go.mod h1:m0MpNAwzfU5UDzcl9v0D8zg8gWTRqZa9RBIspLL5mdg= +golang.org/x/sync v0.0.0-20190423024810-112230192c58/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= +golang.org/x/sys v0.0.0-20190215142949-d0b11bdaac8a/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= +golang.org/x/sys v0.0.0-20201119102817-f84b799fce68/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= +golang.org/x/sys v0.0.0-20210615035016-665e8c7367d1/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= +golang.org/x/sys v0.0.0-20210616094352-59db8d763f22 h1:RqytpXGR1iVNX7psjB3ff8y7sNFinVFvkx1c8SjBkio= +golang.org/x/sys v0.0.0-20210616094352-59db8d763f22/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= +golang.org/x/term v0.0.0-20201126162022-7de9c90e9dd1 h1:v+OssWQX+hTHEmOBgwxdZxK4zHq3yOs8F9J7mk0PY8E= +golang.org/x/term v0.0.0-20201126162022-7de9c90e9dd1/go.mod h1:bj7SfCRtBDWHUb9snDiAeCFNEtKQo2Wmx5Cou7ajbmo= +golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ= +golang.org/x/text v0.3.3/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ= +golang.org/x/tools v0.0.0-20180917221912-90fa682c2a6e/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ= +golang.org/x/tools v0.0.0-20190624222133-a101b041ded4/go.mod h1:/rFqwRUd4F7ZHNgwSSTFct+R/Kf4OFW1sUzUTQQTgfc= +golang.org/x/xerrors v0.0.0-20191204190536-9bdfabe68543/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0= +gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= +gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c h1:dUUwHk2QECo/6vqA44rthZ8ie2QXMNeKRTHCNY2nXvo= +gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM= +gotest.tools/v3 v3.0.2 h1:kG1BFyqVHuQoVQiR1bWGnfz/fmHvvuiSPIV7rvl360E= +gotest.tools/v3 v3.0.2/go.mod h1:3SzNCllyD9/Y+b5r9JIKQ474KzkZyqLqEfYqMsX94Bk= diff --git a/qemu.go b/qemu.go index 988dcfc..b761871 100644 --- a/qemu.go +++ b/qemu.go @@ -73,8 +73,8 @@ func (d *Driver) GetCreateFlags() []mcnflag.Flag { }, mcnflag.IntFlag{ Name: "qemu-disk-size", - Usage: "Size of disk for host in MB", - Value: 20000, + Usage: "Size of disk for host in GB", + Value: 20, }, mcnflag.IntFlag{ Name: "qemu-cpu-count", @@ -483,18 +483,15 @@ func (d *Driver) Start() error { if d.Network == "user" { startCmd = append(startCmd, - "-net", "nic,vlan=0,model=virtio", - "-net", fmt.Sprintf("user,vlan=0,hostfwd=tcp::%d-:22,hostfwd=tcp::%d-:2376,hostname=%s", d.SSHPort, d.EnginePort, d.GetMachineName()), + "-nic", fmt.Sprintf("user,model=virtio,hostfwd=tcp::%d-:22,hostfwd=tcp::%d-:2376,hostname=%s", d.SSHPort, d.EnginePort, d.GetMachineName()), ) } else if d.Network == "tap" { startCmd = append(startCmd, - "-net", "nic,vlan=0,model=virtio", - "-net", fmt.Sprintf("tap,vlan=0,ifname=%s,script=no,downscript=no", d.NetworkInterface), + "-nic", fmt.Sprintf("tap,model=virtio,ifname=%s,script=no,downscript=no", d.NetworkInterface), ) } else if d.Network == "bridge" { startCmd = append(startCmd, - "-net", "nic,vlan=0,model=virtio", - "-net", fmt.Sprintf("bridge,vlan=0,br=%s", d.NetworkBridge), + "-nic", fmt.Sprintf("bridge,model=virtio,br=%s", d.NetworkBridge), ) } else { log.Errorf("Unknown network: %s", d.Network) @@ -714,7 +711,7 @@ func (d *Driver) generateDiskImage(size int) error { fmt.Printf("ERROR: %s\n", stderr) return err } - if stdout, stderr, err := cmdOutErr("qemu-img", "resize", d.diskPath(), fmt.Sprintf("+%dM", size)); err != nil { + if stdout, stderr, err := cmdOutErr("qemu-img", "resize", d.diskPath(), fmt.Sprintf("+%dG", size)); err != nil { fmt.Printf("OUTPUT: %s\n", stdout) fmt.Printf("ERROR: %s\n", stderr) return err