diff --git a/cmd/hauler/cli/completion.go b/cmd/hauler/cli/completion.go index 4caeaa70..97cf0251 100644 --- a/cmd/hauler/cli/completion.go +++ b/cmd/hauler/cli/completion.go @@ -5,6 +5,7 @@ import ( "os" "github.com/spf13/cobra" + "hauler.dev/go/hauler/internal/flags" ) diff --git a/cmd/hauler/cli/store.go b/cmd/hauler/cli/store.go index 872769c4..754439ef 100644 --- a/cmd/hauler/cli/store.go +++ b/cmd/hauler/cli/store.go @@ -138,7 +138,7 @@ func addStoreServeRegistry(rso *flags.StoreRootOpts, ro *flags.CliRootOpts) *cob return err } - return store.ServeRegistryCmd(ctx, o, s, ro) + return store.ServeRegistryCmd(ctx, o, s, rso, ro) }, } diff --git a/cmd/hauler/cli/store/add.go b/cmd/hauler/cli/store/add.go index 1d6aed25..b4a22d6d 100644 --- a/cmd/hauler/cli/store/add.go +++ b/cmd/hauler/cli/store/add.go @@ -5,13 +5,13 @@ import ( "os" "github.com/google/go-containerregistry/pkg/name" - "hauler.dev/go/hauler/pkg/artifacts/file/getter" - "hauler.dev/go/hauler/pkg/consts" "helm.sh/helm/v3/pkg/action" "hauler.dev/go/hauler/internal/flags" "hauler.dev/go/hauler/pkg/apis/hauler.cattle.io/v1alpha1" "hauler.dev/go/hauler/pkg/artifacts/file" + "hauler.dev/go/hauler/pkg/artifacts/file/getter" + "hauler.dev/go/hauler/pkg/consts" "hauler.dev/go/hauler/pkg/content/chart" "hauler.dev/go/hauler/pkg/cosign" "hauler.dev/go/hauler/pkg/log" diff --git a/cmd/hauler/cli/store/copy.go b/cmd/hauler/cli/store/copy.go index 29af234b..5a25dc10 100644 --- a/cmd/hauler/cli/store/copy.go +++ b/cmd/hauler/cli/store/copy.go @@ -19,7 +19,7 @@ func CopyCmd(ctx context.Context, o *flags.CopyOpts, s *store.Layout, targetRef components := strings.SplitN(targetRef, "://", 2) switch components[0] { case "dir": - l.Debugf("identified directory target reference") + l.Debugf("identified directory target reference of [%s]", components[1]) fs := content.NewFile(components[1]) defer fs.Close() @@ -29,7 +29,7 @@ func CopyCmd(ctx context.Context, o *flags.CopyOpts, s *store.Layout, targetRef } case "registry": - l.Debugf("identified registry target reference") + l.Debugf("identified registry target reference of [%s]", components[1]) ropts := content.RegistryOptions{ Username: o.Username, Password: o.Password, diff --git a/cmd/hauler/cli/store/load.go b/cmd/hauler/cli/store/load.go index 8cace695..427fe1ef 100644 --- a/cmd/hauler/cli/store/load.go +++ b/cmd/hauler/cli/store/load.go @@ -53,7 +53,7 @@ func unarchiveLayoutTo(ctx context.Context, archivePath string, dest string, tem } defer os.RemoveAll(tempDir) - l.Debugf("using temporary directory at %s", tempDir) + l.Debugf("using temporary directory at [%s]", tempDir) if err := archiver.Unarchive(archivePath, tempDir); err != nil { return err diff --git a/cmd/hauler/cli/store/save.go b/cmd/hauler/cli/store/save.go index 886d74fa..8e2bf65a 100644 --- a/cmd/hauler/cli/store/save.go +++ b/cmd/hauler/cli/store/save.go @@ -106,7 +106,7 @@ func writeExportsManifest(ctx context.Context, dir string, platformStr string) e for _, desc := range imx.Manifests { l.Debugf("descriptor [%s] >>> %s", desc.Digest.String(), desc.MediaType) if artifactType := types.MediaType(desc.ArtifactType); artifactType != "" && !artifactType.IsImage() && !artifactType.IsIndex() { - l.Debugf("descriptor [%s] <<< SKIPPING ARTIFACT (%q)", desc.Digest.String(), desc.ArtifactType) + l.Debugf("descriptor [%s] <<< SKIPPING ARTIFACT [%q]", desc.Digest.String(), desc.ArtifactType) continue } if desc.Annotations != nil { @@ -157,7 +157,7 @@ func writeExportsManifest(ctx context.Context, dir string, platformStr string) e } } default: - l.Debugf("descriptor [%s] <<< SKIPPING KIND (%q)", desc.Digest.String(), kind) + l.Debugf("descriptor [%s] <<< SKIPPING KIND [%q]", desc.Digest.String(), kind) } } } diff --git a/cmd/hauler/cli/store/serve.go b/cmd/hauler/cli/store/serve.go index 1ba3a7a3..4cecd80c 100644 --- a/cmd/hauler/cli/store/serve.go +++ b/cmd/hauler/cli/store/serve.go @@ -2,7 +2,10 @@ package store import ( "context" + "fmt" + "net/http" "os" + "strings" "github.com/distribution/distribution/v3/configuration" dcontext "github.com/distribution/distribution/v3/context" @@ -10,6 +13,7 @@ import ( _ "github.com/distribution/distribution/v3/registry/storage/driver/filesystem" _ "github.com/distribution/distribution/v3/registry/storage/driver/inmemory" "github.com/distribution/distribution/v3/version" + "gopkg.in/yaml.v3" "hauler.dev/go/hauler/internal/flags" "hauler.dev/go/hauler/internal/server" @@ -17,7 +21,35 @@ import ( "hauler.dev/go/hauler/pkg/store" ) -func ServeRegistryCmd(ctx context.Context, o *flags.ServeRegistryOpts, s *store.Layout, ro *flags.CliRootOpts) error { +func DefaultRegistryConfig(o *flags.ServeRegistryOpts, rso *flags.StoreRootOpts, ro *flags.CliRootOpts) *configuration.Configuration { + cfg := &configuration.Configuration{ + Version: "0.1", + Storage: configuration.Storage{ + "cache": configuration.Parameters{"blobdescriptor": "inmemory"}, + "filesystem": configuration.Parameters{"rootdirectory": o.RootDir}, + "maintenance": configuration.Parameters{ + "readonly": map[any]any{"enabled": o.ReadOnly}, + }, + }, + } + + if o.TLSCert != "" && o.TLSKey != "" { + cfg.HTTP.TLS.Certificate = o.TLSCert + cfg.HTTP.TLS.Key = o.TLSKey + } + + cfg.HTTP.Addr = fmt.Sprintf(":%d", o.Port) + cfg.HTTP.Headers = http.Header{ + "X-Content-Type-Options": []string{"nosniff"}, + } + + cfg.Log.Level = configuration.Loglevel(ro.LogLevel) + cfg.Validation.Manifests.URLs.Allow = []string{".+"} + + return cfg +} + +func ServeRegistryCmd(ctx context.Context, o *flags.ServeRegistryOpts, s *store.Layout, rso *flags.StoreRootOpts, ro *flags.CliRootOpts) error { l := log.FromContext(ctx) ctx = dcontext.WithVersion(ctx, version.Version) @@ -33,7 +65,7 @@ func ServeRegistryCmd(ctx context.Context, o *flags.ServeRegistryOpts, s *store. tr.Close() - cfg := o.DefaultRegistryConfig() + cfg := DefaultRegistryConfig(o, rso, ro) if o.ConfigFile != "" { ucfg, err := loadConfig(o.ConfigFile) if err != nil { @@ -43,6 +75,16 @@ func ServeRegistryCmd(ctx context.Context, o *flags.ServeRegistryOpts, s *store. } l.Infof("starting registry on port [%d]", o.Port) + + yamlConfig, err := yaml.Marshal(cfg) + if err != nil { + l.Errorf("failed to validate/output registry configuration: %v", err) + } else { + l.Infof("using registry configuration... \n%s", strings.TrimSpace(string(yamlConfig))) + } + + l.Debugf("detailed registry configuration: %+v", cfg) + r, err := server.NewRegistry(ctx, cfg) if err != nil { return err diff --git a/cmd/hauler/cli/store/sync.go b/cmd/hauler/cli/store/sync.go index 2505161a..a4e913c9 100644 --- a/cmd/hauler/cli/store/sync.go +++ b/cmd/hauler/cli/store/sync.go @@ -29,7 +29,7 @@ func SyncCmd(ctx context.Context, o *flags.SyncOpts, s *store.Layout, rso *flags // if passed products, check for a remote manifest to retrieve and use. for _, product := range o.Products { - l.Infof("processing content file for product: '%s'", product) + l.Infof("processing content file for product [%s]", product) parts := strings.Split(product, "=") tag := strings.ReplaceAll(parts[1], "+", "-") @@ -40,7 +40,7 @@ func SyncCmd(ctx context.Context, o *flags.SyncOpts, s *store.Layout, rso *flags } manifestLoc := fmt.Sprintf("%s/hauler/%s-manifest.yaml:%s", ProductRegistry, parts[0], tag) - l.Infof("retrieving product manifest from: '%s'", manifestLoc) + l.Infof("retrieving product manifest from [%s]", manifestLoc) img := v1alpha1.Image{ Name: manifestLoc, } @@ -66,7 +66,7 @@ func SyncCmd(ctx context.Context, o *flags.SyncOpts, s *store.Layout, rso *flags // if passed a local manifest, process it for _, filename := range o.ContentFiles { - l.Debugf("processing content file: '%s'", filename) + l.Debugf("processing content file: [%s]", filename) fi, err := os.Open(filename) if err != nil { return err diff --git a/go.mod b/go.mod index d6479aa9..730df539 100644 --- a/go.mod +++ b/go.mod @@ -8,7 +8,6 @@ require ( github.com/common-nighthawk/go-figure v0.0.0-20210622060536-734e95fb86be github.com/containerd/containerd v1.7.23 github.com/distribution/distribution/v3 v3.0.0-20221208165359-362910506bc2 - github.com/docker/go-metrics v0.0.1 github.com/google/go-containerregistry v0.16.1 github.com/gorilla/handlers v1.5.1 github.com/gorilla/mux v1.8.0 @@ -23,6 +22,7 @@ require ( github.com/spf13/afero v1.10.0 github.com/spf13/cobra v1.8.1 golang.org/x/sync v0.10.0 + gopkg.in/yaml.v3 v3.0.1 helm.sh/helm/v3 v3.16.3 k8s.io/apimachinery v0.31.3 k8s.io/client-go v0.31.3 @@ -63,6 +63,7 @@ require ( github.com/docker/docker-credential-helpers v0.7.0 // indirect github.com/docker/go-connections v0.5.0 // indirect github.com/docker/go-events v0.0.0-20190806004212-e31b211e4f1c // indirect + github.com/docker/go-metrics v0.0.1 // indirect github.com/docker/libtrust v0.0.0-20150114040149-fa567046d9b1 // indirect github.com/dsnet/compress v0.0.2-0.20210315054119-f66993602bf5 // indirect github.com/emicklei/go-restful/v3 v3.11.0 // indirect @@ -162,7 +163,6 @@ require ( gopkg.in/evanphx/json-patch.v4 v4.12.0 // indirect gopkg.in/inf.v0 v0.9.1 // indirect gopkg.in/yaml.v2 v2.4.0 // indirect - gopkg.in/yaml.v3 v3.0.1 // indirect k8s.io/api v0.31.3 // indirect k8s.io/apiextensions-apiserver v0.31.3 // indirect k8s.io/apiserver v0.31.3 // indirect diff --git a/internal/flags/serve.go b/internal/flags/serve.go index 6ee24c3d..47fa2d35 100644 --- a/internal/flags/serve.go +++ b/internal/flags/serve.go @@ -1,10 +1,6 @@ package flags import ( - "fmt" - "net/http" - - "github.com/distribution/distribution/v3/configuration" "github.com/spf13/cobra" "hauler.dev/go/hauler/pkg/consts" ) @@ -35,34 +31,6 @@ func (o *ServeRegistryOpts) AddFlags(cmd *cobra.Command) { cmd.MarkFlagsRequiredTogether("tls-cert", "tls-key") } -func (o *ServeRegistryOpts) DefaultRegistryConfig() *configuration.Configuration { - cfg := &configuration.Configuration{ - Version: "0.1", - Storage: configuration.Storage{ - "cache": configuration.Parameters{"blobdescriptor": "inmemory"}, - "filesystem": configuration.Parameters{"rootdirectory": o.RootDir}, - "maintenance": configuration.Parameters{ - "readonly": map[any]any{"enabled": o.ReadOnly}, - }, - }, - } - - if o.TLSCert != "" && o.TLSKey != "" { - cfg.HTTP.TLS.Certificate = o.TLSCert - cfg.HTTP.TLS.Key = o.TLSKey - } - - cfg.HTTP.Addr = fmt.Sprintf(":%d", o.Port) - cfg.HTTP.Headers = http.Header{ - "X-Content-Type-Options": []string{"nosniff"}, - } - - cfg.Log.Level = "info" - cfg.Validation.Manifests.URLs.Allow = []string{".+"} - - return cfg -} - type ServeFilesOpts struct { *StoreRootOpts diff --git a/internal/flags/store.go b/internal/flags/store.go index 202b255c..c2dd6cec 100644 --- a/internal/flags/store.go +++ b/internal/flags/store.go @@ -41,7 +41,7 @@ func (o *StoreRootOpts) Store(ctx context.Context) (*store.Layout, error) { return nil, err } - l.Debugf("using store at %s", abs) + l.Debugf("using store at [%s]", abs) if _, err := os.Stat(abs); errors.Is(err, os.ErrNotExist) { if err := os.MkdirAll(abs, os.ModePerm); err != nil { diff --git a/internal/server/registry.go b/internal/server/registry.go index 9f27b6d3..8856fd8a 100644 --- a/internal/server/registry.go +++ b/internal/server/registry.go @@ -11,7 +11,6 @@ import ( "github.com/distribution/distribution/v3/configuration" "github.com/distribution/distribution/v3/registry" "github.com/distribution/distribution/v3/registry/handlers" - "github.com/docker/go-metrics" "github.com/pkg/errors" "github.com/sirupsen/logrus" ) @@ -22,14 +21,6 @@ func NewRegistry(ctx context.Context, cfg *configuration.Configuration) (*regist return nil, err } - if cfg.HTTP.Debug.Prometheus.Enabled { - path := cfg.HTTP.Debug.Prometheus.Path - if path == "" { - path = "/metrics" - } - http.Handle(path, metrics.Handler()) - } - return r, nil } @@ -45,7 +36,7 @@ func NewTempRegistry(ctx context.Context, root string) *tmpRegistryServer { "filesystem": configuration.Parameters{"rootdirectory": root}, }, } - // Add validation configuration + cfg.Validation.Manifests.URLs.Allow = []string{".+"} cfg.Log.Level = "error" diff --git a/pkg/apis/hauler.cattle.io/v1alpha1/groupversion_info.go b/pkg/apis/hauler.cattle.io/v1alpha1/groupversion_info.go index 29e66d46..5190d448 100644 --- a/pkg/apis/hauler.cattle.io/v1alpha1/groupversion_info.go +++ b/pkg/apis/hauler.cattle.io/v1alpha1/groupversion_info.go @@ -1,8 +1,9 @@ package v1alpha1 import ( - "hauler.dev/go/hauler/pkg/consts" "k8s.io/apimachinery/pkg/runtime/schema" + + "hauler.dev/go/hauler/pkg/consts" ) var ( diff --git a/pkg/cosign/cosign.go b/pkg/cosign/cosign.go index 4156b8b1..a2a24a5d 100644 --- a/pkg/cosign/cosign.go +++ b/pkg/cosign/cosign.go @@ -64,7 +64,7 @@ func SaveImage(ctx context.Context, s *store.Layout, ref string, platform string if err != nil { return err } - l.Debugf("multi-arch image: %v", isMultiArch) + l.Debugf("multi-arch image [%v]", isMultiArch) cmd := exec.Command(cosignBinaryPath, "save", ref, "--dir", s.Root) // Conditionally add platform. @@ -248,7 +248,7 @@ func EnsureBinaryExists(ctx context.Context, bin embed.FS, ro *flags.CliRootOpts return fmt.Errorf("error: %v", err) } - l.Debugf("using hauler directory at %s", filepath.Dir(binaryPath)) + l.Debugf("using hauler directory at [%s]", filepath.Dir(binaryPath)) // Determine the architecture so that we pull the correct embedded binary arch := runtime.GOARCH diff --git a/pkg/log/log.go b/pkg/log/log.go index 3f5371d6..89e50131 100644 --- a/pkg/log/log.go +++ b/pkg/log/log.go @@ -7,6 +7,7 @@ import ( "github.com/rs/zerolog" "github.com/rs/zerolog/log" + "hauler.dev/go/hauler/pkg/consts" ) diff --git a/pkg/reference/reference.go b/pkg/reference/reference.go index 611f93e2..23735d28 100644 --- a/pkg/reference/reference.go +++ b/pkg/reference/reference.go @@ -8,6 +8,7 @@ import ( "strings" gname "github.com/google/go-containerregistry/pkg/name" + "hauler.dev/go/hauler/pkg/consts" )