Commit 9b494f55 authored by Matt Butcher's avatar Matt Butcher

feat(deploy): deploy charts instead of templates

parent 9b9705e7
package main package main
import ( import (
"encoding/json"
"errors" "errors"
"os" "os"
"github.com/codegangsta/cli" "github.com/codegangsta/cli"
dep "github.com/deis/helm-dm/deploy" dep "github.com/deis/helm-dm/deploy"
"github.com/deis/helm-dm/format" "github.com/deis/helm-dm/format"
"github.com/kubernetes/deployment-manager/chart"
) )
func deploy(c *cli.Context) error { func deploy(c *cli.Context) error {
...@@ -35,7 +35,7 @@ func deploy(c *cli.Context) error { ...@@ -35,7 +35,7 @@ func deploy(c *cli.Context) error {
d.Input = os.Stdin d.Input = os.Stdin
} }
//return doDeploy(d, c.GlobalString("host"), c.Bool("dry-run")) return doDeploy(d, c.GlobalString("host"), c.Bool("dry-run"))
return nil return nil
} }
...@@ -44,26 +44,43 @@ func doDeploy(cfg *dep.Deployment, host string, dry bool) error { ...@@ -44,26 +44,43 @@ func doDeploy(cfg *dep.Deployment, host string, dry bool) error {
return errors.New("A filename must be specified. For a tar archive, this is the name of the root template in the archive.") return errors.New("A filename must be specified. For a tar archive, this is the name of the root template in the archive.")
} }
if err := cfg.Prepare(); err != nil { fi, err := os.Stat(cfg.Filename)
format.Error("Failed to prepare deployment: %s", err) if err != nil {
return err return err
} }
// For a dry run, print the template and exit. if fi.IsDir() {
if dry { format.Info("Chart is directory")
format.Info("Template prepared for %s", cfg.Template.Name) c, err := chart.LoadDir(cfg.Filename)
data, err := json.MarshalIndent(cfg.Template, "", "\t")
if err != nil { if err != nil {
return err return err
} }
format.Msg(string(data))
return nil //tdir, err := ioutil.TempDir("", "helm-")
//if err != nil {
//format.Warn("Could not create temporary directory. Using .")
//tdir = "."
//} else {
//defer os.RemoveAll(tdir)
//}
tdir := "."
tfile, err := chart.Save(c, tdir)
if err != nil {
return err
} }
cfg.Filename = tfile
if err := cfg.Commit(host); err != nil { }
format.Error("Failed to commit deployment: %s", err)
if !dry {
if err := uploadTar(cfg.Filename); err != nil {
return err return err
} }
}
return nil
}
func uploadTar(filename string) error {
return nil return nil
} }
...@@ -8,6 +8,7 @@ import ( ...@@ -8,6 +8,7 @@ import (
//"strings" //"strings"
//"github.com/ghodss/yaml" //"github.com/ghodss/yaml"
"github.com/kubernetes/deployment-manager/chart"
"github.com/kubernetes/deployment-manager/common" "github.com/kubernetes/deployment-manager/common"
//"github.com/kubernetes/deployment-manager/expandybird/expander" //"github.com/kubernetes/deployment-manager/expandybird/expander"
//"github.com/kubernetes/deployment-manager/registry" //"github.com/kubernetes/deployment-manager/registry"
...@@ -41,6 +42,8 @@ type Deployment struct { ...@@ -41,6 +42,8 @@ type Deployment struct {
// The template, typically generated by the Deployment. // The template, typically generated by the Deployment.
Template *common.Template Template *common.Template
lchart *chart.Chart
} }
// Prepare loads templates and checks for client-side errors. // Prepare loads templates and checks for client-side errors.
...@@ -48,23 +51,37 @@ type Deployment struct { ...@@ -48,23 +51,37 @@ type Deployment struct {
// This will generate the Template based on other information. // This will generate the Template based on other information.
func (d *Deployment) Prepare() error { func (d *Deployment) Prepare() error {
/* // Is Filename a local dir, a local file, or a remote URL?
tpl, err := d.resolveTemplate() fi, err := os.Stat(d.Filename)
if err != nil { if err != nil {
return err return err
} }
// If a deployment Name is specified, set that explicitly. var c *chart.Chart
if d.Name != "" { if fi.IsDir() {
tpl.Name = d.Name c, err = chart.LoadDir(d.Filename)
if err != nil {
return err
} }
} else {
c, err = chart.Load(d.Filename)
if err != nil {
return err
}
}
// Override name if we need to
d.Template = tpl // Properties
*/
d.lchart = c
return nil return nil
} }
func (d *Deployment) Chart() *chart.Chart {
return d.lchart
}
// Commit prepares the Deployment and then commits it to the remote processor. // Commit prepares the Deployment and then commits it to the remote processor.
func (d *Deployment) Commit(host string) error { func (d *Deployment) Commit(host string) error {
return nil return nil
......
...@@ -6,6 +6,8 @@ import ( ...@@ -6,6 +6,8 @@ import (
"io" "io"
"io/ioutil" "io/ioutil"
"net/http" "net/http"
"os"
"path/filepath"
"time" "time"
"github.com/ghodss/yaml" "github.com/ghodss/yaml"
...@@ -106,3 +108,48 @@ func (c *Client) ListDeployments() error { ...@@ -106,3 +108,48 @@ func (c *Client) ListDeployments() error {
fmt.Printf("%#v\n", d) fmt.Printf("%#v\n", d)
return nil return nil
} }
func (c *Client) DeployChart(filename, deployname string) error {
f, err := os.Open(filename)
if err != nil {
return err
}
defer f.Close()
request, err := http.NewRequest("POST", "/v2/deployments/", f)
// There is an argument to be made for using the legacy x-octet-stream for
// this. But since we control both sides, we should use the standard one.
// Also, gzip (x-compress) is usually treated as a content encoding. In this
// case it probably is not, but it makes more sense to follow the standard,
// even though we don't assume the remote server will strip it off.
request.Header.Add("Content-Type", "application/x-tar")
request.Header.Add("Content-Encoding", "gzip")
request.Header.Add("X-Deployment-Name", deployname)
request.Header.Add("X-Chart-Name", filepath.Base(filename))
client := http.Client{
Timeout: time.Duration(time.Duration(DefaultHTTPTimeout) * time.Second),
Transport: c.Transport,
}
response, err := client.Do(request)
if err != nil {
return err
}
body, err := ioutil.ReadAll(response.Body)
response.Body.Close()
if err != nil {
return err
}
// FIXME: We only want 200 OK or 204(?) CREATED
if response.StatusCode < http.StatusOK ||
response.StatusCode >= http.StatusMultipleChoices {
message := fmt.Sprintf("status code: %d status: %s : %s", response.StatusCode, response.Status, body)
return fmt.Errorf("Failed to post: %s", message)
}
return nil
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment