feat(deploy): upload chart if its local

pull/291/head
Matt Butcher 9 years ago
parent b4c31808eb
commit 84146a29cd

@ -2,6 +2,7 @@ package main
import (
"io/ioutil"
"os"
"github.com/codegangsta/cli"
"github.com/kubernetes/deployment-manager/common"
@ -60,7 +61,17 @@ func deploy(c *cli.Context) error {
// file with it.
args := c.Args()
if len(args) > 0 {
cfg.Resources[0].Type = args[0]
cname := args[0]
if isLocalChart(cname) {
// If we get here, we need to first package then upload the chart.
loc, err := doUpload(cname, "", c)
if err != nil {
return err
}
cfg.Resources[0].Name = loc
} else {
cfg.Resources[0].Type = cname
}
}
// Override the name if one is passed in.
@ -82,6 +93,12 @@ func deploy(c *cli.Context) error {
return client(c).PostDeployment(cfg)
}
// isLocalChart returns true if the given path can be statted.
func isLocalChart(path string) bool {
_, err := os.Stat(path)
return err == nil
}
// loadConfig loads a file into a common.Configuration.
func loadConfig(c *common.Configuration, filename string) error {
data, err := ioutil.ReadFile(filename)

@ -174,18 +174,21 @@ func (c *Client) ListDeployments() ([]string, error) {
return l, nil
}
// UploadChart sends a chart to DM for deploying.
func (c *Client) PostChart(filename, deployname string) error {
// PostChart sends a chart to DM for deploying.
//
// This returns the location for the new chart, typically of the form
// `helm:repo/bucket/name-version.tgz`.
func (c *Client) PostChart(filename, deployname string) (string, error) {
f, err := os.Open(filename)
if err != nil {
return err
return "", err
}
u, err := c.url("/v2/charts")
request, err := http.NewRequest("POST", u, f)
if err != nil {
f.Close()
return err
return "", err
}
// There is an argument to be made for using the legacy x-octet-stream for
@ -206,7 +209,7 @@ func (c *Client) PostChart(filename, deployname string) error {
response, err := client.Do(request)
if err != nil {
return err
return "", err
}
// We only want 201 CREATED. Admittedly, we could accept 200 and 202.
@ -214,12 +217,13 @@ func (c *Client) PostChart(filename, deployname string) error {
body, err := ioutil.ReadAll(response.Body)
response.Body.Close()
if err != nil {
return err
return "", err
}
return &HTTPError{StatusCode: response.StatusCode, Message: string(body), URL: request.URL}
return "", &HTTPError{StatusCode: response.StatusCode, Message: string(body), URL: request.URL}
}
return nil
loc := response.Header.Get("Location")
return loc, nil
}
// HTTPError is an error caused by an unexpected HTTP status code.

Loading…
Cancel
Save