Skip to content

Commit

Permalink
Merge branch 'main' into main
Browse files Browse the repository at this point in the history
Signed-off-by: Zack Brady <[email protected]>
  • Loading branch information
zackbradys authored Jan 9, 2025
2 parents 55b6451 + e97adcd commit 01e62e6
Show file tree
Hide file tree
Showing 16 changed files with 66 additions and 59 deletions.
1 change: 1 addition & 0 deletions cmd/hauler/cli/completion.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import (
"os"

"github.com/spf13/cobra"

"hauler.dev/go/hauler/internal/flags"
)

Expand Down
2 changes: 1 addition & 1 deletion cmd/hauler/cli/store.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
},
}

Expand Down
2 changes: 2 additions & 0 deletions cmd/hauler/cli/store/add.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@ import (
"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"

Check failure on line 18 in cmd/hauler/cli/store/add.go

View workflow job for this annotation

GitHub Actions / Unit Tests

getter redeclared in this block

Check failure on line 18 in cmd/hauler/cli/store/add.go

View workflow job for this annotation

GitHub Actions / Unit Tests

"hauler.dev/go/hauler/pkg/artifacts/file/getter" imported and not used
"hauler.dev/go/hauler/pkg/consts"

Check failure on line 19 in cmd/hauler/cli/store/add.go

View workflow job for this annotation

GitHub Actions / Unit Tests

consts redeclared in this block

Check failure on line 19 in cmd/hauler/cli/store/add.go

View workflow job for this annotation

GitHub Actions / Unit Tests

"hauler.dev/go/hauler/pkg/consts" imported and not used
"hauler.dev/go/hauler/pkg/content/chart"
"hauler.dev/go/hauler/pkg/cosign"
"hauler.dev/go/hauler/pkg/log"
Expand Down
4 changes: 2 additions & 2 deletions cmd/hauler/cli/store/copy.go
Original file line number Diff line number Diff line change
Expand Up @@ -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()

Expand All @@ -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,
Expand Down
2 changes: 1 addition & 1 deletion cmd/hauler/cli/store/load.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
4 changes: 2 additions & 2 deletions cmd/hauler/cli/store/save.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -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)
}
}
}
Expand Down
46 changes: 44 additions & 2 deletions cmd/hauler/cli/store/serve.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,22 +2,54 @@ package store

import (
"context"
"fmt"
"net/http"
"os"
"strings"

"github.com/distribution/distribution/v3/configuration"
dcontext "github.com/distribution/distribution/v3/context"
_ "github.com/distribution/distribution/v3/registry/storage/driver/base"
_ "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"
"hauler.dev/go/hauler/pkg/log"
"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)

Expand All @@ -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 {
Expand All @@ -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
Expand Down
6 changes: 3 additions & 3 deletions cmd/hauler/cli/store/sync.go
Original file line number Diff line number Diff line change
Expand Up @@ -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], "+", "-")

Expand All @@ -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,
}
Expand All @@ -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
Expand Down
4 changes: 2 additions & 2 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down
32 changes: 0 additions & 32 deletions internal/flags/serve.go
Original file line number Diff line number Diff line change
@@ -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"
)
Expand Down Expand Up @@ -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

Expand Down
2 changes: 1 addition & 1 deletion internal/flags/store.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
11 changes: 1 addition & 10 deletions internal/server/registry.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
)
Expand All @@ -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
}

Expand All @@ -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"
Expand Down
3 changes: 2 additions & 1 deletion pkg/apis/hauler.cattle.io/v1alpha1/groupversion_info.go
Original file line number Diff line number Diff line change
@@ -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 (
Expand Down
4 changes: 2 additions & 2 deletions pkg/cosign/cosign.go
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -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
Expand Down
1 change: 1 addition & 0 deletions pkg/log/log.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import (

"github.com/rs/zerolog"
"github.com/rs/zerolog/log"

"hauler.dev/go/hauler/pkg/consts"
)

Expand Down
1 change: 1 addition & 0 deletions pkg/reference/reference.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import (
"strings"

gname "github.com/google/go-containerregistry/pkg/name"

"hauler.dev/go/hauler/pkg/consts"
)

Expand Down

0 comments on commit 01e62e6

Please sign in to comment.