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

Lifecycle image #1130

Merged
merged 7 commits into from
May 8, 2021
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
8 changes: 5 additions & 3 deletions DEVELOPMENT.md
Original file line number Diff line number Diff line change
Expand Up @@ -100,8 +100,10 @@ Some options users can provide to our acceptance tests are:
| ACCEPTANCE_SUITE_CONFIG | A set of configurations for how to run the acceptance tests, describing the version of `pack` used for testing, the version of `pack` used to create the builders used in the test, and the version of `lifecycle` binaries used to test with Github | `[{"pack": "current", "pack_create_builder": "current", "lifecycle": "default"}]'` |
| COMPILE_PACK_WITH_VERSION | Tell `pack` what version to consider itself | `dev` |
| GITHUB_TOKEN | A Github Token, used when downloading `pack` and `lifecycle` releases from Github during the test setup | "" |
| PACK_PATH | Path to a `pack` executable. | A compiled version of the current branch |
| PREVIOUS_PACK_PATH | Path to a `pack` executable, used to test compatibility with n-1 version of `pack` | The most recent release from `pack`'s Github release |
| PREVIOUS_PACK_FIXTURES_PATH | Path to a set of fixtures, used to override the most up-to-date fixtures, in case of changed functionality | `acceptance/testdata/pack_previous_fixtures_overrides` |
Comment on lines -103 to -105
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sorted alphabetically...

