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

Output image name as provided by user #822

Merged
merged 4 commits into from
Sep 17, 2020
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
27 changes: 14 additions & 13 deletions common_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,14 +32,15 @@ func testCommon(t *testing.T, when spec.G, it spec.S) {
gcrRegistry string
gcrRunMirror string
stackInfo builder.StackMetadata
assert = h.NewAssertionManager(t)
)

it.Before(func() {
logger = ilogging.NewLogWithWriters(&outBuf, &outBuf)

var err error
subject, err = NewClient(WithLogger(logger))
h.AssertNil(t, err)
assert.Nil(err)

defaultRegistry = "default.registry.io"
runImageName = "stack/run"
Expand All @@ -60,59 +61,59 @@ func testCommon(t *testing.T, when spec.G, it spec.S) {
it("selects that run image", func() {
runImgFlag := "flag/passed-run-image"
runImageName := subject.resolveRunImage(runImgFlag, defaultRegistry, "", stackInfo, nil, false)
h.AssertEq(t, runImageName, runImgFlag)
assert.Equal(runImageName, runImgFlag)
})
})

when("publish is true", func() {
it("defaults to run-image in registry publishing to", func() {
runImageName := subject.resolveRunImage("", gcrRegistry, defaultRegistry, stackInfo, nil, true)
h.AssertEq(t, runImageName, gcrRunMirror)
assert.Equal(runImageName, gcrRunMirror)
})

it("prefers config defined run image mirror to stack defined run image mirror", func() {
configMirrors := map[string][]string{
runImageName: []string{defaultRegistry + "/unique-run-img"},
}
runImageName := subject.resolveRunImage("", defaultRegistry, "", stackInfo, configMirrors, true)
h.AssertNotEq(t, runImageName, defaultMirror)
h.AssertEq(t, runImageName, defaultRegistry+"/unique-run-img")
assert.NotEqual(runImageName, defaultMirror)
assert.Equal(runImageName, defaultRegistry+"/unique-run-img")
})

it("returns a config mirror if no match to target registry", func() {
configMirrors := map[string][]string{
runImageName: []string{defaultRegistry + "/unique-run-img"},
}
runImageName := subject.resolveRunImage("", "test.registry.io", "", stackInfo, configMirrors, true)
h.AssertNotEq(t, runImageName, defaultMirror)
h.AssertEq(t, runImageName, defaultRegistry+"/unique-run-img")
assert.NotEqual(runImageName, defaultMirror)
assert.Equal(runImageName, defaultRegistry+"/unique-run-img")
})
})

// If publish is false, we are using the local daemon, and want to match to the builder registry
when("publish is false", func() {
it("defaults to run-image in registry publishing to", func() {
runImageName := subject.resolveRunImage("", gcrRegistry, defaultRegistry, stackInfo, nil, false)
h.AssertEq(t, runImageName, defaultMirror)
h.AssertNotEq(t, runImageName, gcrRunMirror)
assert.Equal(runImageName, defaultMirror)
assert.NotEqual(runImageName, gcrRunMirror)
})

it("prefers config defined run image mirror to stack defined run image mirror", func() {
configMirrors := map[string][]string{
runImageName: []string{defaultRegistry + "/unique-run-img"},
}
runImageName := subject.resolveRunImage("", gcrRegistry, defaultRegistry, stackInfo, configMirrors, false)
h.AssertNotEq(t, runImageName, defaultMirror)
h.AssertEq(t, runImageName, defaultRegistry+"/unique-run-img")
assert.NotEqual(runImageName, defaultMirror)
assert.Equal(runImageName, defaultRegistry+"/unique-run-img")
})

it("returns a config mirror if no match to target registry", func() {
configMirrors := map[string][]string{
runImageName: []string{defaultRegistry + "/unique-run-img"},
}
runImageName := subject.resolveRunImage("", defaultRegistry, "test.registry.io", stackInfo, configMirrors, false)
h.AssertNotEq(t, runImageName, defaultMirror)
h.AssertEq(t, runImageName, defaultRegistry+"/unique-run-img")
assert.NotEqual(runImageName, defaultMirror)
assert.Equal(runImageName, defaultRegistry+"/unique-run-img")
})
})
})
Expand Down
4 changes: 2 additions & 2 deletions internal/build/fakes/fake_phase_factory.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import "github.com/buildpacks/pack/internal/build"
type FakePhaseFactory struct {
NewCallCount int
ReturnForNew build.RunnerCleaner
NewCalledWithProvider *build.PhaseConfigProvider
NewCalledWithProvider []*build.PhaseConfigProvider
}

func NewFakePhaseFactory(ops ...func(*FakePhaseFactory)) *FakePhaseFactory {
Expand All @@ -28,7 +28,7 @@ func WhichReturnsForNew(phase build.RunnerCleaner) func(*FakePhaseFactory) {

func (f *FakePhaseFactory) New(phaseConfigProvider *build.PhaseConfigProvider) build.RunnerCleaner {
f.NewCallCount++
f.NewCalledWithProvider = phaseConfigProvider
f.NewCalledWithProvider = append(f.NewCalledWithProvider, phaseConfigProvider)

return f.ReturnForNew
}
10 changes: 5 additions & 5 deletions internal/build/lifecycle_execution.go
Original file line number Diff line number Diff line change
Expand Up @@ -102,8 +102,8 @@ func (l *LifecycleExecution) PlatformAPI() *api.Version {
return l.platformAPI
}

func (l *LifecycleExecution) Run(ctx context.Context) error {
phaseFactory := NewDefaultPhaseFactory(l)
func (l *LifecycleExecution) Run(ctx context.Context, phaseFactoryCreator PhaseFactoryCreator) error {
phaseFactory := phaseFactoryCreator(l)

buildCache := cache.NewVolumeCache(l.opts.Image, "build", l.docker)

Expand All @@ -124,7 +124,7 @@ func (l *LifecycleExecution) Run(ctx context.Context) error {
}

l.logger.Info(style.Step("ANALYZING"))
if err := l.Analyze(ctx, l.opts.Image.Name(), buildCache.Name(), l.opts.Network, l.opts.Publish, l.opts.ClearCache, phaseFactory); err != nil {
if err := l.Analyze(ctx, l.opts.Image.String(), buildCache.Name(), l.opts.Network, l.opts.Publish, l.opts.ClearCache, phaseFactory); err != nil {
return err
}

Expand All @@ -142,7 +142,7 @@ func (l *LifecycleExecution) Run(ctx context.Context) error {
}

l.logger.Info(style.Step("EXPORTING"))
return l.Export(ctx, l.opts.Image.Name(), l.opts.RunImage, l.opts.Publish, launchCache.Name(), buildCache.Name(), l.opts.Network, phaseFactory)
return l.Export(ctx, l.opts.Image.String(), l.opts.RunImage, l.opts.Publish, launchCache.Name(), buildCache.Name(), l.opts.Network, phaseFactory)
}

return l.Create(
Expand All @@ -152,7 +152,7 @@ func (l *LifecycleExecution) Run(ctx context.Context) error {
l.opts.RunImage,
launchCache.Name(),
buildCache.Name(),
l.opts.Image.Name(),
l.opts.Image.String(),
l.opts.Network,
l.opts.Volumes,
phaseFactory,
Expand Down
Loading