Commit 84146a29 authored by Matt Butcher's avatar Matt Butcher

feat(deploy): upload chart if its local

parent b4c31808
...@@ -2,6 +2,7 @@ package main ...@@ -2,6 +2,7 @@ package main
import ( import (
"io/ioutil" "io/ioutil"
"os"
"github.com/codegangsta/cli" "github.com/codegangsta/cli"
"github.com/kubernetes/deployment-manager/common" "github.com/kubernetes/deployment-manager/common"
...@@ -60,7 +61,17 @@ func deploy(c *cli.Context) error { ...@@ -60,7 +61,17 @@ func deploy(c *cli.Context) error {
// file with it. // file with it.
args := c.Args() args := c.Args()
if len(args) > 0 { 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. // Override the name if one is passed in.
...@@ -82,6 +93,12 @@ func deploy(c *cli.Context) error { ...@@ -82,6 +93,12 @@ func deploy(c *cli.Context) error {
return client(c).PostDeployment(cfg) 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. // loadConfig loads a file into a common.Configuration.
func loadConfig(c *common.Configuration, filename string) error { func loadConfig(c *common.Configuration, filename string) error {
data, err := ioutil.ReadFile(filename) data, err := ioutil.ReadFile(filename)
......
...@@ -174,18 +174,21 @@ func (c *Client) ListDeployments() ([]string, error) { ...@@ -174,18 +174,21 @@ func (c *Client) ListDeployments() ([]string, error) {
return l, nil return l, nil
} }
// UploadChart sends a chart to DM for deploying. // PostChart sends a chart to DM for deploying.
func (c *Client) PostChart(filename, deployname string) error { //
// 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) f, err := os.Open(filename)
if err != nil { if err != nil {
return err return "", err
} }
u, err := c.url("/v2/charts") u, err := c.url("/v2/charts")
request, err := http.NewRequest("POST", u, f) request, err := http.NewRequest("POST", u, f)
if err != nil { if err != nil {
f.Close() f.Close()
return err return "", err
} }
// There is an argument to be made for using the legacy x-octet-stream for // 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 { ...@@ -206,7 +209,7 @@ func (c *Client) PostChart(filename, deployname string) error {
response, err := client.Do(request) response, err := client.Do(request)
if err != nil { if err != nil {
return err return "", err
} }
// We only want 201 CREATED. Admittedly, we could accept 200 and 202. // We only want 201 CREATED. Admittedly, we could accept 200 and 202.
...@@ -214,12 +217,13 @@ func (c *Client) PostChart(filename, deployname string) error { ...@@ -214,12 +217,13 @@ func (c *Client) PostChart(filename, deployname string) error {
body, err := ioutil.ReadAll(response.Body) body, err := ioutil.ReadAll(response.Body)
response.Body.Close() response.Body.Close()
if err != nil { 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. // HTTPError is an error caused by an unexpected HTTP status code.
......
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