Skip to content

Commit

Permalink
Log when mirrorred ref is used
Browse files Browse the repository at this point in the history
Signed-off-by: Anthony Emengo <[email protected]>
  • Loading branch information
Anthony Emengo committed Jul 7, 2021
1 parent cfdac4a commit 95ed976
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 7 deletions.
2 changes: 1 addition & 1 deletion build.go
Original file line number Diff line number Diff line change
Expand Up @@ -289,7 +289,7 @@ func (c *Client) Build(ctx context.Context, opts BuildOptions) error {
return err
}

runImageName, err = pname.TranslateRegistry(runImageName, c.registryMirrors)
runImageName, err = pname.TranslateRegistry(runImageName, c.registryMirrors, c.logger)
if err != nil {
return err
}
Expand Down
2 changes: 1 addition & 1 deletion internal/image/fetcher.go
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ func NewFetcher(logger logging.Logger, docker client.CommonAPIClient, opts ...Fe
var ErrNotFound = errors.New("not found")

func (f *Fetcher) Fetch(ctx context.Context, name string, options FetchOptions) (imgutil.Image, error) {
name, err := pname.TranslateRegistry(name, f.registryMirrors)
name, err := pname.TranslateRegistry(name, f.registryMirrors, f.logger)
if err != nil {
return nil, err
}
Expand Down
6 changes: 5 additions & 1 deletion internal/name/name.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,12 @@ import (
"fmt"

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

"github.com/buildpacks/pack/internal/style"
"github.com/buildpacks/pack/logging"
)

func TranslateRegistry(name string, registryMirrors map[string]string) (string, error) {
func TranslateRegistry(name string, registryMirrors map[string]string, logger logging.Logger) (string, error) {
if registryMirrors == nil {
return name, nil
}
Expand All @@ -28,6 +31,7 @@ func TranslateRegistry(name string, registryMirrors map[string]string) (string,
return "", err
}

logger.Infof("Using mirror %s for %s", style.Symbol(refName), name)
return refName, nil
}

Expand Down
11 changes: 7 additions & 4 deletions internal/name/name_test.go
Original file line number Diff line number Diff line change
@@ -1,12 +1,14 @@
package name_test

import (
"io/ioutil"
"testing"

"github.com/sclevine/spec"
"github.com/sclevine/spec/report"

"github.com/buildpacks/pack/internal/name"
"github.com/buildpacks/pack/logging"
h "github.com/buildpacks/pack/testhelpers"
)

Expand All @@ -17,13 +19,14 @@ func TestTranslateRegistry(t *testing.T) {
func testTranslateRegistry(t *testing.T, when spec.G, it spec.S) {
var (
assert = h.NewAssertionManager(t)
logger = logging.New(ioutil.Discard)
)

when("#TranslateRegistry", func() {
it("doesn't translate when there are no mirrors", func() {
input := "index.docker.io/my/buildpack:0.1"

output, err := name.TranslateRegistry(input, nil)
output, err := name.TranslateRegistry(input, nil, logger)
assert.Nil(err)
assert.Equal(output, input)
})
Expand All @@ -34,7 +37,7 @@ func testTranslateRegistry(t *testing.T, when spec.G, it spec.S) {
"us.gcr.io": "10.0.0.1",
}

output, err := name.TranslateRegistry(input, registryMirrors)
output, err := name.TranslateRegistry(input, registryMirrors, logger)
assert.Nil(err)
assert.Equal(output, input)
})
Expand All @@ -46,7 +49,7 @@ func testTranslateRegistry(t *testing.T, when spec.G, it spec.S) {
"index.docker.io": "10.0.0.1",
}

output, err := name.TranslateRegistry(input, registryMirrors)
output, err := name.TranslateRegistry(input, registryMirrors, logger)
assert.Nil(err)
assert.Equal(output, expected)
})
Expand All @@ -59,7 +62,7 @@ func testTranslateRegistry(t *testing.T, when spec.G, it spec.S) {
"*": "10.0.0.2",
}

output, err := name.TranslateRegistry(input, registryMirrors)
output, err := name.TranslateRegistry(input, registryMirrors, logger)
assert.Nil(err)
assert.Equal(output, expected)
})
Expand Down

0 comments on commit 95ed976

Please sign in to comment.