Fixes #1243 Custom GCE images support

Signed-off-by: Andrew Grande <aprepel@gmail.com>

Signed-off-by: David Gageot <david@gageot.net>
This commit is contained in:
aperepel 2015-06-08 19:46:44 -04:00 committed by David Gageot
parent d855c35059
commit 914ccb6968
3 changed files with 32 additions and 17 deletions

View File

@ -43,6 +43,7 @@ $ docker-machine create --driver google \
- `--google-project`: **required** The id of your project to use when launching the instance. - `--google-project`: **required** The id of your project to use when launching the instance.
- `--google-zone`: The zone to launch the instance. - `--google-zone`: The zone to launch the instance.
- `--google-machine-type`: The type of instance. - `--google-machine-type`: The type of instance.
- `--google-machine-image`: The absolute URL to a base VM image to instantiate.
- `--google-username`: The username to use for the instance. - `--google-username`: The username to use for the instance.
- `--google-scopes`: The scopes for OAuth 2.0 to Access Google APIs. See [Google Compute Engine Doc](https://cloud.google.com/storage/docs/authentication). - `--google-scopes`: The scopes for OAuth 2.0 to Access Google APIs. See [Google Compute Engine Doc](https://cloud.google.com/storage/docs/authentication).
- `--google-disk-size`: The disk size of instance. - `--google-disk-size`: The disk size of instance.
@ -51,7 +52,11 @@ $ docker-machine create --driver google \
- `--google-preemptible`: Instance preemptibility. - `--google-preemptible`: Instance preemptibility.
- `--google-tags`: Instance tags (comma-separated). - `--google-tags`: Instance tags (comma-separated).
The driver uses the `ubuntu-1404-trusty-v20150909a` disk image. The GCE driver will use the `ubuntu-1404-trusty-v20150909a` instance image unless otherwise specified. To obtain a
list of image URLs run:
```
gcloud compute images list --uri
```
Environment variables and default values: Environment variables and default values:
@ -60,6 +65,7 @@ Environment variables and default values:
| **`--google-project`** | `GOOGLE_PROJECT` | - | | **`--google-project`** | `GOOGLE_PROJECT` | - |
| `--google-zone` | `GOOGLE_ZONE` | `us-central1-a` | | `--google-zone` | `GOOGLE_ZONE` | `us-central1-a` |
| `--google-machine-type` | `GOOGLE_MACHINE_TYPE` | `n1-standard-1` | | `--google-machine-type` | `GOOGLE_MACHINE_TYPE` | `n1-standard-1` |
| `--google-machine-image` | `GOOGLE_MACHINE_IMAGE`| `ubuntu-1404-trusty-v20150909a` |
| `--google-username` | `GOOGLE_USERNAME` | `docker-user` | | `--google-username` | `GOOGLE_USERNAME` | `docker-user` |
| `--google-scopes` | `GOOGLE_SCOPES` | `devstorage.read_only,logging.write` | | `--google-scopes` | `GOOGLE_SCOPES` | `devstorage.read_only,logging.write` |
| `--google-disk-size` | `GOOGLE_DISK_SIZE` | `10` | | `--google-disk-size` | `GOOGLE_DISK_SIZE` | `10` |

View File

@ -35,7 +35,6 @@ type ComputeUtil struct {
const ( const (
apiURL = "https://www.googleapis.com/compute/v1/projects/" apiURL = "https://www.googleapis.com/compute/v1/projects/"
imageName = "https://www.googleapis.com/compute/v1/projects/ubuntu-os-cloud/global/images/ubuntu-1404-trusty-v20150909a"
firewallRule = "docker-machines" firewallRule = "docker-machines"
port = "2376" port = "2376"
firewallTargetTag = "docker-machine" firewallTargetTag = "docker-machine"
@ -231,7 +230,7 @@ func (c *ComputeUtil) createInstance(d *Driver) error {
if disk == nil || err != nil { if disk == nil || err != nil {
instance.Disks[0].InitializeParams = &raw.AttachedDiskInitializeParams{ instance.Disks[0].InitializeParams = &raw.AttachedDiskInitializeParams{
DiskName: c.diskName(), DiskName: c.diskName(),
SourceImage: imageName, SourceImage: d.MachineImage,
// The maximum supported disk size is 1000GB, the cast should be fine. // The maximum supported disk size is 1000GB, the cast should be fine.
DiskSizeGb: int64(d.DiskSize), DiskSizeGb: int64(d.DiskSize),
DiskType: c.diskType(), DiskType: c.diskType(),

View File

@ -14,21 +14,23 @@ import (
// Driver is a struct compatible with the docker.hosts.drivers.Driver interface. // Driver is a struct compatible with the docker.hosts.drivers.Driver interface.
type Driver struct { type Driver struct {
*drivers.BaseDriver *drivers.BaseDriver
Zone string Zone string
MachineType string MachineType string
DiskType string MachineImage string
Address string DiskType string
Preemptible bool Address string
Scopes string Preemptible bool
DiskSize int Scopes string
Project string DiskSize int
Tags string Project string
Tags string
} }
const ( const (
defaultZone = "us-central1-a" defaultZone = "us-central1-a"
defaultUser = "docker-user" defaultUser = "docker-user"
defaultMachineType = "n1-standard-1" defaultMachineType = "n1-standard-1"
defaultImageName = "https://www.googleapis.com/compute/v1/projects/ubuntu-os-cloud/global/images/ubuntu-1404-trusty-v20150909a"
defaultScopes = "https://www.googleapis.com/auth/devstorage.read_only,https://www.googleapis.com/auth/logging.write" defaultScopes = "https://www.googleapis.com/auth/devstorage.read_only,https://www.googleapis.com/auth/logging.write"
defaultDiskType = "pd-standard" defaultDiskType = "pd-standard"
defaultDiskSize = 10 defaultDiskSize = 10
@ -50,6 +52,12 @@ func (d *Driver) GetCreateFlags() []mcnflag.Flag {
Value: defaultMachineType, Value: defaultMachineType,
EnvVar: "GOOGLE_MACHINE_TYPE", EnvVar: "GOOGLE_MACHINE_TYPE",
}, },
mcnflag.StringFlag{
Name: "google-machine-image",
Usage: "GCE Machine Image Absolute URL",
Value: defaultImageName,
EnvVar: "GOOGLE_MACHINE_IMAGE",
},
mcnflag.StringFlag{ mcnflag.StringFlag{
Name: "google-username", Name: "google-username",
Usage: "GCE User Name", Usage: "GCE User Name",
@ -101,11 +109,12 @@ func (d *Driver) GetCreateFlags() []mcnflag.Flag {
// NewDriver creates a Driver with the specified storePath. // NewDriver creates a Driver with the specified storePath.
func NewDriver(machineName string, storePath string) *Driver { func NewDriver(machineName string, storePath string) *Driver {
return &Driver{ return &Driver{
Zone: defaultZone, Zone: defaultZone,
DiskType: defaultDiskType, DiskType: defaultDiskType,
DiskSize: defaultDiskSize, DiskSize: defaultDiskSize,
MachineType: defaultMachineType, MachineType: defaultMachineType,
Scopes: defaultScopes, MachineImage: defaultImageName,
Scopes: defaultScopes,
BaseDriver: &drivers.BaseDriver{ BaseDriver: &drivers.BaseDriver{
SSHUser: defaultUser, SSHUser: defaultUser,
MachineName: machineName, MachineName: machineName,
@ -141,6 +150,7 @@ func (d *Driver) SetConfigFromFlags(flags drivers.DriverOptions) error {
d.Zone = flags.String("google-zone") d.Zone = flags.String("google-zone")
d.MachineType = flags.String("google-machine-type") d.MachineType = flags.String("google-machine-type")
d.MachineImage = flags.String("google-machine-image")
d.DiskSize = flags.Int("google-disk-size") d.DiskSize = flags.Int("google-disk-size")
d.DiskType = flags.String("google-disk-type") d.DiskType = flags.String("google-disk-type")
d.Address = flags.String("google-address") d.Address = flags.String("google-address")