Skip to content
This repository has been archived by the owner on Sep 26, 2021. It is now read-only.

New Driver: Hypriot (for Raspberry Pi) #1225

Closed
wants to merge 42 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
42 commits
Select commit Hold shift + click to select a range
3cc051b
Register driver 'hypriot'
DieterReuter May 23, 2015
4291de1
Add new driver 'hypriot' as a clone of driver 'generic'
DieterReuter May 23, 2015
6083082
Add new provisioner 'hypriot' as a clone of provisioner 'ubuntu'
DieterReuter May 23, 2015
50b865f
Change debian package to 'docker-hypriot'
DieterReuter May 23, 2015
336f531
Add docs for Hypriot driver
DieterReuter May 23, 2015
cba679a
Set hostname for Occidentalis config
DieterReuter May 23, 2015
65f10ce
Install package 'docker' if not already installed
DieterReuter May 23, 2015
fcf82c4
Set Hypriot apt source repository
DieterReuter May 23, 2015
8cf6bc8
Upgrade 'docker' package only, not all packages
DieterReuter May 23, 2015
5b1b68f
Copy public ssh key to make passphrases work
StefanScherer May 23, 2015
1736c55
Start docker daemon if not running
StefanScherer May 23, 2015
d7c8a1f
Receive apt key for hypriot repository
StefanScherer May 23, 2015
f93b643
Add hypriot bats tests
StefanScherer May 24, 2015
625e0a3
Allow only compatible hypriot devices
StefanScherer May 24, 2015
902e3c2
Upgrade packages the secure way
DieterReuter May 24, 2015
2497071
Add more detailled hypriot bats tests
DieterReuter May 24, 2015
c748c70
Improved docs for hypriot driver
DieterReuter May 24, 2015
471968b
Merge pull request #1428 from cdosso/patch-1
nathanleclaire Jun 26, 2015
b48548d
fix creating swARM on Raspberry Pi's
StefanScherer Jul 2, 2015
5d4b7d3
Register driver 'hypriot'
DieterReuter May 23, 2015
ffec6d8
Add new driver 'hypriot' as a clone of driver 'generic'
DieterReuter May 23, 2015
00b71dc
Add new provisioner 'hypriot' as a clone of provisioner 'ubuntu'
DieterReuter May 23, 2015
6b15b63
Change debian package to 'docker-hypriot'
DieterReuter May 23, 2015
c41bafa
Add docs for Hypriot driver
DieterReuter May 23, 2015
d1a2c1e
Set hostname for Occidentalis config
DieterReuter May 23, 2015
d21631f
Install package 'docker' if not already installed
DieterReuter May 23, 2015
3f37afd
Set Hypriot apt source repository
DieterReuter May 23, 2015
5d878b7
Upgrade 'docker' package only, not all packages
DieterReuter May 23, 2015
2af1d83
Copy public ssh key to make passphrases work
StefanScherer May 23, 2015
09de238
Start docker daemon if not running
StefanScherer May 23, 2015
cbf60cf
Receive apt key for hypriot repository
StefanScherer May 23, 2015
c5aa45b
Add hypriot bats tests
StefanScherer May 24, 2015
8554576
Allow only compatible hypriot devices
StefanScherer May 24, 2015
2bedceb
Upgrade packages the secure way
DieterReuter May 24, 2015
506f674
Add more detailled hypriot bats tests
DieterReuter May 24, 2015
db067b2
Improved docs for hypriot driver
DieterReuter May 24, 2015
cbd5c88
fix creating swARM on Raspberry Pi's
StefanScherer Jul 2, 2015
fc525de
rebased
StefanScherer Jul 2, 2015
42c2364
use swARM image
StefanScherer Jul 2, 2015
98ec3e9
go fmt
StefanScherer Jul 2, 2015
1927127
add packagecloud as apt repo
StefanScherer Jul 15, 2015
a0ac950
update bats tests
StefanScherer Jul 17, 2015
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions commands/commands.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ import (
_ "github.com/docker/machine/drivers/generic"
_ "github.com/docker/machine/drivers/google"
_ "github.com/docker/machine/drivers/hyperv"
_ "github.com/docker/machine/drivers/hypriot"
_ "github.com/docker/machine/drivers/none"
_ "github.com/docker/machine/drivers/openstack"
_ "github.com/docker/machine/drivers/rackspace"
Expand Down
118 changes: 113 additions & 5 deletions docs/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
+++
title = "Overview of Docker Machine"
description = "Introduction and Overview of Machine"
keywords = ["docker, machine, amazonec2, azure, digitalocean, google, openstack, rackspace, softlayer, virtualbox, vmwarefusion, vmwarevcloudair, vmwarevsphere, exoscale"]
keywords = ["docker, machine, amazonec2, azure, digitalocean, google, hypriot, openstack, rackspace, softlayer, virtualbox, vmwarefusion, vmwarevcloudair, vmwarevsphere, exoscale"]
[menu.main]
parent="smn_workw_machine"
+++
Expand Down Expand Up @@ -1248,6 +1248,114 @@ Environment variables and default values:
| `--google-disk-size` | `GOOGLE_DISK_SIZE` | `10` |
| `--google-disk-type` | `GOOGLE_DISK_TYPE` | `pd-standard` |

#### Hypriot
Create machines using an existing Raspberry Pi with installed [Hypriot](http://blog.hypriot.com/) image (based on Raspbian).

For more details on installing the basic system (including a preinstalled Docker daemon) please
see the detailled tutorial [Getting started with Docker on your Raspberry Pi](http://blog.hypriot.com/getting-started-with-docker-on-your-arm-device/).

Before using the `docker-machine create` command you have to copy your SSH keys to the device:

$ ssh-copy-id root@$HYPRIOT_IP_ADDRESS

Now you can easily provision your Docker engine with:

$ docker-machine create --driver hypriot --hypriot-ip-address=$HYPRIOT_IP_ADDRESS black-pearl

In order to upgrade to the latest available Docker version, just run:

$ docker-machine upgrade black-pearl

Options:

- `--hypriot-ip-address`: **required** IP Address of host.
- `--hypriot-ssh-user`: SSH username used to connect.
- `--hypriot-ssh-key`: Path to the SSH user private key.
- `--hypriot-ssh-port`: Port to use for SSH.

> Note: currently only a numerical IP address is supported.

Environment variables and default values:

| CLI option | Environment variable | Default |
|----------------------------|----------------------|---------------------|
| **`--hypriot-ip-address`** | - | - |
| `--hypriot-ssh-user` | - | `root` |
| `--hypriot-ssh-key` | - | `$HOME/.ssh/id_rsa` |
| `--hypriot-ssh-port` | - | `22` |

Once you have created your Docker machine run this command to configure your shell:

$ eval "$(docker-machine env black-pearl)"

Now you can use the Docker machine as usual:

$ docker version
Client version: 1.6.2
Client API version: 1.18
Go version (client): go1.4.2
Git commit (client): 7c8fca2
OS/Arch (client): darwin/amd64
Server version: 1.6.2
Server API version: 1.18
Go version (server): go1.4.2
Git commit (server): 7c8fca2
OS/Arch (server): linux/arm

#### Hypriot
Create machines using an existing Raspberry Pi with installed [Hypriot](http://blog.hypriot.com/) image (based on Raspbian).

For more details on installing the basic system (including a preinstalled Docker daemon) please
see the detailled tutorial [Getting started with Docker on your Raspberry Pi](http://blog.hypriot.com/getting-started-with-docker-on-your-arm-device/).

Before using the `docker-machine create` command you have to copy your SSH keys to the device:

$ ssh-copy-id root@$HYPRIOT_IP_ADDRESS

Now you can easily provision your Docker engine with:

$ docker-machine create --driver hypriot --hypriot-ip-address=$HYPRIOT_IP_ADDRESS black-pearl

In order to upgrade to the latest available Docker version, just run:

$ docker-machine upgrade black-pearl

Options:

- `--hypriot-ip-address`: **required** IP Address of host.
- `--hypriot-ssh-user`: SSH username used to connect.
- `--hypriot-ssh-key`: Path to the SSH user private key.
- `--hypriot-ssh-port`: Port to use for SSH.

> Note: currently only a numerical IP address is supported.

Environment variables and default values:

| CLI option | Environment variable | Default |
|----------------------------|----------------------|---------------------|
| **`--hypriot-ip-address`** | - | - |
| `--hypriot-ssh-user` | - | `root` |
| `--hypriot-ssh-key` | - | `$HOME/.ssh/id_rsa` |
| `--hypriot-ssh-port` | - | `22` |

Once you have created your Docker machine run this command to configure your shell:

$ eval "$(docker-machine env black-pearl)"

Now you can use the Docker machine as usual:

$ docker version
Client version: 1.6.2
Client API version: 1.18
Go version (client): go1.4.2
Git commit (client): 7c8fca2
OS/Arch (client): darwin/amd64
Server version: 1.6.2
Server API version: 1.18
Go version (server): go1.4.2
Git commit (server): 7c8fca2
OS/Arch (server): linux/arm

#### IBM Softlayer
Create machines on [Softlayer](http://softlayer.com).

Expand Down Expand Up @@ -1466,7 +1574,7 @@ Create machines locally using [VirtualBox](https://www.virtualbox.org/).
This driver requires VirtualBox to be installed on your host.

$ docker-machine create --driver=virtualbox vbox-test

You can create an entirely new machine or you can convert a Boot2Docker VM into
a machine by importing the VM. To convert a Boot2Docker VM, you'd use the following
command:
Expand Down Expand Up @@ -1502,11 +1610,11 @@ using the `http://` form.

To customize the host only adapter, you can use the `--virtualbox-hostonly-cidr`
flag. This will specify the host IP and Machine will calculate the VirtualBox
DHCP server address (a random IP on the subnet between `.1` and `.25`) so
DHCP server address (a random IP on the subnet between `.1` and `.25`) so
it does not clash with the specified host IP.
Machine will also specify the DHCP lower bound to `.100` and the upper bound
to `.254`. For example, a specified CIDR of `192.168.24.1/24` would have a
DHCP server between `192.168.24.2-25`, a lower bound of `192.168.24.100` and
DHCP server between `192.168.24.2-25`, a lower bound of `192.168.24.100` and
upper bound of `192.168.24.254`.

Environment variables and default values:
Expand All @@ -1530,7 +1638,7 @@ Options:
- `--vmwarefusion-disk-size`: Size of disk for host VM (in MB).
- `--vmwarefusion-memory-size`: Size of memory for host VM (in MB).

The VMware Fusion driver uses the latest boot2docker image.
The VMware Fusion driver uses the latest boot2docker image.
See [frapposelli/boot2docker](https://github.com/frapposelli/boot2docker/tree/vmware-64bit)

Environment variables and default values:
Expand Down
221 changes: 221 additions & 0 deletions drivers/hypriot/hypriot.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,221 @@
package hypriot

import (
"fmt"
"net"
"os"
"path/filepath"
"time"

"github.com/codegangsta/cli"
"github.com/docker/machine/drivers"
"github.com/docker/machine/log"
"github.com/docker/machine/state"
"github.com/docker/machine/utils"
)

type Driver struct {
MachineName string
IPAddress string
SSHKey string
SSHUser string
SSHPort int
CaCertPath string
PrivateKeyPath string
DriverKeyPath string
SwarmMaster bool
SwarmHost string
SwarmDiscovery string
storePath string
}

const (
defaultTimeout = 1 * time.Second
)

func init() {
drivers.Register("hypriot", &drivers.RegisteredDriver{
New: NewDriver,
GetCreateFlags: GetCreateFlags,
})
}

// GetCreateFlags registers the flags this driver adds to
// "docker hosts create"
func GetCreateFlags() []cli.Flag {
return []cli.Flag{
cli.StringFlag{
Name: "hypriot-ip-address",
Usage: "IP Address of machine",
Value: "",
},
cli.StringFlag{
Name: "hypriot-ssh-user",
Usage: "SSH user",
Value: "root",
},
cli.StringFlag{
Name: "hypriot-ssh-key",
Usage: "SSH private key path",
Value: filepath.Join(utils.GetHomeDir(), ".ssh", "id_rsa"),
},
cli.IntFlag{
Name: "hypriot-ssh-port",
Usage: "SSH port",
Value: 22,
},
}
}

func NewDriver(machineName string, storePath string, caCert string, privateKey string) (drivers.Driver, error) {
return &Driver{
MachineName: machineName,
storePath: storePath,
CaCertPath: caCert,
PrivateKeyPath: privateKey,
}, nil
}

func (d *Driver) DriverName() string {
return "hypriot"
}

func (d *Driver) AuthorizePort(ports []*drivers.Port) error {
return nil
}

func (d *Driver) DeauthorizePort(ports []*drivers.Port) error {
return nil
}

func (d *Driver) GetMachineName() string {
return d.MachineName
}

func (d *Driver) GetSSHHostname() (string, error) {
return d.GetIP()
}

func (d *Driver) GetSSHKeyPath() string {
return filepath.Join(d.storePath, "id_rsa")
}

func (d *Driver) GetSSHPort() (int, error) {
if d.SSHPort == 0 {
d.SSHPort = 22
}

return d.SSHPort, nil
}

func (d *Driver) GetSSHUsername() string {
return d.SSHUser
}

func (d *Driver) SetConfigFromFlags(flags drivers.DriverOptions) error {
d.IPAddress = flags.String("hypriot-ip-address")
d.SSHUser = flags.String("hypriot-ssh-user")
d.SSHKey = flags.String("hypriot-ssh-key")
d.SSHPort = flags.Int("hypriot-ssh-port")

if d.IPAddress == "" {
return fmt.Errorf("hypriot driver requires the --hypriot-ip-address option")
}

if d.SSHKey == "" {
return fmt.Errorf("hypriot driver requires the --hypriot-ssh-key option")
}

return nil
}

func (d *Driver) PreCreateCheck() error {
return nil
}

func (d *Driver) Create() error {
log.Infof("Importing SSH key...")

if err := utils.CopyFile(d.SSHKey, d.sshKeyPath()); err != nil {
return fmt.Errorf("unable to copy ssh key: %s", err)
}

if err := os.Chmod(d.sshKeyPath(), 0600); err != nil {
return err
}

if err := utils.CopyFile(fmt.Sprintf("%s.pub", d.SSHKey), d.publicSSHKeyPath()); err != nil {
return fmt.Errorf("unable to copy public ssh key: %s", err)
}

log.Debugf("IP: %s", d.IPAddress)

return nil
}

func (d *Driver) GetURL() (string, error) {
ip, err := d.GetIP()
if err != nil {
return "", err
}
return fmt.Sprintf("tcp://%s:2376", ip), nil
}

func (d *Driver) GetIP() (string, error) {
if d.IPAddress == "" {
return "", fmt.Errorf("IP address is not set")
}
return d.IPAddress, nil
}

func (d *Driver) GetState() (state.State, error) {
addr := fmt.Sprintf("%s:%d", d.IPAddress, d.SSHPort)
_, err := net.DialTimeout("tcp", addr, defaultTimeout)
var st state.State
if err != nil {
st = state.Stopped
} else {
st = state.Running
}
return st, nil
}

func (d *Driver) Start() error {
return fmt.Errorf("hypriot driver does not support start")
}

func (d *Driver) Stop() error {
return fmt.Errorf("hypriot driver does not support stop")
}

func (d *Driver) Remove() error {
return nil
}

func (d *Driver) Restart() error {
log.Debug("Restarting...")

if _, err := drivers.RunSSHCommandFromDriver(d, "sudo shutdown -r now"); err != nil {
return err
}

return nil
}

func (d *Driver) Kill() error {
log.Debug("Killing...")

if _, err := drivers.RunSSHCommandFromDriver(d, "sudo shutdown -P now"); err != nil {
return err
}

return nil
}

func (d *Driver) sshKeyPath() string {
return filepath.Join(d.storePath, "id_rsa")
}

func (d *Driver) publicSSHKeyPath() string {
return d.sshKeyPath() + ".pub"
}
1 change: 1 addition & 0 deletions drivers/hypriot/hypriot_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
package hypriot
Loading