Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow to bind chartmuseum to a specific interface #345

Merged
merged 2 commits into from
Jul 14, 2020
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion cmd/chartmuseum/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@ func cliHandler(c *cli.Context) {
crash(err)
}

server.Listen(conf.GetInt("port"))
server.Listen(conf.GetString("listen.host"), conf.GetInt("port"))
}

func backendFromConfig(conf *config.Config) storage.Backend {
Expand Down
6 changes: 3 additions & 3 deletions pkg/chartmuseum/router/router.go
Original file line number Diff line number Diff line change
Expand Up @@ -163,13 +163,13 @@ func NewRouter(options RouterOptions) *Router {
return router
}

func (router *Router) Start(port int) {
func (router *Router) Start(host string, port int) {
router.Logger.Infow("Starting ChartMuseum",
"port", port,
"host", host, "port", port,
)

server := http.Server{
Addr: fmt.Sprintf(":%d", port),
Addr: fmt.Sprintf("%s:%d", host, port),
Handler: router,
ReadTimeout: router.ReadTimeout,
WriteTimeout: router.WriteTimeout,
Expand Down
2 changes: 1 addition & 1 deletion pkg/chartmuseum/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ type (

// Server is a generic interface for web servers
Server interface {
Listen(port int)
Listen(host string, port int)
}
)

Expand Down
4 changes: 2 additions & 2 deletions pkg/chartmuseum/server/multitenant/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -147,8 +147,8 @@ func NewMultiTenantServer(options MultiTenantServerOptions) (*MultiTenantServer,
}

// Listen starts the router on a given port
func (server *MultiTenantServer) Listen(port int) {
server.Router.Start(port)
func (server *MultiTenantServer) Listen(host string, port int) {
server.Router.Start(host, port)
}

func (server *MultiTenantServer) genIndex() {
Expand Down
9 changes: 9 additions & 0 deletions pkg/config/vars.go
Original file line number Diff line number Diff line change
Expand Up @@ -739,6 +739,15 @@ var configVars = map[string]configVar{
EnvVar: "ENFORCE_SEMVER2",
},
},
"listen.host": {
Type: stringType,
Default: "0.0.0.0",
CLIFlag: cli.StringFlag{
Name: "listen-host",
Usage: "specifies the host to listen on",
EnvVar: "LISTEN_HOST",
},
},
}

func populateCLIFlags() {
Expand Down