Skip to content
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
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ require (
github.com/lmittmann/tint v1.1.2
github.com/minio/minio-go/v7 v7.0.97
go.etcd.io/bbolt v1.4.3
golang.org/x/mod v0.31.0
)

require (
Expand All @@ -31,6 +30,7 @@ require (
github.com/stretchr/testify v1.11.1 // indirect
github.com/tinylib/msgp v1.3.0 // indirect
golang.org/x/crypto v0.44.0 // indirect
golang.org/x/mod v0.31.0 // indirect
golang.org/x/net v0.47.0 // indirect
golang.org/x/sys v0.38.0 // indirect
golang.org/x/text v0.32.0 // indirect
Expand Down
55 changes: 0 additions & 55 deletions internal/strategy/gomod/fetcher.go

This file was deleted.

79 changes: 13 additions & 66 deletions internal/strategy/gomod/gomod.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,15 +6,10 @@ import (
"log/slog"
"net/http"
"net/url"
"os"
"path/filepath"
"time"

"github.com/alecthomas/errors"
"github.com/goproxy/goproxy"

"github.com/block/cachew/internal/cache"
"github.com/block/cachew/internal/gitclone"
"github.com/block/cachew/internal/jobscheduler"
"github.com/block/cachew/internal/logging"
"github.com/block/cachew/internal/strategy"
Expand All @@ -25,21 +20,15 @@ func init() {
}

type Config struct {
Proxy string `hcl:"proxy,optional" help:"Upstream Go module proxy URL (defaults to proxy.golang.org)" default:"https://proxy.golang.org"`
PrivatePaths []string `hcl:"private-paths,optional" help:"Module path patterns for private repositories"`
MirrorRoot string `hcl:"mirror-root,optional" help:"Directory to store git clones for private repos." default:""`
FetchInterval time.Duration `hcl:"fetch-interval,optional" help:"How often to fetch from upstream for private repos." default:"15m"`
RefCheckInterval time.Duration `hcl:"ref-check-interval,optional" help:"How long to cache ref checks for private repos." default:"10s"`
CloneDepth int `hcl:"clone-depth,optional" help:"Depth for shallow clones of private repos. 0 means full clone." default:"0"`
Proxy string `hcl:"proxy,optional" help:"Upstream Go module proxy URL (defaults to proxy.golang.org)" default:"https://proxy.golang.org"`
}

type Strategy struct {
config Config
cache cache.Cache
logger *slog.Logger
proxy *url.URL
goproxy *goproxy.Goproxy
cloneManager *gitclone.Manager // Manager for cloning private repositories
config Config
cache cache.Cache
logger *slog.Logger
proxy *url.URL
goproxy *goproxy.Goproxy
}

var _ strategy.Strategy = (*Strategy)(nil)
Expand All @@ -57,56 +46,14 @@ func New(ctx context.Context, config Config, _ jobscheduler.Scheduler, cache cac
proxy: parsedURL,
}

publicFetcher := &goproxy.GoFetcher{
Env: []string{
"GOPROXY=" + config.Proxy,
"GOSUMDB=off", // Disable checksum database validation in fetcher, to prevent unneccessary double validation
},
}

var fetcher goproxy.Fetcher = publicFetcher

if len(config.PrivatePaths) > 0 {
// Set default mirror root if not specified
mirrorRoot := config.MirrorRoot
if mirrorRoot == "" {
homeDir, err := os.UserHomeDir()
if err != nil {
return nil, errors.Wrap(err, "get user home directory")
}
mirrorRoot = filepath.Join(homeDir, ".cache", "cachew", "gomod-git-mirrors")
}

// Create gitclone manager for private repositories
cloneManager, err := gitclone.NewManager(ctx, gitclone.Config{
RootDir: mirrorRoot,
FetchInterval: config.FetchInterval,
RefCheckInterval: config.RefCheckInterval,
CloneDepth: config.CloneDepth,
GitConfig: gitclone.DefaultGitTuningConfig(),
})
if err != nil {
return nil, errors.Wrap(err, "create clone manager for private repos")
}
s.cloneManager = cloneManager

// Discover existing clones
if err := cloneManager.DiscoverExisting(ctx); err != nil {
s.logger.WarnContext(ctx, "Failed to discover existing clones for private repos",
slog.String("error", err.Error()))
}

privateFetcher := newPrivateFetcher(s, cloneManager)
fetcher = newCompositeFetcher(publicFetcher, privateFetcher, config.PrivatePaths)

s.logger.InfoContext(ctx, "Configured private module support",
slog.Any("private_paths", config.PrivatePaths),
slog.String("mirror_root", mirrorRoot))
}

s.goproxy = &goproxy.Goproxy{
Logger: s.logger,
Fetcher: fetcher,
Logger: s.logger,
Fetcher: &goproxy.GoFetcher{
Env: []string{
"GOPROXY=" + config.Proxy,
"GOSUMDB=off", // Disable checksum database validation in fetcher, to prevent unneccessary double validation
},
},
Cacher: &goproxyCacher{
cache: cache,
},
Expand Down
32 changes: 0 additions & 32 deletions internal/strategy/gomod/matcher.go

This file was deleted.

123 changes: 0 additions & 123 deletions internal/strategy/gomod/matcher_test.go

This file was deleted.

Loading