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

Publish should also support default process #602

Merged
merged 3 commits into from
May 7, 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
3 changes: 1 addition & 2 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -462,9 +462,8 @@ golang.org/x/crypto v0.0.0-20190820162420-60c769a6c586/go.mod h1:yigFU9vqHzYiE8U
golang.org/x/crypto v0.0.0-20191011191535-87dc89f01550/go.mod h1:yigFU9vqHzYiE8UmvKecakEJjdnWj3jj499lnFckfCI=
golang.org/x/crypto v0.0.0-20191206172530-e9b2fee46413/go.mod h1:LzIPMQfyMNhhGPhUkYOs5KpL4U8rLKemX1yGLhDgUto=
golang.org/x/crypto v0.0.0-20200220183623-bac4c82f6975/go.mod h1:LzIPMQfyMNhhGPhUkYOs5KpL4U8rLKemX1yGLhDgUto=
golang.org/x/crypto v0.0.0-20200311171314-f7b00557c8c4 h1:QmwruyY+bKbDDL0BaglrbZABEali68eoMFhTZpCjYVA=
golang.org/x/crypto v0.0.0-20200311171314-f7b00557c8c4/go.mod h1:LzIPMQfyMNhhGPhUkYOs5KpL4U8rLKemX1yGLhDgUto=
golang.org/x/crypto v0.0.0-20200323165209-0ec3e9974c59 h1:3zb4D3T4G8jdExgVU/95+vQXfpEPiMdCaZgmGVxjNHM=
golang.org/x/crypto v0.0.0-20200323165209-0ec3e9974c59/go.mod h1:LzIPMQfyMNhhGPhUkYOs5KpL4U8rLKemX1yGLhDgUto=
golang.org/x/exp v0.0.0-20190121172915-509febef88a4/go.mod h1:CJ0aWSM057203Lf6IL+f9T1iT9GByDxfZKAQTCR3kQA=
golang.org/x/exp v0.0.0-20190125153040-c74c464bbbf2/go.mod h1:CJ0aWSM057203Lf6IL+f9T1iT9GByDxfZKAQTCR3kQA=
golang.org/x/exp v0.0.0-20190312203227-4b39c73a6495/go.mod h1:ZjyILWgesfNpC6sMxTJOJm9Kp84zZh5NQWvqDGG3Qr8=
Expand Down
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)
}
25 changes: 23 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,19 @@ 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
6 changes: 3 additions & 3 deletions vendor/modules.txt
Original file line number Diff line number Diff line change
Expand Up @@ -12,14 +12,13 @@ github.com/Microsoft/go-winio/pkg/guid
github.com/Microsoft/hcsshim/osversion
# github.com/apex/log v1.1.2
github.com/apex/log
# github.com/buildpacks/imgutil v0.0.0-20200313170640-a02052f47d62
# github.com/buildpacks/imgutil v0.0.0-20200424215026-dfdc82949704
github.com/buildpacks/imgutil
github.com/buildpacks/imgutil/archive
github.com/buildpacks/imgutil/fakes
github.com/buildpacks/imgutil/layer
github.com/buildpacks/imgutil/local
github.com/buildpacks/imgutil/remote
# github.com/buildpacks/lifecycle v0.7.1
# github.com/buildpacks/lifecycle v0.7.2
github.com/buildpacks/lifecycle
github.com/buildpacks/lifecycle/api
github.com/buildpacks/lifecycle/archive
Expand Down Expand Up @@ -194,6 +193,7 @@ github.com/src-d/gcfg/types
# github.com/xanzy/ssh-agent v0.2.1
github.com/xanzy/ssh-agent
# golang.org/x/crypto v0.0.0-20200311171314-f7b00557c8c4
golang.org/x/crypto/bcrypt
golang.org/x/crypto/blowfish
golang.org/x/crypto/cast5
golang.org/x/crypto/chacha20
Expand Down