Skip to content
Closed
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
4 changes: 4 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -628,6 +628,10 @@ The `--gen-index` CLI option (described above) can be used to generate and print

Upon index regeneration, *ChartMuseum* will, however, save a statefile in storage called `index-cache.yaml` used for cache optimization. This file is only meant for internal use, but may be able to be used for migration to simple storage.

## Limitations

* ChartMuseum will not rebuild index instantly if `dynamic-depth` flag is opened and **manually(not via API)** update or remove the chart from storage.

## Mirroring the official Kubernetes repositories
Please see `scripts/mirror-k8s-repos.sh` for an example of how to download all .tgz packages from the official Kubernetes repositories (both stable and incubator).

Expand Down
152 changes: 87 additions & 65 deletions cmd/chartmuseum/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,11 +21,13 @@ import (
"log"
"os"
"strings"
"sync"

"github.com/chartmuseum/storage"
"helm.sh/chartmuseum/pkg/cache"
"helm.sh/chartmuseum/pkg/chartmuseum"
cm_logger "helm.sh/chartmuseum/pkg/chartmuseum/logger"
"helm.sh/chartmuseum/pkg/chartmuseum/server/multitenant"
"helm.sh/chartmuseum/pkg/config"

"github.com/urfave/cli"
Expand All @@ -41,6 +43,9 @@ var (

// Revision is the git commit id (added at compile time)
Revision string

serverOnce sync.Once
server chartmuseum.Server
)

func main() {
Expand All @@ -53,76 +58,83 @@ func main() {
app.Run(os.Args)
}

func getServer() chartmuseum.Server {
return server
}

func cliHandler(c *cli.Context) {
conf := config.NewConfig()
err := conf.UpdateFromCLIContext(c)
if err != nil {
crash(err)
}
serverOnce.Do(func() {
conf := config.NewConfig()
err := conf.UpdateFromCLIContext(c)
if err != nil {
crash(err)
}

logger, err := cm_logger.NewLogger(cm_logger.LoggerOptions{
Debug: conf.GetBool("debug"),
LogJSON: conf.GetBool("logjson"),
})
if err != nil {
crash(err)
}
logger, err := cm_logger.NewLogger(cm_logger.LoggerOptions{
Debug: conf.GetBool("debug"),
LogJSON: conf.GetBool("logjson"),
})
if err != nil {
crash(err)
}

conf.ShowDeprecationWarnings(c, logger)

backend := backendFromConfig(conf)
store := storeFromConfig(conf)

options := chartmuseum.ServerOptions{
Version: Version,
StorageBackend: backend,
ExternalCacheStore: store,
Logger: logger,
TimestampTolerance: conf.GetDuration("storage.timestamptolerance"),
ChartURL: conf.GetString("charturl"),
TlsCert: conf.GetString("tls.cert"),
TlsKey: conf.GetString("tls.key"),
TlsCACert: conf.GetString("tls.cacert"),
Username: conf.GetString("basicauth.user"),
Password: conf.GetString("basicauth.pass"),
ChartPostFormFieldName: conf.GetString("chartpostformfieldname"),
ProvPostFormFieldName: conf.GetString("provpostformfieldname"),
ContextPath: conf.GetString("contextpath"),
LogHealth: conf.GetBool("loghealth"),
LogLatencyInteger: conf.GetBool("loglatencyinteger"),
EnableAPI: !conf.GetBool("disableapi"),
DisableDelete: conf.GetBool("disabledelete"),
UseStatefiles: !conf.GetBool("disablestatefiles"),
AllowOverwrite: conf.GetBool("allowoverwrite"),
AllowForceOverwrite: !conf.GetBool("disableforceoverwrite"),
EnableMetrics: conf.GetBool("enablemetrics"),
AnonymousGet: conf.GetBool("authanonymousget"),
GenIndex: conf.GetBool("genindex"),
MaxStorageObjects: conf.GetInt("maxstorageobjects"),
IndexLimit: conf.GetInt("indexlimit"),
Depth: conf.GetInt("depth"),
MaxUploadSize: conf.GetInt("maxuploadsize"),
BearerAuth: conf.GetBool("bearerauth"),
AuthRealm: conf.GetString("authrealm"),
AuthService: conf.GetString("authservice"),
AuthCertPath: conf.GetString("authcertpath"),
AuthActionsSearchPath: conf.GetString("authactionssearchpath"),
DepthDynamic: conf.GetBool("depthdynamic"),
CORSAllowOrigin: conf.GetString("cors.alloworigin"),
WriteTimeout: conf.GetInt("writetimeout"),
ReadTimeout: conf.GetInt("readtimeout"),
EnforceSemver2: conf.GetBool("enforce-semver2"),
CacheInterval: conf.GetDuration("cacheinterval"),
Host: conf.GetString("listen.host"),
PerChartLimit: conf.GetInt("per-chart-limit"),
}
conf.ShowDeprecationWarnings(c, logger)

backend := backendFromConfig(conf)
store := storeFromConfig(conf)

options := chartmuseum.ServerOptions{
Version: Version,
StorageBackend: backend,
ExternalCacheStore: store,
Logger: logger,
TimestampTolerance: conf.GetDuration("storage.timestamptolerance"),
ChartURL: conf.GetString("charturl"),
TlsCert: conf.GetString("tls.cert"),
TlsKey: conf.GetString("tls.key"),
TlsCACert: conf.GetString("tls.cacert"),
Username: conf.GetString("basicauth.user"),
Password: conf.GetString("basicauth.pass"),
ChartPostFormFieldName: conf.GetString("chartpostformfieldname"),
ProvPostFormFieldName: conf.GetString("provpostformfieldname"),
ContextPath: conf.GetString("contextpath"),
LogHealth: conf.GetBool("loghealth"),
LogLatencyInteger: conf.GetBool("loglatencyinteger"),
EnableAPI: !conf.GetBool("disableapi"),
DisableDelete: conf.GetBool("disabledelete"),
UseStatefiles: !conf.GetBool("disablestatefiles"),
AllowOverwrite: conf.GetBool("allowoverwrite"),
AllowForceOverwrite: !conf.GetBool("disableforceoverwrite"),
EnableMetrics: conf.GetBool("enablemetrics"),
AnonymousGet: conf.GetBool("authanonymousget"),
GenIndex: conf.GetBool("genindex"),
MaxStorageObjects: conf.GetInt("maxstorageobjects"),
IndexLimit: conf.GetInt("indexlimit"),
Depth: conf.GetInt("depth"),
MaxUploadSize: conf.GetInt("maxuploadsize"),
BearerAuth: conf.GetBool("bearerauth"),
AuthRealm: conf.GetString("authrealm"),
AuthService: conf.GetString("authservice"),
AuthCertPath: conf.GetString("authcertpath"),
AuthActionsSearchPath: conf.GetString("authactionssearchpath"),
DepthDynamic: conf.GetBool("depthdynamic"),
CORSAllowOrigin: conf.GetString("cors.alloworigin"),
WriteTimeout: conf.GetInt("writetimeout"),
ReadTimeout: conf.GetInt("readtimeout"),
EnforceSemver2: conf.GetBool("enforce-semver2"),
CacheInterval: conf.GetDuration("cacheinterval"),
Host: conf.GetString("listen.host"),
PerChartLimit: conf.GetInt("per-chart-limit"),
}

server, err := newServer(options)
if err != nil {
crash(err)
}
server, err = newServer(options)
if err != nil {
crash(err)
}

server.Listen(conf.GetInt("port"))

server.Listen(conf.GetInt("port"))
})
}

func backendFromConfig(conf *config.Config) storage.Backend {
Expand Down Expand Up @@ -165,6 +177,16 @@ func localBackendFromConfig(conf *config.Config) storage.Backend {
crashIfConfigMissingVars(conf, []string{"storage.local.rootdir"})
return storage.NewLocalFilesystemBackend(
conf.GetString("storage.local.rootdir"),
storage.WithEventNotifier(storage.EventPutObject, func() {
if _, ok := getServer().(*multitenant.MultiTenantServer); ok {
getServer().(*multitenant.MultiTenantServer).RebuildIndex()
}
}),
storage.WithEventNotifier(storage.EventDeleteObject, func() {
if _, ok := getServer().(*multitenant.MultiTenantServer); ok {
getServer().(*multitenant.MultiTenantServer).RebuildIndex()
}
}),
)
}

Expand Down
26 changes: 14 additions & 12 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,9 @@ require (

require (
cloud.google.com/go v0.100.2 // indirect
cloud.google.com/go/compute v0.1.0 // indirect
cloud.google.com/go/compute v1.5.0 // indirect
cloud.google.com/go/iam v0.1.1 // indirect
cloud.google.com/go/storage v1.19.0 // indirect
cloud.google.com/go/storage v1.21.0 // indirect
github.com/Azure/azure-sdk-for-go v61.4.0+incompatible // indirect
github.com/Azure/go-ansiterm v0.0.0-20210617225240-d185dfc1b5a1 // indirect
github.com/Azure/go-autorest v14.2.0+incompatible // indirect
Expand All @@ -40,7 +40,7 @@ require (
github.com/PuerkitoBio/urlesc v0.0.0-20170810143723-de5bf2ad4578 // indirect
github.com/alicebob/gopher-json v0.0.0-20200520072559-a9ecdc9d1d3a // indirect
github.com/aliyun/aliyun-oss-go-sdk v2.2.0+incompatible // indirect
github.com/aws/aws-sdk-go v1.42.44 // indirect
github.com/aws/aws-sdk-go v1.43.16 // indirect
github.com/baidubce/bce-sdk-go v0.9.105 // indirect
github.com/beorn7/perks v1.0.1 // indirect
github.com/cespare/xxhash/v2 v2.1.2 // indirect
Expand Down Expand Up @@ -130,26 +130,26 @@ require (
github.com/xlab/treeprint v0.0.0-20181112141820-a009c3971eca // indirect
github.com/yuin/gopher-lua v0.0.0-20210529063254-f4c35e4016d9 // indirect
go.etcd.io/etcd v3.3.27+incompatible // indirect
go.etcd.io/etcd/api/v3 v3.5.1 // indirect
go.etcd.io/etcd/client/pkg/v3 v3.5.1 // indirect
go.etcd.io/etcd/client/v3 v3.5.1 // indirect
go.etcd.io/etcd/api/v3 v3.5.2 // indirect
go.etcd.io/etcd/client/pkg/v3 v3.5.2 // indirect
go.etcd.io/etcd/client/v3 v3.5.2 // indirect
go.opencensus.io v0.23.0 // indirect
go.starlark.net v0.0.0-20200306205701-8dd3e2ee1dd5 // indirect
go.uber.org/atomic v1.7.0 // indirect
go.uber.org/multierr v1.6.0 // indirect
golang.org/x/crypto v0.0.0-20211215153901-e495a2d5b3d3 // indirect
golang.org/x/net v0.0.0-20220121210141-e204ce36a2ba // indirect
golang.org/x/oauth2 v0.0.0-20211104180415-d3ed0bb246c8 // indirect
golang.org/x/net v0.0.0-20220225172249-27dd8689420f // indirect
golang.org/x/oauth2 v0.0.0-20220223155221-ee480838109b // indirect
golang.org/x/sync v0.0.0-20210220032951-036812b2e83c // indirect
golang.org/x/sys v0.0.0-20220114195835-da31bd327af9 // indirect
golang.org/x/sys v0.0.0-20220227234510-4e6760a101f9 // indirect
golang.org/x/term v0.0.0-20210927222741-03fcf44c2211 // indirect
golang.org/x/text v0.3.7 // indirect
golang.org/x/time v0.0.0-20210723032227-1f47c861a9ac // indirect
golang.org/x/xerrors v0.0.0-20200804184101-5ec99f83aff1 // indirect
google.golang.org/api v0.66.0 // indirect
google.golang.org/api v0.71.0 // indirect
google.golang.org/appengine v1.6.7 // indirect
google.golang.org/genproto v0.0.0-20220118154757-00ab72f36ad5 // indirect
google.golang.org/grpc v1.43.0 // indirect
google.golang.org/genproto v0.0.0-20220304144024-325a89244dc8 // indirect
google.golang.org/grpc v1.44.0 // indirect
google.golang.org/protobuf v1.27.1 // indirect
gopkg.in/inf.v0 v0.9.1 // indirect
gopkg.in/ini.v1 v1.66.2 // indirect
Expand All @@ -169,3 +169,5 @@ require (
sigs.k8s.io/structured-merge-diff/v4 v4.2.1 // indirect
sigs.k8s.io/yaml v1.3.0 // indirect
)

replace github.com/chartmuseum/storage v0.12.3 => ../storage
Loading