Skip to content

Commit

Permalink
Merge pull request #1701 from nadworny/feature/fix_azure_devops
Browse files Browse the repository at this point in the history
feat: add registry cache support for Azure DevOps
  • Loading branch information
jkutner authored Apr 5, 2023
2 parents 8156fe6 + 444b040 commit 953ae77
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 5 deletions.
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

0 comments on commit 953ae77

Please sign in to comment.