mirror of https://github.com/docker/docs.git
Merge branch 'libmachine-validate-host-config' into internal-api
This commit is contained in:
commit
d770ea55f3
29
commands.go
29
commands.go
|
@ -374,15 +374,36 @@ func cmdCreate(c *cli.Context) {
|
|||
log.Fatal("You must specify a machine name")
|
||||
}
|
||||
|
||||
if err := setupCertificates(c.GlobalString("tls-ca-cert"), c.GlobalString("tls-ca-key"),
|
||||
c.GlobalString("tls-client-cert"), c.GlobalString("tls-client-key")); err != nil {
|
||||
// setup cert paths
|
||||
caCertPath := c.GlobalString("tls-ca-cert")
|
||||
caKeyPath := c.GlobalString("tls-ca-key")
|
||||
clientCertPath := c.GlobalString("tls-client-cert")
|
||||
clientKeyPath := c.GlobalString("tls-client-key")
|
||||
|
||||
if caCertPath == "" {
|
||||
caCertPath = filepath.Join(utils.GetMachineCertDir(), "ca.pem")
|
||||
}
|
||||
|
||||
if caKeyPath == "" {
|
||||
caKeyPath = filepath.Join(utils.GetMachineCertDir(), "ca-key.pem")
|
||||
}
|
||||
|
||||
if clientCertPath == "" {
|
||||
clientCertPath = filepath.Join(utils.GetMachineCertDir(), "cert.pem")
|
||||
}
|
||||
|
||||
if clientKeyPath == "" {
|
||||
clientKeyPath = filepath.Join(utils.GetMachineCertDir(), "key.pem")
|
||||
}
|
||||
|
||||
if err := setupCertificates(caCertPath, caKeyPath, clientCertPath, clientKeyPath); err != nil {
|
||||
log.Fatalf("Error generating certificates: %s", err)
|
||||
}
|
||||
|
||||
defaultStore, err := getDefaultStore(
|
||||
c.GlobalString("storage-path"),
|
||||
c.GlobalString("tls-ca-cert"),
|
||||
c.GlobalString("tls-ca-key"),
|
||||
caCertPath,
|
||||
caKeyPath,
|
||||
)
|
||||
if err != nil {
|
||||
log.Fatal(err)
|
||||
|
|
|
@ -8,6 +8,8 @@ import (
|
|||
"strings"
|
||||
|
||||
log "github.com/Sirupsen/logrus"
|
||||
"github.com/docker/machine/libmachine/engine"
|
||||
"github.com/docker/machine/libmachine/swarm"
|
||||
"github.com/docker/machine/utils"
|
||||
)
|
||||
|
||||
|
@ -32,7 +34,8 @@ func (s Filestore) loadHost(name string) (*Host, error) {
|
|||
return nil, err
|
||||
}
|
||||
|
||||
return host, nil
|
||||
h := validateHost(host)
|
||||
return h, nil
|
||||
}
|
||||
|
||||
func (s Filestore) GetPath() string {
|
||||
|
@ -146,3 +149,22 @@ func (s Filestore) RemoveActive() error {
|
|||
func (s Filestore) activePath() string {
|
||||
return filepath.Join(utils.GetMachineDir(), ".active")
|
||||
}
|
||||
|
||||
// validates host config and modifies if needed
|
||||
// this is used for configuration updates
|
||||
func validateHost(host *Host) *Host {
|
||||
if host.EngineOptions == nil {
|
||||
host.EngineOptions = &engine.EngineOptions{}
|
||||
}
|
||||
|
||||
if host.SwarmOptions == nil {
|
||||
host.SwarmOptions = &swarm.SwarmOptions{
|
||||
Address: "",
|
||||
Discovery: host.SwarmDiscovery,
|
||||
Host: host.SwarmHost,
|
||||
Master: host.SwarmMaster,
|
||||
}
|
||||
}
|
||||
|
||||
return host
|
||||
}
|
||||
|
|
|
@ -48,6 +48,10 @@ type Host struct {
|
|||
StorePath string
|
||||
EngineOptions *engine.EngineOptions
|
||||
SwarmOptions *swarm.SwarmOptions
|
||||
// deprecated options; these are left to assist in config migrations
|
||||
SwarmHost string
|
||||
SwarmMaster bool
|
||||
SwarmDiscovery string
|
||||
}
|
||||
|
||||
type HostOptions struct {
|
||||
|
|
11
main.go
11
main.go
|
@ -3,7 +3,6 @@ package main
|
|||
import (
|
||||
"os"
|
||||
"path"
|
||||
"path/filepath"
|
||||
|
||||
log "github.com/Sirupsen/logrus"
|
||||
"github.com/codegangsta/cli"
|
||||
|
@ -39,32 +38,32 @@ func main() {
|
|||
cli.StringFlag{
|
||||
EnvVar: "MACHINE_STORAGE_PATH",
|
||||
Name: "storage-path",
|
||||
Value: utils.GetMachineRoot(),
|
||||
Value: utils.GetBaseDir(),
|
||||
Usage: "Configures storage path",
|
||||
},
|
||||
cli.StringFlag{
|
||||
EnvVar: "MACHINE_TLS_CA_CERT",
|
||||
Name: "tls-ca-cert",
|
||||
Usage: "CA to verify remotes against",
|
||||
Value: filepath.Join(utils.GetMachineCertDir(), "ca.pem"),
|
||||
Value: "",
|
||||
},
|
||||
cli.StringFlag{
|
||||
EnvVar: "MACHINE_TLS_CA_KEY",
|
||||
Name: "tls-ca-key",
|
||||
Usage: "Private key to generate certificates",
|
||||
Value: filepath.Join(utils.GetMachineCertDir(), "ca-key.pem"),
|
||||
Value: "",
|
||||
},
|
||||
cli.StringFlag{
|
||||
EnvVar: "MACHINE_TLS_CLIENT_CERT",
|
||||
Name: "tls-client-cert",
|
||||
Usage: "Client cert to use for TLS",
|
||||
Value: filepath.Join(utils.GetMachineCertDir(), "cert.pem"),
|
||||
Value: "",
|
||||
},
|
||||
cli.StringFlag{
|
||||
EnvVar: "MACHINE_TLS_CLIENT_KEY",
|
||||
Name: "tls-client-key",
|
||||
Usage: "Private key used in client TLS auth",
|
||||
Value: filepath.Join(utils.GetMachineCertDir(), "key.pem"),
|
||||
Value: "",
|
||||
},
|
||||
}
|
||||
|
||||
|
|
|
@ -0,0 +1,24 @@
|
|||
{
|
||||
"DriverName": "virtualbox",
|
||||
"Driver": {
|
||||
"MachineName": "test-vbox",
|
||||
"SSHUser": "docker",
|
||||
"SSHPort": 45515,
|
||||
"Memory": 1024,
|
||||
"DiskSize": 20000,
|
||||
"Boot2DockerURL": "",
|
||||
"CaCertPath": "/tmp/store/certs/ca.pem",
|
||||
"PrivateKeyPath": "/tmp/store/certs/ca-key.pem",
|
||||
"SwarmMaster": false,
|
||||
"SwarmHost": "tcp://0.0.0.0:3376",
|
||||
"SwarmDiscovery": ""
|
||||
},
|
||||
"CaCertPath": "/tmp/store/certs/ca.pem",
|
||||
"ServerCertPath": "",
|
||||
"ServerKeyPath": "",
|
||||
"PrivateKeyPath": "/tmp/store/certs/ca-key.pem",
|
||||
"ClientCertPath": "",
|
||||
"SwarmMaster": false,
|
||||
"SwarmHost": "tcp://0.0.0.0:3376",
|
||||
"SwarmDiscovery": ""
|
||||
}
|
|
@ -0,0 +1,49 @@
|
|||
{
|
||||
"DriverName": "virtualbox",
|
||||
"Driver": {
|
||||
"MachineName": "test-vbox",
|
||||
"SSHUser": "docker",
|
||||
"SSHPort": 51575,
|
||||
"Memory": 1024,
|
||||
"DiskSize": 20000,
|
||||
"Boot2DockerURL": "",
|
||||
"CaCertPath": "/tmp/store/certs/ca.pem",
|
||||
"PrivateKeyPath": "/tmp/store/certs/ca-key.pem",
|
||||
"SwarmMaster": false,
|
||||
"SwarmHost": "tcp://0.0.0.0:3376",
|
||||
"SwarmDiscovery": ""
|
||||
},
|
||||
"CaCertPath": "/tmp/store/certs/ca.pem",
|
||||
"PrivateKeyPath": "/tmp/store/certs/ca-key.pem",
|
||||
"ServerCertPath": "",
|
||||
"ServerKeyPath": "",
|
||||
"ClientCertPath": "",
|
||||
"StorePath": "/tmp/store/machines/test-vbox",
|
||||
"EngineOptions": {
|
||||
"Dns": null,
|
||||
"GraphDir": "",
|
||||
"Ipv6": false,
|
||||
"Labels": null,
|
||||
"LogLevel": "",
|
||||
"StorageDriver": "",
|
||||
"SelinuxEnabled": false,
|
||||
"TlsCaCert": "",
|
||||
"TlsCert": "",
|
||||
"TlsKey": "",
|
||||
"TlsVerify": false,
|
||||
"RegistryMirror": null
|
||||
},
|
||||
"SwarmOptions": {
|
||||
"Address": "",
|
||||
"Discovery": "",
|
||||
"Master": false,
|
||||
"Host": "",
|
||||
"Strategy": "",
|
||||
"Heartbeat": 0,
|
||||
"Overcommit": 0,
|
||||
"TlsCaCert": "",
|
||||
"TlsCert": "",
|
||||
"TlsKey": "",
|
||||
"TlsVerify": false
|
||||
}
|
||||
}
|
|
@ -22,7 +22,7 @@ func GetHomeDir() string {
|
|||
func GetBaseDir() string {
|
||||
baseDir := os.Getenv("MACHINE_STORAGE_PATH")
|
||||
if baseDir == "" {
|
||||
baseDir = filepath.Join(GetHomeDir(), ".docker")
|
||||
baseDir = filepath.Join(GetHomeDir(), ".docker", "machine")
|
||||
}
|
||||
return baseDir
|
||||
}
|
||||
|
@ -31,20 +31,16 @@ func GetDockerDir() string {
|
|||
return filepath.Join(GetHomeDir(), ".docker")
|
||||
}
|
||||
|
||||
func GetMachineRoot() string {
|
||||
return filepath.Join(GetBaseDir(), "machine")
|
||||
}
|
||||
|
||||
func GetMachineDir() string {
|
||||
return filepath.Join(GetMachineRoot(), "machines")
|
||||
return filepath.Join(GetBaseDir(), "machines")
|
||||
}
|
||||
|
||||
func GetMachineCertDir() string {
|
||||
return filepath.Join(GetMachineRoot(), "certs")
|
||||
return filepath.Join(GetBaseDir(), "certs")
|
||||
}
|
||||
|
||||
func GetMachineCacheDir() string {
|
||||
return filepath.Join(GetMachineRoot(), "cache")
|
||||
return filepath.Join(GetBaseDir(), "cache")
|
||||
}
|
||||
|
||||
func GetUsername() string {
|
||||
|
|
Loading…
Reference in New Issue