mirror of https://github.com/docker/docs.git
Merge pull request #11 from bfirsh/cloud-backend-fixes
This commit is contained in:
commit
b69fb4ec3b
|
@ -52,19 +52,19 @@ type cloud struct {
|
||||||
}
|
}
|
||||||
|
|
||||||
type Container struct {
|
type Container struct {
|
||||||
Id string
|
Id string
|
||||||
Image string
|
Image string
|
||||||
Tty bool
|
Tty bool
|
||||||
}
|
}
|
||||||
|
|
||||||
// returns true, if the connection was successful, false otherwise
|
// returns true, if the connection was successful, false otherwise
|
||||||
type Tunnel struct {
|
type Tunnel struct {
|
||||||
url.URL
|
url.URL
|
||||||
}
|
}
|
||||||
|
|
||||||
func (t Tunnel) isActive() bool {
|
func (t Tunnel) isActive() bool {
|
||||||
_, err := http.Get(t.String())
|
_, err := http.Get(t.String())
|
||||||
return err == nil
|
return err == nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (s *cloud) Install(eng *engine.Engine) error {
|
func (s *cloud) Install(eng *engine.Engine) error {
|
||||||
|
@ -83,7 +83,7 @@ func (s *cloud) Install(eng *engine.Engine) error {
|
||||||
}
|
}
|
||||||
cloud, err = NewCloudGCE(job.Args[3])
|
cloud, err = NewCloudGCE(job.Args[3])
|
||||||
if err != nil {
|
if err != nil {
|
||||||
job.Errorf("Unexpected error: %#v", err)
|
return job.Errorf("Unexpected error: %#v", err)
|
||||||
}
|
}
|
||||||
default:
|
default:
|
||||||
return job.Errorf("Unknown cloud provider: %s", job.Args[0])
|
return job.Errorf("Unknown cloud provider: %s", job.Args[0])
|
||||||
|
@ -91,39 +91,39 @@ func (s *cloud) Install(eng *engine.Engine) error {
|
||||||
ip, err := cloud.GetPublicIPAddress(instance, zone)
|
ip, err := cloud.GetPublicIPAddress(instance, zone)
|
||||||
instanceRunning := len(ip) > 0
|
instanceRunning := len(ip) > 0
|
||||||
if !instanceRunning {
|
if !instanceRunning {
|
||||||
log.Print("Instance doesn't exist, creating....");
|
log.Print("Instance doesn't exist, creating....")
|
||||||
_, err = cloud.CreateInstance(instance, zone)
|
_, err = cloud.CreateInstance(instance, zone)
|
||||||
}
|
}
|
||||||
if err != nil {
|
if err != nil {
|
||||||
job.Errorf("Unexpected error: %#v", err)
|
return job.Errorf("Unexpected error: %#v", err)
|
||||||
}
|
}
|
||||||
remotePort := 8000
|
remotePort := 8000
|
||||||
localPort := 8001
|
localPort := 8001
|
||||||
apiVersion := "v1.10"
|
apiVersion := "v1.10"
|
||||||
tunnelUrl, err := url.Parse(fmt.Sprintf("http://localhost:%d/%s/containers/json", localPort, apiVersion))
|
tunnelUrl, err := url.Parse(fmt.Sprintf("http://localhost:%d/%s/containers/json", localPort, apiVersion))
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return job.Errorf("Unexpected error: %#v", err)
|
return job.Errorf("Unexpected error: %#v", err)
|
||||||
}
|
}
|
||||||
tunnel := Tunnel{*tunnelUrl}
|
tunnel := Tunnel{*tunnelUrl}
|
||||||
|
|
||||||
if !tunnel.isActive() {
|
if !tunnel.isActive() {
|
||||||
fmt.Printf("Creating tunnel")
|
fmt.Printf("Creating tunnel")
|
||||||
_, err = cloud.OpenSecureTunnel(instance, zone, localPort, remotePort)
|
_, err = cloud.OpenSecureTunnel(instance, zone, localPort, remotePort)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
job.Errorf("Failed to open tunnel: %#v", err)
|
return job.Errorf("Failed to open tunnel: %#v", err)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
host := fmt.Sprintf("tcp://localhost:%d", localPort)
|
host := fmt.Sprintf("tcp://localhost:%d", localPort)
|
||||||
client, err := newClient(host, apiVersion)
|
client, err := newClient(host, apiVersion)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
job.Errorf("Unexpected error: %#v", err)
|
return job.Errorf("Unexpected error: %#v", err)
|
||||||
}
|
}
|
||||||
//job.Eng.Register("inspect", func(job *engine.Job) engine.Status {
|
//job.Eng.Register("inspect", func(job *engine.Job) engine.Status {
|
||||||
// resp, err := client.call("GET", "/containers/
|
// resp, err := client.call("GET", "/containers/
|
||||||
job.Eng.Register("create", func(job *engine.Job) engine.Status {
|
job.Eng.Register("create", func(job *engine.Job) engine.Status {
|
||||||
container := Container{
|
container := Container{
|
||||||
Image: job.Getenv("Image"),
|
Image: job.Getenv("Image"),
|
||||||
Tty: job.Getenv("Tty") == "true",
|
Tty: job.Getenv("Tty") == "true",
|
||||||
}
|
}
|
||||||
data, err := json.Marshal(container)
|
data, err := json.Marshal(container)
|
||||||
resp, err := client.call("POST", "/containers/create", string(data))
|
resp, err := client.call("POST", "/containers/create", string(data))
|
||||||
|
@ -143,7 +143,7 @@ func (s *cloud) Install(eng *engine.Engine) error {
|
||||||
log.Printf("%s", string(body))
|
log.Printf("%s", string(body))
|
||||||
return engine.StatusOK
|
return engine.StatusOK
|
||||||
})
|
})
|
||||||
|
|
||||||
job.Eng.Register("start", func(job *engine.Job) engine.Status {
|
job.Eng.Register("start", func(job *engine.Job) engine.Status {
|
||||||
path := fmt.Sprintf("/containers/%s/start", job.Args[0])
|
path := fmt.Sprintf("/containers/%s/start", job.Args[0])
|
||||||
resp, err := client.call("POST", path, "{\"Binds\":[],\"ContainerIDFile\":\"\",\"LxcConf\":[],\"Privileged\":false,\"PortBindings\":{},\"Links\":null,\"PublishAllPorts\":false,\"Dns\":null,\"DnsSearch\":[],\"VolumesFrom\":[]}")
|
resp, err := client.call("POST", path, "{\"Binds\":[],\"ContainerIDFile\":\"\",\"LxcConf\":[],\"Privileged\":false,\"PortBindings\":{},\"Links\":null,\"PublishAllPorts\":false,\"Dns\":null,\"DnsSearch\":[],\"VolumesFrom\":[]}")
|
||||||
|
@ -184,11 +184,11 @@ func (s *cloud) Install(eng *engine.Engine) error {
|
||||||
c.WriteListTo(job.Stdout)
|
c.WriteListTo(job.Stdout)
|
||||||
return engine.StatusOK
|
return engine.StatusOK
|
||||||
})
|
})
|
||||||
|
|
||||||
job.Eng.Register("container_delete", func(job *engine.Job) engine.Status {
|
job.Eng.Register("container_delete", func(job *engine.Job) engine.Status {
|
||||||
log.Printf("%#v", job.Args)
|
log.Printf("%#v", job.Args)
|
||||||
path := "/containers/" + job.Args[0]
|
path := "/containers/" + job.Args[0]
|
||||||
|
|
||||||
resp, err := client.call("DELETE", path, "")
|
resp, err := client.call("DELETE", path, "")
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return job.Errorf("%s: delete: %v", client.URL.String(), err)
|
return job.Errorf("%s: delete: %v", client.URL.String(), err)
|
||||||
|
@ -196,11 +196,11 @@ func (s *cloud) Install(eng *engine.Engine) error {
|
||||||
log.Printf("%#v", resp)
|
log.Printf("%#v", resp)
|
||||||
return engine.StatusOK
|
return engine.StatusOK
|
||||||
})
|
})
|
||||||
|
|
||||||
job.Eng.Register("stop", func(job *engine.Job) engine.Status {
|
job.Eng.Register("stop", func(job *engine.Job) engine.Status {
|
||||||
log.Printf("%#v", job.Args)
|
log.Printf("%#v", job.Args)
|
||||||
path := "/containers/" + job.Args[0] + "/stop"
|
path := "/containers/" + job.Args[0] + "/stop"
|
||||||
|
|
||||||
resp, err := client.call("POST", path, "")
|
resp, err := client.call("POST", path, "")
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return job.Errorf("%s: delete: %v", client.URL.String(), err)
|
return job.Errorf("%s: delete: %v", client.URL.String(), err)
|
||||||
|
@ -208,7 +208,7 @@ func (s *cloud) Install(eng *engine.Engine) error {
|
||||||
log.Printf("%#v", resp)
|
log.Printf("%#v", resp)
|
||||||
return engine.StatusOK
|
return engine.StatusOK
|
||||||
})
|
})
|
||||||
|
|
||||||
job.Eng.RegisterCatchall(func(job *engine.Job) engine.Status {
|
job.Eng.RegisterCatchall(func(job *engine.Job) engine.Status {
|
||||||
log.Printf("%#v %#v %#v", *job, job.Env(), job.Args)
|
log.Printf("%#v %#v %#v", *job, job.Env(), job.Args)
|
||||||
return engine.StatusOK
|
return engine.StatusOK
|
||||||
|
|
|
@ -28,7 +28,7 @@ import (
|
||||||
"path"
|
"path"
|
||||||
"strings"
|
"strings"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
"code.google.com/p/goauth2/oauth"
|
"code.google.com/p/goauth2/oauth"
|
||||||
compute "code.google.com/p/google-api-go-client/compute/v1"
|
compute "code.google.com/p/google-api-go-client/compute/v1"
|
||||||
)
|
)
|
||||||
|
|
Loading…
Reference in New Issue