Skip to content

Commit

Permalink
Allow to bind chartmuseum to a specific interface
Browse files Browse the repository at this point in the history
The new config option "listen.host" ("--listen-host", "LISTEN_HOST") may
be used to bind  chartmuseum to a specific interface rather than 0.0.0.0.

Default is 0.0.0.0 to stick with current behaviour.

Fixes #255
  • Loading branch information
jayme-github committed Jun 23, 2020
1 parent 18656d8 commit 74997b3
Show file tree
Hide file tree
Showing 5 changed files with 16 additions and 7 deletions.
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

0 comments on commit 74997b3

Please sign in to comment.