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

feat(deploy): deploy charts instead of templates

parent 9b9705e7
package main
import (
"encoding/json"
"errors"
"os"
"github.com/codegangsta/cli"
dep "github.com/deis/helm-dm/deploy"
"github.com/deis/helm-dm/format"
"github.com/kubernetes/deployment-manager/chart"
)
func deploy(c *cli.Context) error {
......@@ -35,7 +35,7 @@ func deploy(c *cli.Context) error {
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
}
......@@ -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.")
}
if err := cfg.Prepare(); err != nil {
format.Error("Failed to prepare deployment: %s", err)
fi, err := os.Stat(cfg.Filename)
if err != nil {
return err
}
// For a dry run, print the template and exit.
if dry {
format.Info("Template prepared for %s", cfg.Template.Name)
data, err := json.MarshalIndent(cfg.Template, "", "\t")
if fi.IsDir() {
format.Info("Chart is directory")
c, err := chart.LoadDir(cfg.Filename)
if err != nil {
return err
}
//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
}
format.Msg(string(data))
return nil
cfg.Filename = tfile
}
if err := cfg.Commit(host); err != nil {
format.Error("Failed to commit deployment: %s", err)
return err
if !dry {
if err := uploadTar(cfg.Filename); err != nil {
return err
}
}
return nil
}
func uploadTar(filename string) error {
return nil
}
......@@ -8,6 +8,7 @@ import (
//"strings"
//"github.com/ghodss/yaml"
"github.com/kubernetes/deployment-manager/chart"
"github.com/kubernetes/deployment-manager/common"
//"github.com/kubernetes/deployment-manager/expandybird/expander"
//"github.com/kubernetes/deployment-manager/registry"
......@@ -41,6 +42,8 @@ type Deployment struct {
// The template, typically generated by the Deployment.
Template *common.Template
lchart *chart.Chart
}
// Prepare loads templates and checks for client-side errors.
......@@ -48,23 +51,37 @@ type Deployment struct {
// This will generate the Template based on other information.
func (d *Deployment) Prepare() error {
/*
tpl, err := d.resolveTemplate()
// Is Filename a local dir, a local file, or a remote URL?
fi, err := os.Stat(d.Filename)
if err != nil {
return err
}
var c *chart.Chart
if fi.IsDir() {
c, err = chart.LoadDir(d.Filename)
if err != nil {
return err
}
// If a deployment Name is specified, set that explicitly.
if d.Name != "" {
tpl.Name = d.Name
} else {
c, err = chart.Load(d.Filename)
if err != nil {
return err
}
}
d.Template = tpl
*/
// Override name if we need to
// Properties
d.lchart = c
return nil
}
func (d *Deployment) Chart() *chart.Chart {
return d.lchart
}
// Commit prepares the Deployment and then commits it to the remote processor.
func (d *Deployment) Commit(host string) error {
return nil
......
......@@ -6,6 +6,8 @@ import (
"io"
"io/ioutil"
"net/http"
"os"
"path/filepath"
"time"
"github.com/ghodss/yaml"
......@@ -106,3 +108,48 @@ func (c *Client) ListDeployments() error {
fmt.Printf("%#v\n", d)
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