mirror of https://github.com/helm/helm
parent
bb8fca9b69
commit
00b9356a95
@ -0,0 +1,29 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"os"
|
||||
|
||||
"github.com/deis/tiller/pkg/repo"
|
||||
"github.com/spf13/cobra"
|
||||
)
|
||||
|
||||
var serveDesc = `This command starts a local chart repository server that serves the charts saved in your $HELM_HOME/local/ directory.`
|
||||
|
||||
//TODO: add repoPath flag to be passed in in case you want
|
||||
// to serve charts from a different local dir
|
||||
|
||||
func init() {
|
||||
RootCommand.AddCommand(serveCmd)
|
||||
}
|
||||
|
||||
var serveCmd = &cobra.Command{
|
||||
Use: "serve",
|
||||
Short: "Start a local http web server",
|
||||
Long: serveDesc,
|
||||
Run: ServeLocal,
|
||||
}
|
||||
|
||||
func ServeLocal(cmd *cobra.Command, args []string) {
|
||||
localRepoPath := os.ExpandEnv(helmHome) + "/local/"
|
||||
repo.StartLocalRepo(localRepoPath)
|
||||
}
|
@ -0,0 +1,36 @@
|
||||
package repo
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"net/http"
|
||||
"strings"
|
||||
)
|
||||
|
||||
var localRepoPath string
|
||||
|
||||
func StartLocalRepo(path string) {
|
||||
fmt.Println("Now serving you on localhost:8879...")
|
||||
localRepoPath = path
|
||||
http.HandleFunc("/", homeHandler)
|
||||
http.HandleFunc("/charts/", indexHandler)
|
||||
http.ListenAndServe(":8879", nil)
|
||||
}
|
||||
func homeHandler(w http.ResponseWriter, r *http.Request) {
|
||||
fmt.Fprintf(w, "Welcome to the Kubernetes Package manager!\nBrowse charts on localhost:8879/charts!")
|
||||
}
|
||||
func indexHandler(w http.ResponseWriter, r *http.Request) {
|
||||
file := r.URL.Path[len("/charts/"):]
|
||||
if len(strings.Split(file, ".")) > 1 {
|
||||
serveFile(w, r, file)
|
||||
} else if file == "" {
|
||||
fmt.Fprintf(w, "list of charts should be here at some point")
|
||||
} else if file == "cache" {
|
||||
fmt.Fprintf(w, "cache file data should be here at some point")
|
||||
} else {
|
||||
fmt.Fprintf(w, "Ummm... Nothing to see here folks")
|
||||
}
|
||||
}
|
||||
|
||||
func serveFile(w http.ResponseWriter, r *http.Request, file string) {
|
||||
http.ServeFile(w, r, localRepoPath+file)
|
||||
}
|
Loading…
Reference in new issue