Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
67 commits
Select commit Hold shift + click to select a range
c20168c
wip: Probably working right.
yhakbar Feb 21, 2025
a521804
fix: Cleaning things up a bit
yhakbar Feb 24, 2025
cb731e6
fix: Getting rid of unused constant
yhakbar Feb 24, 2025
1a54f04
fix: Fixing remote reference optimization
yhakbar Feb 24, 2025
6d70093
fix: More performance improvements
yhakbar Feb 24, 2025
0b592ea
fix: Performance testing done.
yhakbar Feb 24, 2025
52a9cd1
fix: Tossing some unnecessary comments
yhakbar Feb 24, 2025
4802efe
feat: Attempting implementation
yhakbar Feb 24, 2025
5629b2c
fix: Fixing recursive storage of trees
yhakbar Feb 24, 2025
9264dc3
feat: Upgrade to `go-getter` v2
yhakbar Feb 25, 2025
15d4fa3
feat: Use go-getter for cln protocol
yhakbar Feb 25, 2025
629f98b
fix: Removing debug logging
yhakbar Feb 25, 2025
926fc74
fix: Using an early return
yhakbar Feb 25, 2025
add47f5
fix: Some updates to how scaffolding gets done after catalog
yhakbar Feb 25, 2025
67ce742
fix: Updating experiment name
yhakbar Feb 25, 2025
1f4704f
fix: Rename `clngo` to `cln`
yhakbar Feb 25, 2025
95f3919
fix: Linting
yhakbar Feb 25, 2025
28aad5a
fix: Revert changes to `catalog` command
yhakbar Feb 25, 2025
7ab6f05
fix: Refactoring clone so that it's easier to work with
yhakbar Feb 25, 2025
477e496
fix: Switch to explicit sentinel instead of relying on `.git`
yhakbar Feb 26, 2025
4674e3f
fix: Renaming `repo` to `url`
yhakbar Feb 26, 2025
1549810
fix: Fixing tree linking
yhakbar Feb 26, 2025
0ee6b48
fix: Mostly fixed
yhakbar Feb 26, 2025
23192d4
fix: Tests fixed
yhakbar Feb 26, 2025
46bf743
fix: Fully repaired cln
yhakbar Feb 26, 2025
172901f
feat: Concurrently linking the tree
yhakbar Feb 26, 2025
06c4fe3
feat: Reducing concurrency for linking
yhakbar Feb 27, 2025
09950d8
feat: Persisting select `.git` files
yhakbar Feb 27, 2025
b2650f2
feat: Integrating `cln` into catalog
yhakbar Feb 27, 2025
996d9ad
feat: Renaming cln to CAS
yhakbar Feb 27, 2025
28e4e69
feat: Adjusting store path
yhakbar Feb 27, 2025
ac38312
feat: Paritioning content
yhakbar Feb 27, 2025
acebb90
fix: Refactoring a bit
yhakbar Feb 27, 2025
d69785f
fix: Lock access to the map
yhakbar Feb 27, 2025
557290b
fix: Improving integration into catalog
yhakbar Feb 27, 2025
2196a3a
fix: Linting
yhakbar Feb 27, 2025
18b7990
feat: Adding experiment docs
yhakbar Feb 27, 2025
5f2ab42
feat: Adding CAS feature docs
yhakbar Feb 27, 2025
8a66be5
fix: Filling in placeholder link
yhakbar Feb 27, 2025
d0f60f7
fix: Addressing CodeRabbit feedback
yhakbar Feb 27, 2025
27daacb
fix: Use parent logger
yhakbar Feb 27, 2025
21996f6
fix: Linting errors
yhakbar Feb 27, 2025
8f9b5ce
fix: Working on optimization
yhakbar Mar 4, 2025
b3b4d6f
fix: Tests working
yhakbar Mar 4, 2025
5e692a5
fix: Cleanup
yhakbar Mar 4, 2025
97d7859
fix: Adding tmp timestamp check
yhakbar Mar 4, 2025
60e7b2b
fix: Remove unused constants
yhakbar Mar 4, 2025
4c53664
feat: Adding `LinkTree` test
yhakbar Mar 4, 2025
9b1a4fc
fix: Update implementation to test table
yhakbar Mar 4, 2025
456c68c
fix: Linting
yhakbar Mar 4, 2025
53d2566
fix: Deleting some dead code
yhakbar Mar 4, 2025
12fe862
fix: Fixing Windows test of hard linked tree
yhakbar Mar 4, 2025
adf258f
fix: Fixing unnecessary imports
yhakbar Mar 4, 2025
cb71191
feat: Bumping Catalog to use go-getter v2
yhakbar Mar 4, 2025
58f3ea3
wip: Adding go-getter
yhakbar Mar 4, 2025
3844890
fix: Adjusting abstraction so that clone gets options
yhakbar Mar 4, 2025
baa76b0
fix: Refactoring
yhakbar Mar 4, 2025
1e0805d
fix: Adding getter
yhakbar Mar 4, 2025
ebe538c
fix: Use go-getter for clones
yhakbar Mar 4, 2025
87617ad
fix: Updating docs for updated CAS implementation
yhakbar Mar 4, 2025
edd85b1
fix: Linting
yhakbar Mar 5, 2025
428d562
fix: Getting rid of command cache
yhakbar Mar 5, 2025
46b8000
fix: Fixing comment
yhakbar Mar 5, 2025
c6efc57
fix: Addressing CodeRabbit feedback
yhakbar Mar 5, 2025
f50e994
fix: Removing unnecessary lock
yhakbar Mar 5, 2025
49291b1
feat: Plumbing ctx
yhakbar Mar 5, 2025
5086658
feat: Addressing review feedback
yhakbar Mar 10, 2025
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
Prev Previous commit
Next Next commit
fix: Improving integration into catalog
  • Loading branch information