| LIFECYCLE_IMAGE | Image reference to be used in untrusted builder workflows | buildpacksio/lifecycle:<lifecycle version> |
| LIFECYCLE_PATH | Path to a `.tgz` file filled with a set of `lifecycle` binaries | The Github release for the default version of lifecycle in `pack` |
| PACK_PATH | Path to a `pack` executable. | A compiled version of the current branch |
| PREVIOUS_LIFECYCLE_IMAGE | Image reference to be used in untrusted builder workflows, used to test compatibility of `pack` with the n-1 version of the `lifecycle` | buildpacksio/lifecycle:<PREVIOUS_LIFECYCLE_PATH lifecycle version>, buildpacksio/lifecycle:<n-1 lifecycle version> |
| PREVIOUS_LIFECYCLE_PATH | Path to a `.tgz` file filled with a set of `lifecycle` binaries, used to test compatibility of `pack` with the n-1 version of the `lifecycle` | The Github release for n-1 release of `lifecycle` |
| PREVIOUS_PACK_FIXTURES_PATH | Path to a set of fixtures, used to override the most up-to-date fixtures, in case of changed functionality | `acceptance/testdata/pack_previous_fixtures_overrides` |
| PREVIOUS_PACK_PATH | Path to a `pack` executable, used to test compatibility with n-1 version of `pack` | The most recent release from `pack`'s Github release |
9 changes: 4 additions & 5 deletions acceptance/acceptance_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,6 @@ import (
"github.com/buildpacks/pack/acceptance/managers"
pubcfg "github.com/buildpacks/pack/config"
"github.com/buildpacks/pack/internal/cache"
internalConfig "github.com/buildpacks/pack/internal/config"
"github.com/buildpacks/pack/internal/style"
"github.com/buildpacks/pack/pkg/archive"
h "github.com/buildpacks/pack/testhelpers"
Expand Down Expand Up @@ -772,6 +771,7 @@ func testAcceptance(
it.Before(func() {
repo = "some-org/" + h.RandString(10)
repoName = registryConfig.RepoName(repo)
pack.JustRunSuccessfully("config", "lifecycle-image", lifecycle.Image())
})

it.After(func() {
Expand All @@ -798,14 +798,13 @@ func testAcceptance(
buildpackManager,
runImageMirror,
)
assert.Nil(err)

suiteManager.RegisterCleanUp("remove-lifecycle-"+lifecycle.Version(), func() error {
img := imageManager.GetImageID(fmt.Sprintf("%s:%s", internalConfig.DefaultLifecycleImageRepo, lifecycle.Version()))
suiteManager.RegisterCleanUp("remove-lifecycle-"+lifecycle.Image(), func() error {
img := imageManager.GetImageID(lifecycle.Image())
imageManager.CleanupImages(img)
return nil
})

assert.Nil(err)
})

it.After(func() {
Expand Down
51 changes: 45 additions & 6 deletions acceptance/config/asset_manager.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ import (
acceptanceOS "github.com/buildpacks/pack/acceptance/os"
"github.com/buildpacks/pack/internal/blob"
"github.com/buildpacks/pack/internal/builder"
"github.com/buildpacks/pack/internal/config"
"github.com/buildpacks/pack/internal/style"
h "github.com/buildpacks/pack/testhelpers"
)
Expand All @@ -36,8 +37,10 @@ type AssetManager struct {
githubAssetFetcher *GithubAssetFetcher
lifecyclePath string
lifecycleDescriptor builder.LifecycleDescriptor
lifecycleImage string
previousLifecyclePath string
previousLifecycleDescriptor builder.LifecycleDescriptor
previousLifecycleImage string
defaultLifecycleDescriptor builder.LifecycleDescriptor
testObject *testing.T
}
Expand All @@ -50,8 +53,10 @@ func ConvergedAssetManager(t *testing.T, assert h.AssertionManager, inputConfig
convergedPreviousPackPath string
convergedPreviousPackFixturesPaths []string
convergedCurrentLifecyclePath string
convergedCurrentLifecycleImage string
convergedCurrentLifecycleDescriptor builder.LifecycleDescriptor
convergedPreviousLifecyclePath string
convergedPreviousLifecycleImage string
convergedPreviousLifecycleDescriptor builder.LifecycleDescriptor
convergedDefaultLifecycleDescriptor builder.LifecycleDescriptor
)
Expand All @@ -78,11 +83,11 @@ func ConvergedAssetManager(t *testing.T, assert h.AssertionManager, inputConfig
}

if inputConfig.combinations.requiresCurrentLifecycle() {
convergedCurrentLifecyclePath, convergedCurrentLifecycleDescriptor = assetBuilder.ensureCurrentLifecycle()
convergedCurrentLifecyclePath, convergedCurrentLifecycleImage, convergedCurrentLifecycleDescriptor = assetBuilder.ensureCurrentLifecycle()
}

if inputConfig.combinations.requiresPreviousLifecycle() {
convergedPreviousLifecyclePath, convergedPreviousLifecycleDescriptor = assetBuilder.ensurePreviousLifecycle()
convergedPreviousLifecyclePath, convergedPreviousLifecycleImage, convergedPreviousLifecycleDescriptor = assetBuilder.ensurePreviousLifecycle()
}

if inputConfig.combinations.requiresDefaultLifecycle() {
Expand All @@ -95,8 +100,10 @@ func ConvergedAssetManager(t *testing.T, assert h.AssertionManager, inputConfig
previousPackPath: convergedPreviousPackPath,
previousPackFixturesPaths: convergedPreviousPackFixturesPaths,
lifecyclePath: convergedCurrentLifecyclePath,
lifecycleImage: convergedCurrentLifecycleImage,
lifecycleDescriptor: convergedCurrentLifecycleDescriptor,
previousLifecyclePath: convergedPreviousLifecyclePath,
previousLifecycleImage: convergedPreviousLifecycleImage,
previousLifecycleDescriptor: convergedPreviousLifecycleDescriptor,
defaultLifecycleDescriptor: convergedDefaultLifecycleDescriptor,
testObject: t,
Expand Down Expand Up @@ -152,6 +159,22 @@ func (a AssetManager) LifecycleDescriptor(kind ComboValue) builder.LifecycleDesc
return builder.LifecycleDescriptor{} // Unreachable
}

func (a AssetManager) LifecycleImage(kind ComboValue) string {
a.testObject.Helper()

switch kind {
case Current:
natalieparellano marked this conversation as resolved.
Show resolved Hide resolved
return a.lifecycleImage
case Previous:
natalieparellano marked this conversation as resolved.
Show resolved Hide resolved
return a.previousLifecycleImage
case DefaultKind:
return fmt.Sprintf("%s:%s", config.DefaultLifecycleImageRepo, a.defaultLifecycleDescriptor.Info.Version)
natalieparellano marked this conversation as resolved.
Show resolved Hide resolved
}

a.testObject.Fatalf("lifecycle kind must be previous, current or default was %s", kind)
return "" // Unreachable
}

type assetManagerBuilder struct {
testObject *testing.T
assert h.AssertionManager
Expand Down Expand Up @@ -235,7 +258,7 @@ func (b assetManagerBuilder) ensurePreviousPackFixtures() string {
return fixturesDir
}

func (b assetManagerBuilder) ensureCurrentLifecycle() (string, builder.LifecycleDescriptor) {
func (b assetManagerBuilder) ensureCurrentLifecycle() (string, string, builder.LifecycleDescriptor) {
b.testObject.Helper()

lifecyclePath := b.inputConfig.lifecyclePath
Expand All @@ -255,10 +278,18 @@ func (b assetManagerBuilder) ensureCurrentLifecycle() (string, builder.Lifecycle
lifecycle, err := builder.NewLifecycle(blob.NewBlob(lifecyclePath))
b.assert.Nil(err)

return lifecyclePath, lifecycle.Descriptor()
lifecycleImage := b.inputConfig.lifecycleImage

if lifecycleImage == "" {
lifecycleImage = fmt.Sprintf("%s:%s", config.DefaultLifecycleImageRepo, lifecycle.Descriptor().Info.Version)

b.testObject.Logf("using %s for current lifecycle image", lifecycleImage)
}

return lifecyclePath, lifecycleImage, lifecycle.Descriptor()
}

func (b assetManagerBuilder) ensurePreviousLifecycle() (string, builder.LifecycleDescriptor) {
func (b assetManagerBuilder) ensurePreviousLifecycle() (string, string, builder.LifecycleDescriptor) {
b.testObject.Helper()

previousLifecyclePath := b.inputConfig.previousLifecyclePath
Expand All @@ -278,7 +309,15 @@ func (b assetManagerBuilder) ensurePreviousLifecycle() (string, builder.Lifecycl
lifecycle, err := builder.NewLifecycle(blob.NewBlob(previousLifecyclePath))
b.assert.Nil(err)

return previousLifecyclePath, lifecycle.Descriptor()
previousLifecycleImage := b.inputConfig.previousLifecycleImage

if previousLifecycleImage == "" {
previousLifecycleImage = fmt.Sprintf("%s:%s", config.DefaultLifecycleImageRepo, lifecycle.Descriptor().Info.Version)
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

opt.semgrep.sprintf-host-port: Use net.JoinHostPort instead of fmt.Sprintf(config.DefaultLifecycleImageRepo, lifecycle.Descriptor().Info.Version). When using IPv6, JoinHostPort continues to operate properly.

(at-me in a reply with help or ignore)

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@Muse-Dev ignore

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I've recorded this as ignored for this pull request. If you change your mind, just comment @muse-dev unignore.


b.testObject.Logf("using %s for previous lifecycle image", previousLifecycleImage)
}

return previousLifecyclePath, previousLifecycleImage, lifecycle.Descriptor()
}

func (b assetManagerBuilder) downloadLifecycle(version string) string {
Expand Down
24 changes: 14 additions & 10 deletions acceptance/config/input_configuration_manager.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,14 +13,16 @@ import (
)

const (
envPackPath = "PACK_PATH"
envPreviousPackPath = "PREVIOUS_PACK_PATH"
envPreviousPackFixturesPath = "PREVIOUS_PACK_FIXTURES_PATH"
envLifecyclePath = "LIFECYCLE_PATH"
envPreviousLifecyclePath = "PREVIOUS_LIFECYCLE_PATH"
envGitHubToken = "GITHUB_TOKEN"
Comment on lines -16 to -21
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sorted again...

envAcceptanceSuiteConfig = "ACCEPTANCE_SUITE_CONFIG"
envCompilePackWithVersion = "COMPILE_PACK_WITH_VERSION"
envGitHubToken = "GITHUB_TOKEN"
envLifecycleImage = "LIFECYCLE_IMAGE"
envLifecyclePath = "LIFECYCLE_PATH"
envPackPath = "PACK_PATH"
envPreviousLifecycleImage = "PREVIOUS_LIFECYCLE_IMAGE"
envPreviousLifecyclePath = "PREVIOUS_LIFECYCLE_PATH"
envPreviousPackFixturesPath = "PREVIOUS_PACK_FIXTURES_PATH"
envPreviousPackPath = "PREVIOUS_PACK_PATH"
)

type InputConfigurationManager struct {
Expand All @@ -29,6 +31,8 @@ type InputConfigurationManager struct {
previousPackFixturesPath string
lifecyclePath string
previousLifecyclePath string
lifecycleImage string
previousLifecycleImage string
compilePackWithVersion string
githubToken string
combinations ComboSet
Expand All @@ -40,8 +44,6 @@ func NewInputConfigurationManager() (InputConfigurationManager, error) {
previousPackFixturesPath := os.Getenv(envPreviousPackFixturesPath)
lifecyclePath := os.Getenv(envLifecyclePath)
previousLifecyclePath := os.Getenv(envPreviousLifecyclePath)
compilePackWithVersion := os.Getenv(envCompilePackWithVersion)
githubToken := os.Getenv(envGitHubToken)

err := resolveAbsolutePaths(&packPath, &previousPackPath, &previousPackFixturesPath, &lifecyclePath, &previousLifecyclePath)
if err != nil {
Expand Down Expand Up @@ -69,8 +71,10 @@ func NewInputConfigurationManager() (InputConfigurationManager, error) {
previousPackFixturesPath: previousPackFixturesPath,
lifecyclePath: lifecyclePath,
previousLifecyclePath: previousLifecyclePath,
compilePackWithVersion: compilePackWithVersion,
githubToken: githubToken,
Comment on lines -72 to -73
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It seems fine to inline these.

lifecycleImage: os.Getenv(envLifecycleImage),
previousLifecycleImage: os.Getenv(envPreviousLifecycleImage),
compilePackWithVersion: os.Getenv(envCompilePackWithVersion),
githubToken: os.Getenv(envGitHubToken),
combinations: combos,
}, nil
}
Expand Down
6 changes: 6 additions & 0 deletions acceptance/config/lifecycle_asset.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,12 +15,14 @@ import (
type LifecycleAsset struct {
path string
descriptor builder.LifecycleDescriptor
image string
}

func (a AssetManager) NewLifecycleAsset(kind ComboValue) LifecycleAsset {
return LifecycleAsset{
path: a.LifecyclePath(kind),
descriptor: a.LifecycleDescriptor(kind),
image: a.LifecycleImage(kind),
}
}

Expand Down Expand Up @@ -48,6 +50,10 @@ func (l *LifecycleAsset) EscapedPath() string {
return strings.ReplaceAll(l.path, `\`, `\\`)
}

func (l *LifecycleAsset) Image() string {
return l.image
}

func earliestVersion(versions []*api.Version) *api.Version {
var earliest *api.Version
for _, version := range versions {
Expand Down