Skip to content

Commit

Permalink
Merge pull request #2 from Parallels/release-1.0
Browse files Browse the repository at this point in the history
Release v1.0.0
  • Loading branch information
legal90 committed Oct 28, 2015
2 parents 703ca4e + 79676f5 commit 360a481
Show file tree
Hide file tree
Showing 12 changed files with 549 additions and 15 deletions.
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
docker-machine-driver-parallels
*.log
17 changes: 11 additions & 6 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,12 +1,17 @@
default: build

build:
go build -i -o docker-machine-driver-parallels ./bin
bin/docker-machine-driver-parallels:
go build -i -o ./bin/docker-machine-driver-parallels ./bin

build: clean bin/docker-machine-driver-parallels

clean:
$(RM) docker-machine-driver-parallels
$(RM) bin/docker-machine-driver-parallels

install: bin/docker-machine-driver-parallels
cp -f ./bin/docker-machine-driver-parallels $(GOPATH)/bin/

install: build
cp -r ./docker-machine-driver-parallels /usr/local/bin/
test-acceptance:
test/integration/run-bats.sh test/integration/bats/

.PHONY: install
.PHONY: clean build install test-acceptance
101 changes: 92 additions & 9 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,22 +1,105 @@
# Docker Machine Parallels Driver

### PREVIEW
This is a pre-release version of Parallels Driver for Docker Machine.
Work is still in progress.
This is a plugin for [Docker Machine](https://docs.docker.com/machine/) allowing
to create Docker hosts locally on [Parallels Desktop for Mac](http://www.parallels.com/products/desktop/)

This is a plugin for Docker Machine, wich is gonna be compatible with Docker
Machine v0.5.0.
Refer to this PR for more details: https://github.com/docker/machine/pull/1902
## Requirements
* OS X 10.9+
* [Docker Machine](https://docs.docker.com/machine/) 0.5.0+ (is bundled to
[Docker Toolbox](https://www.docker.com/docker-toolbox) 1.9.0+)
* [Parallels Desktop](http://www.parallels.com/products/desktop/) 11.0.0+ **Pro** or
**Business** edition (_Standard edition is not supported!_)

## Build
## Installation
To install this plugin, download the binary `docker-machine-driver-parallels`
and make it available by `$PATH`, for example by putting it to `/usr/local/bin/`:

```console
$ curl -L https://github.com/Parallels/docker-machine-parallels/releases/download/v1.0.0/docker-machine-driver-parallels > /usr/local/bin/docker-machine-driver-parallels

$ chmod +x /usr/local/bin/docker-machine-driver-parallels
```

The latest version of `docker-machine-driver-parallels` binary is available on
the ["Releases"](https://github.com/Parallels/docker-machine-parallels/releases) page.

## Usage
Official documentation for Docker Machine [is available here](https://docs.docker.com/machine/).

To create a Parallels Desktop virtual machine for Docker purposes just run this
command:

```
$ docker-machine create --driver=parallels prl-dev
```

Available options:

- `--parallels-boot2docker-url`: The URL of the boot2docker image.
- `--parallels-disk-size`: Size of disk for the host VM (in MB).
- `--parallels-memory`: Size of memory for the host VM (in MB).
- `--parallels-cpu-count`: Number of CPUs to use to create the VM (-1 to use the number of CPUs available).
- `--parallels-no-share`: Disable the sharing of `/Users` directory

The `--parallels-boot2docker-url` flag takes a few different forms. By
default, if no value is specified for this flag, Machine will check locally for
a boot2docker ISO. If one is found, that will be used as the ISO for the
created machine. If one is not found, the latest ISO release available on
[boot2docker/boot2docker](https://github.com/boot2docker/boot2docker) will be
downloaded and stored locally for future use. Note that this means you must run
`docker-machine upgrade` deliberately on a machine if you wish to update the "cached"
boot2docker ISO.

This is the default behavior (when `--parallels-boot2docker-url=""`), but the
option also supports specifying ISOs by the `http://` and `file://` protocols.

Environment variables and default values:

| CLI option | Environment variable | Default |
|-------------------------------|-----------------------------|--------------------------|
| `--parallels-boot2docker-url` | `PARALLELS_BOOT2DOCKER_URL` | *Latest boot2docker url* |
| `--parallels-cpu-count` | `PARALLELS_CPU_COUNT` | `1` |
| `--parallels-disk-size` | `PARALLELS_DISK_SIZE` | `20000` |
| `--parallels-memory` | `PARALLELS_MEMORY_SIZE` | `1024` |
| `--parallels-no-share` | - | `false` |

## Development

### Build from Source
If you wish to work on Parallels Driver for Docker machine, you'll first need
[Go](http://www.golang.org) installed (version 1.5+ is required).
Make sure Go is properly installed, including setting up a [GOPATH](http://golang.org/doc/code.html#GOPATH).

Run these commands to build the plugin binary:

```bash
$ go get -d github.com/Parallels/docker-machine-parallels
$ cd $GOPATH/github.com/Parallels/docker-machine-parallels
$ make
$ make build
```

After the build is complete, `bin/docker-machine-driver-parallels` binary will
be created. If you want to copy it to the `${GOPATH}/bin/`, run `make install`.

### Acceptance Tests

We use [BATS](https://github.com/sstephenson/bats) for acceptance testing, so,
[install it](https://github.com/sstephenson/bats#installing-bats-from-source) first.

You also need to build the plugin binary by calling `make build`.

Then you can run acceptance tests using this command:

```bash
$ make test-acceptance
```

The binary will appear in the working directory. Just make it available on the `$PATH`
Acceptance tests will invoke the general `docker-machine` binary available by
`$PATH`. If you want to specify it explicitly, just set `MACHINE_BINARY` env variable:

```bash
$ MACHINE_BINARY=/path/to/docker-machine make test-acceptance
```

## Authors

Expand Down
10 changes: 10 additions & 0 deletions test/integration/bats/bad-create-iso.bats
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
#!/usr/bin/env bats

load ${BASE_TEST_DIR}/helpers.bash

export BAD_URL="http://dev.null:9111/bad.iso"

@test "$DRIVER: Should not allow machine creation with bad ISO" {
run machine create -d parallels --parallels-boot2docker-url $BAD_URL $NAME
[[ ${status} -eq 1 ]]
}
19 changes: 19 additions & 0 deletions test/integration/bats/certs-checksum.bats
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
#!/usr/bin/env bats

load ${BASE_TEST_DIR}/helpers.bash

@test "$DRIVER: create" {
run machine create -d $DRIVER $NAME
}

@test "$DRIVER: verify that server cert checksum matches local checksum" {
# Have to create this directory and file or else the OpenSSL checksum will barf.
machine ssh $NAME -- sudo mkdir -p /usr/local/ssl
machine ssh $NAME -- sudo touch /usr/local/ssl/openssl.cnf

SERVER_CHECKSUM=$(machine ssh $NAME -- openssl dgst -sha256 /var/lib/boot2docker/ca.pem | awk '{ print $2 }')
LOCAL_CHECKSUM=$(openssl dgst -sha256 $MACHINE_STORAGE_PATH/certs/ca.pem | awk '{ print $2 }')
echo ${SERVER_CHECKSUM}
echo ${LOCAL_CHECKSUM}
[[ ${SERVER_CHECKSUM} == ${LOCAL_CHECKSUM} ]]
}
153 changes: 153 additions & 0 deletions test/integration/bats/core-commands.bats
Original file line number Diff line number Diff line change
@@ -0,0 +1,153 @@
#!/usr/bin/env bats

load ${BASE_TEST_DIR}/helpers.bash

@test "$DRIVER: machine should not exist" {
run machine inspect $NAME
echo ${output}
[ "$status" -eq 1 ]
[[ ${lines[0]} == "Host \"$NAME\" does not exist" ]]
}

@test "$DRIVER: create" {
run machine create -d $DRIVER $NAME
echo ${output}
[ "$status" -eq 0 ]
}

@test "$DRIVER: appears with ls" {
run machine ls -q
echo ${output}
[ "$status" -eq 0 ]
[[ ${lines[0]} == "$NAME" ]]
}

@test "$DRIVER: has status 'started' appearing in ls" {
run machine ls -q --filter state=Running
echo ${output}
[ "$status" -eq 0 ]
[[ ${lines[0]} == "$NAME" ]]
}

@test "$DRIVER: create with same name again fails" {
run machine create -d $DRIVER $NAME
echo ${output}
[ "$status" -eq 1 ]
[[ ${lines[0]} == "Host already exists: \"$NAME\"" ]]
}

@test "$DRIVER: run busybox container" {
run docker $(machine config $NAME) run busybox echo hello world
echo ${output}
[ "$status" -eq 0 ]
}

@test "$DRIVER: url" {
run machine url $NAME
echo ${output}
[ "$status" -eq 0 ]
}

@test "$DRIVER: ip" {
run machine ip $NAME
echo ${output}
[ "$status" -eq 0 ]
}

@test "$DRIVER: ssh" {
run machine ssh $NAME -- ls -lah /
echo ${output}
[ "$status" -eq 0 ]
[[ ${lines[0]} =~ "total" ]]
}

@test "$DRIVER: docker commands with the socket should work" {
run machine ssh $NAME -- sudo docker version
echo ${output}
}

@test "$DRIVER: shared folder is mounted" {
run machine ssh $NAME -- "mount | grep prl_fs | awk '{ print $3 }'"
echo ${output}
[ "$status" -eq 0 ]
[[ ${output} == *"/Users"* ]]
}

@test "$DRIVER: stop" {
run machine stop $NAME
echo ${output}
[ "$status" -eq 0 ]
}

@test "$DRIVER: machine should show stopped after stop" {
run machine ls
echo ${output}
[ "$status" -eq 0 ]
[[ ${lines[1]} == *"Stopped"* ]]
}

@test "$DRIVER: url should show an error when machine is stopped" {
run machine url $NAME
echo ${output}
[ "$status" -eq 1 ]
[[ ${output} == *"not running"* ]]
}

@test "$DRIVER: env should show an error when machine is stopped" {
run machine env $NAME
echo ${output}
[ "$status" -eq 1 ]
[[ ${output} == *"not running. Please start"* ]]
}

@test "$DRIVER: machine should not allow upgrade when stopped" {
run machine upgrade $NAME
echo ${output}
[[ "$status" -eq 1 ]]
}

@test "$DRIVER: start" {
run machine start $NAME
echo ${output}
[ "$status" -eq 0 ]
}

@test "$DRIVER: machine should show running after start" {
run machine ls
echo ${output}
[ "$status" -eq 0 ]
[[ ${lines[1]} == *"Running"* ]]
}

@test "$DRIVER: kill" {
run machine kill $NAME
echo ${output}
[ "$status" -eq 0 ]
}

@test "$DRIVER: machine should show stopped after kill" {
run machine ls
echo ${output}
[ "$status" -eq 0 ]
[[ ${lines[1]} == *"Stopped"* ]]
}

@test "$DRIVER: restart" {
run machine restart $NAME
echo ${output}
[ "$status" -eq 0 ]
}

@test "$DRIVER: machine should show running after restart" {
run machine ls
echo ${output}
[ "$status" -eq 0 ]
[[ ${lines[1]} == *"Running"* ]]
}

@test "$DRIVER: status" {
run machine status $NAME
echo ${output}
[ "$status" -eq 0 ]
[[ ${output} == *"Running"* ]]
}
49 changes: 49 additions & 0 deletions test/integration/bats/custom-mem-disk.bats
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
#!/usr/bin/env bats

load ${BASE_TEST_DIR}/helpers.bash

# Default memsize is 1024MB and disksize is 20000MB
# These values are defined in parallels.go
export DEFAULT_MEMSIZE=1024
export DEFAULT_DISKSIZE=20000
export CUSTOM_MEMSIZE=1536
export CUSTOM_DISKSIZE=10000
export CUSTOM_CPUCOUNT=1

function findDiskSize() {
run bash -c "prlctl list -i $NAME | grep 'hdd0.*sata' | grep -o '\d*Mb' | awk -F 'Mb' '{print $1}'"
}

function findMemorySize() {
run bash -c "prlctl list -i $NAME | grep 'memory ' | grep -o '[0-9]\+'"
}

function findCPUCount() {
run bash -c "prlctl list -i $NAME | grep -o 'cpus=\d*' | cut -d'=' -f2"
}

@test "$DRIVER: create with custom disk, cpu count and memory size flags" {
run machine create -d $DRIVER --parallels-cpu-count $CUSTOM_CPUCOUNT --parallels-disk-size $CUSTOM_DISKSIZE --parallels-memory $CUSTOM_MEMSIZE $NAME
[ "$status" -eq 0 ]
}

@test "$DRIVER: check custom machine memory size" {
findMemorySize
[[ ${output} == "$CUSTOM_MEMSIZE" ]]
}

@test "$DRIVER: check custom machine disksize" {
findDiskSize
[[ ${output} == *"$CUSTOM_DISKSIZE"* ]]
}

@test "$DRIVER: check custom machine cpucount" {
findCPUCount
[[ ${output} == "$CUSTOM_CPUCOUNT" ]]
}

@test "$DRIVER: machine should show running after create" {
run machine ls
[ "$status" -eq 0 ]
[[ ${lines[1]} == *"Running"* ]]
}
13 changes: 13 additions & 0 deletions test/integration/bats/no-share.bats
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
#!/usr/bin/env bats

load ${BASE_TEST_DIR}/helpers.bash

@test "$DRIVER: create with disabled sharing" {
run machine create -d $DRIVER --parallels-no-share $NAME
}

@test "$DRIVER: shared folder is not mounted mounted" {
run machine ssh $NAME -- "mount | grep prl_fs"
echo ${output}
[ "$status" -eq 1 ]
}
Loading

0 comments on commit 360a481

Please sign in to comment.