yhakbar committed Mar 10, 2025
commit 557290be747a2293d28eac5688764d808aa1bf71
22 changes: 20 additions & 2 deletions cli/commands/catalog/action.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import (
"fmt"
"os"
"path/filepath"
"strings"

"github.com/gruntwork-io/terragrunt/cli/commands/catalog/module"
"github.com/gruntwork-io/terragrunt/cli/commands/catalog/tui"
Expand Down Expand Up @@ -41,9 +42,26 @@ func Run(ctx context.Context, opts *options.TerragruntOptions, repoURL string) e
allowCAS := opts.Experiments.Evaluate(experiment.CAS)

for _, repoURL := range repoURLs {
tempDir := filepath.Join(os.TempDir(), fmt.Sprintf(tempDirFormat, util.EncodeBase64Sha1(repoURL)))
path := util.EncodeBase64Sha1(repoURL)

// NOTE: We do this check again later, but it's just to make sure that we're leaving
// the separation of concerns for the directory destination and repo cloning.
if strings.HasPrefix(repoURL, "cas://") {
if !allowCAS {
return errors.Errorf("cas:// protocol is not allowed without using the `cas` experiment. Please enable the experiment and try again.")
}

homeDir, err := os.UserHomeDir()
if err != nil {
return err
}

path = filepath.Join(homeDir, ".cache", "terragrunt", "cas", "catalog", path)
} else {
path = filepath.Join(os.TempDir(), fmt.Sprintf(tempDirFormat, path))
}

repo, err := module.NewRepo(ctx, opts.Logger, repoURL, tempDir, walkWithSymlinks, allowCAS)
repo, err := module.NewRepo(ctx, opts.Logger, repoURL, path, walkWithSymlinks, allowCAS)
if err != nil {
return err
}
Expand Down
30 changes: 22 additions & 8 deletions cli/commands/catalog/module/repo.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ const (

var (
gitHeadBranchNameReg = regexp.MustCompile(`^.*?([^/]+)$`)
repoNameFromCloneURLReg = regexp.MustCompile(`(?i)^.*?([-a-z_.]+)[^/]*?(?:\.git)?$`)
repoNameFromCloneURLReg = regexp.MustCompile(`(?i)^.*?([-a-z0-9_.]+)[^/]*?(?:\.git)?$`)

modulesPaths = []string{"modules"}

Expand All @@ -54,7 +54,7 @@ type Repo struct {
useCAS bool
}

func NewRepo(ctx context.Context, logger log.Logger, cloneURL, tempDir string, walkWithSymlinks bool, allowCAS bool) (*Repo, error) {
func NewRepo(ctx context.Context, logger log.Logger, cloneURL, path string, walkWithSymlinks bool, allowCAS bool) (*Repo, error) {
useCAS := false

if strings.HasPrefix(cloneURL, "cas://") {
Expand All @@ -70,7 +70,7 @@ func NewRepo(ctx context.Context, logger log.Logger, cloneURL, tempDir string, w
repo := &Repo{
logger: logger,
cloneURL: cloneURL,
path: tempDir,
path: path,
walkWithSymlinks: walkWithSymlinks,
useCAS: useCAS,
}
Expand Down Expand Up @@ -212,7 +212,13 @@ func (repo *Repo) clone(ctx context.Context) error {
return err
}

return repo.performClone(&opts)
if repo.cloneCompleted() {
repo.logger.Debugf("The repo dir exists and %q exists. Skipping cloning.", cloneCompleteSentinel)

return nil
}

return repo.performClone(ctx, &opts)
}

func (repo *Repo) resolveCloneURL() (string, error) {
Expand All @@ -221,6 +227,7 @@ func (repo *Repo) resolveCloneURL() (string, error) {
if err != nil {
return "", errors.New(err)
}

return currentDir, nil
}

Expand All @@ -233,6 +240,7 @@ func (repo *Repo) handleLocalDir(repoPath string) error {
if err != nil {
return errors.New(err)
}

repo.logger.Debugf("Converting relative path %q to absolute %q", repoPath, absRepoPath)
repo.path = absRepoPath

Expand All @@ -255,6 +263,7 @@ func (repo *Repo) prepareCloneDirectory(opts *CloneOptions) error {
// Clean up incomplete clones
if repo.shouldCleanupIncompleteClone() {
repo.logger.Debugf("The repo dir exists but %q does not. Removing the repo dir for cloning from the remote source.", cloneCompleteSentinel)

if err := os.RemoveAll(repo.path); err != nil {
return errors.New(err)
}
Expand All @@ -273,10 +282,14 @@ func (repo *Repo) extractRepoName() string {
}

func (repo *Repo) shouldCleanupIncompleteClone() bool {
return files.FileExists(repo.path) && !files.FileExists(filepath.Join(repo.path, cloneCompleteSentinel))
return files.FileExists(repo.path) && !repo.cloneCompleted()
}

func (repo *Repo) cloneCompleted() bool {
return files.FileExists(filepath.Join(repo.path, cloneCompleteSentinel))
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
return files.FileExists(filepath.Join(repo.path, cloneCompleteSentinel))
return util.FileExists(filepath.Join(repo.path, cloneCompleteSentinel))

}

func (repo *Repo) performClone(opts *CloneOptions) error {
func (repo *Repo) performClone(ctx context.Context, opts *CloneOptions) error {
if repo.useCAS {
c, err := cas.New(opts.SourceURL, cas.Options{
Dir: repo.path,
Expand All @@ -286,7 +299,7 @@ func (repo *Repo) performClone(opts *CloneOptions) error {
return err
}

if err := c.Clone(); err != nil {
if err := c.Clone(ctx); err != nil {
return err
}

Expand Down Expand Up @@ -315,7 +328,8 @@ func (repo *Repo) performClone(opts *CloneOptions) error {
if err := getter.Get(
repo.path,
strings.Trim(sourceURL.String(), "/"),
getter.WithContext(opts.Context),
// TODO: Resolve this context issue
getter.WithContext(opts.Context), //nolint:contextcheck
getter.WithMode(getter.ClientModeDir),
); err != nil {
return err
Expand Down
5 changes: 3 additions & 2 deletions internal/cas/cas.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
package cas

import (
"context"
"crypto/sha1"
"encoding/hex"
"fmt"
Expand Down Expand Up @@ -73,7 +74,7 @@ func New(url string, opts Options) (*CAS, error) {
}

// Clone performs the clone operation
func (c *CAS) Clone() error {
func (c *CAS) Clone(ctx context.Context) error {
c.cloneLock.Lock()
defer c.cloneLock.Unlock()

Expand Down Expand Up @@ -118,7 +119,7 @@ func (c *CAS) Clone() error {
return err
}

if err := tree.LinkTree(c.store, targetDir); err != nil {
if err := tree.LinkTree(ctx, c.store, targetDir); err != nil {
return err
}

Expand Down
7 changes: 4 additions & 3 deletions internal/cas/tree.go
Original file line number Diff line number Diff line change
Expand Up @@ -92,8 +92,8 @@ func ParseTree(output, path string) (*Tree, error) {
}

// LinkTree writes the tree to a target directory
func (t *Tree) LinkTree(store *Store, targetDir string) error {
ctx, cancel := context.WithCancel(context.Background())
func (t *Tree) LinkTree(ctx context.Context, store *Store, targetDir string) error {
ctx, cancel := context.WithCancel(ctx)
defer cancel()

var (
Expand Down Expand Up @@ -165,7 +165,7 @@ func (t *Tree) LinkTree(store *Store, targetDir string) error {

subTargetDir := filepath.Join(targetDir, entry.Path)

if err := subTree.LinkTree(store, subTargetDir); err != nil {
if err := subTree.LinkTree(ctx, store, subTargetDir); err != nil {
errMu.Lock()
errs = append(errs, wrapError("link_subtree", subTargetDir, err))
errMu.Unlock()
Expand All @@ -179,6 +179,7 @@ func (t *Tree) LinkTree(store *Store, targetDir string) error {
wg.Wait()

if len(errs) > 0 {

return errors.Join(errs...)
}

Expand Down