|
|
@ -13,15 +13,18 @@ import (
|
|
|
|
|
|
|
|
|
|
|
|
var localRepoPath string
|
|
|
|
var localRepoPath string
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// CacheFile represents the cache file in a chart repository
|
|
|
|
type CacheFile struct {
|
|
|
|
type CacheFile struct {
|
|
|
|
Entries map[string]*ChartRef
|
|
|
|
Entries map[string]*ChartRef
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// ChartRef represents a chart entry in the CacheFile
|
|
|
|
type ChartRef struct {
|
|
|
|
type ChartRef struct {
|
|
|
|
Name string
|
|
|
|
Name string
|
|
|
|
Url string
|
|
|
|
URL string
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// StartLocalRepo starts a web server and serves files from the given path
|
|
|
|
func StartLocalRepo(path string) {
|
|
|
|
func StartLocalRepo(path string) {
|
|
|
|
fmt.Println("Now serving you on localhost:8879...")
|
|
|
|
fmt.Println("Now serving you on localhost:8879...")
|
|
|
|
localRepoPath = path
|
|
|
|
localRepoPath = path
|
|
|
@ -49,6 +52,7 @@ func serveFile(w http.ResponseWriter, r *http.Request, file string) {
|
|
|
|
http.ServeFile(w, r, filepath.Join(localRepoPath, file))
|
|
|
|
http.ServeFile(w, r, filepath.Join(localRepoPath, file))
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// AddChartToLocalRepo saves a chart in the given path and then reindexes the cache file
|
|
|
|
func AddChartToLocalRepo(ch *chart.Chart, path string) error {
|
|
|
|
func AddChartToLocalRepo(ch *chart.Chart, path string) error {
|
|
|
|
name, err := chart.Save(ch, path)
|
|
|
|
name, err := chart.Save(ch, path)
|
|
|
|
if err != nil {
|
|
|
|
if err != nil {
|
|
|
@ -62,6 +66,7 @@ func AddChartToLocalRepo(ch *chart.Chart, path string) error {
|
|
|
|
return nil
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// LoadCacheFile takes a file at the given path and returns a CacheFile object
|
|
|
|
func LoadCacheFile(path string) (*CacheFile, error) {
|
|
|
|
func LoadCacheFile(path string) (*CacheFile, error) {
|
|
|
|
b, err := ioutil.ReadFile(path)
|
|
|
|
b, err := ioutil.ReadFile(path)
|
|
|
|
if err != nil {
|
|
|
|
if err != nil {
|
|
|
@ -77,6 +82,7 @@ func LoadCacheFile(path string) (*CacheFile, error) {
|
|
|
|
return &y, nil
|
|
|
|
return &y, nil
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// ReindexCacheFile adds an entry to the cache file at the given path
|
|
|
|
func ReindexCacheFile(ch *chart.Chart, path string) error {
|
|
|
|
func ReindexCacheFile(ch *chart.Chart, path string) error {
|
|
|
|
name := ch.Chartfile().Name + "-" + ch.Chartfile().Version
|
|
|
|
name := ch.Chartfile().Name + "-" + ch.Chartfile().Version
|
|
|
|
y, err := LoadCacheFile(path)
|
|
|
|
y, err := LoadCacheFile(path)
|
|
|
@ -93,7 +99,7 @@ func ReindexCacheFile(ch *chart.Chart, path string) error {
|
|
|
|
if !found {
|
|
|
|
if !found {
|
|
|
|
url := "localhost:8879/charts/" + name + ".tgz"
|
|
|
|
url := "localhost:8879/charts/" + name + ".tgz"
|
|
|
|
|
|
|
|
|
|
|
|
out, err := y.InsertChartEntry(name, url)
|
|
|
|
out, err := y.insertChartEntry(name, url)
|
|
|
|
if err != nil {
|
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
}
|
|
|
@ -102,6 +108,8 @@ func ReindexCacheFile(ch *chart.Chart, path string) error {
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return nil
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// UnmarshalYAML unmarshals the cache file
|
|
|
|
func (c *CacheFile) UnmarshalYAML(unmarshal func(interface{}) error) error {
|
|
|
|
func (c *CacheFile) UnmarshalYAML(unmarshal func(interface{}) error) error {
|
|
|
|
var refs map[string]*ChartRef
|
|
|
|
var refs map[string]*ChartRef
|
|
|
|
if err := unmarshal(&refs); err != nil {
|
|
|
|
if err := unmarshal(&refs); err != nil {
|
|
|
@ -113,13 +121,13 @@ func (c *CacheFile) UnmarshalYAML(unmarshal func(interface{}) error) error {
|
|
|
|
return nil
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
func (cache *CacheFile) InsertChartEntry(name string, url string) ([]byte, error) {
|
|
|
|
func (c *CacheFile) insertChartEntry(name string, url string) ([]byte, error) {
|
|
|
|
if cache.Entries == nil {
|
|
|
|
if c.Entries == nil {
|
|
|
|
cache.Entries = make(map[string]*ChartRef)
|
|
|
|
c.Entries = make(map[string]*ChartRef)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
entry := ChartRef{Name: name, Url: url}
|
|
|
|
entry := ChartRef{Name: name, URL: url}
|
|
|
|
cache.Entries[name] = &entry
|
|
|
|
c.Entries[name] = &entry
|
|
|
|
out, err := yaml.Marshal(&cache.Entries)
|
|
|
|
out, err := yaml.Marshal(&c.Entries)
|
|
|
|
if err != nil {
|
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
}
|
|
|
|