Skip to content

Commit

Permalink
Support default process type while publishing
Browse files Browse the repository at this point in the history
Signed-off-by: Zander Mackie <zmackie@gmail.com>
  • Loading branch information
zmackie committed May 5, 2020
1 parent 87030a1 commit 00a01ca
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 13 deletions.
23 changes: 12 additions & 11 deletions internal/build/phases.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,6 @@ import (
"github.com/Masterminds/semver"
"github.com/buildpacks/lifecycle/auth"
"github.com/google/go-containerregistry/pkg/authn"

"github.com/buildpacks/pack/internal/api"
)

const (
Expand Down Expand Up @@ -165,6 +163,12 @@ func (l *Lifecycle) newExport(repoName, runImage string, publish bool, launchCac

binds := []string{fmt.Sprintf("%s:%s", cacheName, cacheDir)}

if l.DefaultProcessType != "" && l.supportsDefaultProcess() {
args = append([]string{"-process-type", l.DefaultProcessType}, args...)
} else {
l.logger.Warn("You specified a default process type but that is not supported by this version of the lifecycle")
}

if publish {
authConfig, err := auth.BuildEnvVar(authn.DefaultKeychain, repoName, runImage)
if err != nil {
Expand All @@ -188,15 +192,6 @@ func (l *Lifecycle) newExport(repoName, runImage string, publish bool, launchCac
args = append([]string{"-daemon", "-launch-cache", launchCacheDir}, args...)
binds = append(binds, fmt.Sprintf("%s:%s", launchCacheName, launchCacheDir))

if l.DefaultProcessType != "" {
supportsDefaultProcess := api.MustParse(l.platformAPIVersion).SupportsVersion(api.MustParse(defaultProcessPlatformAPI))
if supportsDefaultProcess {
args = append([]string{"-process-type", l.DefaultProcessType}, args...)
} else {
l.logger.Warn("You specified a default process type but that is not supported by this version of the lifecycle")
}
}

configProvider := NewPhaseConfigProvider(
"exporter",
l,
Expand Down Expand Up @@ -227,3 +222,9 @@ func (l *Lifecycle) exportImageArgs(runImage string) []string {
}
return []string{"-image", runImage}
}

func (l *Lifecycle) supportsDefaultProcess() bool {
apiVersion := semver.MustParse(l.platformAPIVersion)
defaultProcVersion := semver.MustParse(defaultProcessPlatformAPI)
return apiVersion.GreaterThan(defaultProcVersion) || apiVersion.Equal(defaultProcVersion)
}
26 changes: 24 additions & 2 deletions internal/build/phases_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -500,11 +500,19 @@ func testPhases(t *testing.T, when spec.G, it spec.S) {
})

when("platform api 0.3+", func() {
it("uses -run-image instead of deprecated -image", func() {
var (
fakeBuilder *fakes.FakeBuilder
err error
)

it.Before(func() {
platformAPIVersion, err := api.NewVersion("0.3")
h.AssertNil(t, err)
fakeBuilder, err := fakes.NewFakeBuilder(fakes.WithPlatformVersion(platformAPIVersion))
fakeBuilder, err = fakes.NewFakeBuilder(fakes.WithPlatformVersion(platformAPIVersion))
h.AssertNil(t, err)
})

it("uses -run-image instead of deprecated -image", func() {
lifecycle := fakeLifecycle(t, false, fakes.WithBuilder(fakeBuilder))
fakePhaseFactory := fakes.NewFakePhaseFactory()
expectedRunImage := "some-run-image"
Expand All @@ -519,6 +527,20 @@ func testPhases(t *testing.T, when spec.G, it spec.S) {
[]string{"-run-image", expectedRunImage},
)
})

it("configures the phase with default arguments", func() {
lifecycle := fakeLifecycle(t, true, fakes.WithBuilder(fakeBuilder), func(options *build.LifecycleOptions) {
options.DefaultProcessType = "test-process"
})
fakePhaseFactory := fakes.NewFakePhaseFactory()
expectedDefaultProc := []string{"-process-type", "test-process"}

err := lifecycle.Export(context.Background(), "test", "test", false, "test", "test", fakePhaseFactory)
h.AssertNil(t, err)
configProvider := fakePhaseFactory.NewCalledWithProvider
h.AssertIncludeAllExpectedPatterns(t, configProvider.ContainerConfig().Cmd, expectedDefaultProc)
})

})
})
}
Expand Down

0 comments on commit 00a01ca

Please sign in to comment.