Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: add registry cache support for Azure DevOps #1701

Merged
merged 4 commits into from
Apr 5, 2023
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
24 changes: 19 additions & 5 deletions internal/registry/registry_cache.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import (
"fmt"
"net/url"
"os"
"os/exec"
"path/filepath"
"runtime"
"time"
Expand Down Expand Up @@ -168,6 +169,7 @@ func (r *Cache) Initialize() error {

// CreateCache creates the cache on the filesystem
func (r *Cache) CreateCache() error {
var repository *git.Repository
r.logger.Debugf("Creating registry cache for %s/%s", r.url.Host, r.url.Path)

registryDir, err := os.MkdirTemp(filepath.Dir(r.Root), "registry")
Expand All @@ -177,11 +179,23 @@ func (r *Cache) CreateCache() error {

r.RegistryDir = registryDir

repository, err := git.PlainClone(r.RegistryDir, false, &git.CloneOptions{
URL: r.url.String(),
})
if err != nil {
return errors.Wrap(err, "cloning remote registry")
if r.url.Host == "dev.azure.com" {
err = exec.Command("git", "clone", r.url.String(), r.RegistryDir).Run()
if err != nil {
return errors.Wrap(err, "cloning remote registry with native git")
}

repository, err = git.PlainOpen(r.RegistryDir)
if err != nil {
return errors.Wrap(err, "opening remote registry clone")
}
} else {
repository, err = git.PlainClone(r.RegistryDir, false, &git.CloneOptions{
URL: r.url.String(),
})
if err != nil {
return errors.Wrap(err, "cloning remote registry")
}
}

w, err := repository.Worktree()
Expand Down
7 changes: 7 additions & 0 deletions internal/registry/registry_cache_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,13 @@ func testRegistryCache(t *testing.T, when spec.G, it spec.S) {
})
})

when("registryURL is Azure", func() {
it("fails to create a registry cache", func() {
_, err := NewRegistryCache(logger, tmpDir, "https://dev.azure.com/")
h.AssertNil(t, err)
})
})

it("creates a RegistryCache", func() {
registryCache, err := NewRegistryCache(logger, tmpDir, registryFixture)
h.AssertNil(t, err)
Expand Down