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))
|
||||||
|
|
Loading…
Reference in New Issue