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 all commits
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
1 change: 1 addition & 0 deletions cmd/chartmuseum/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,7 @@ func cliHandler(c *cli.Context) {
WriteTimeout: conf.GetInt("writetimeout"),
ReadTimeout: conf.GetInt("readtimeout"),
EnforceSemver2: conf.GetBool("enforce-semver2"),
Host: conf.GetString("listen.host"),
}

server, err := newServer(options)
Expand Down
7 changes: 5 additions & 2 deletions pkg/chartmuseum/router/router.go
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ type (
CORSAllowOrigin string
ReadTimeout time.Duration
WriteTimeout time.Duration
Host string
}

// RouterOptions are options for constructing a Router
Expand All @@ -75,6 +76,7 @@ type (
ReadTimeout int
WriteTimeout int
CORSAllowOrigin string
Host string
}

// Route represents an application route
Expand Down Expand Up @@ -113,6 +115,7 @@ func NewRouter(options RouterOptions) *Router {
CORSAllowOrigin: options.CORSAllowOrigin,
ReadTimeout: time.Duration(options.ReadTimeout) * time.Second,
WriteTimeout: time.Duration(options.WriteTimeout) * time.Second,
Host: options.Host,
}

var err error
Expand Down Expand Up @@ -165,11 +168,11 @@ func NewRouter(options RouterOptions) *Router {

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

server := http.Server{
Addr: fmt.Sprintf(":%d", port),
Addr: fmt.Sprintf("%s:%d", router.Host, port),
Handler: router,
ReadTimeout: router.ReadTimeout,
WriteTimeout: router.WriteTimeout,
Expand Down
2 changes: 2 additions & 0 deletions pkg/chartmuseum/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,7 @@ type (
// EnforceSemver2 represents if the museum server always accept the Chart with [valid semantic version 2](https://semver.org/)
// More refers to : https://github.com/helm/chartmuseum/issues/320
EnforceSemver2 bool
Host string
}

// Server is a generic interface for web servers
Expand Down Expand Up @@ -114,6 +115,7 @@ func NewServer(options ServerOptions) (Server, error) {
CORSAllowOrigin: options.CORSAllowOrigin,
ReadTimeout: options.ReadTimeout,
WriteTimeout: options.WriteTimeout,
Host: options.Host,
})

server, err := mt.NewMultiTenantServer(mt.MultiTenantServerOptions{
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