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

Add support for platform api 0.7 and 0.8 #1334

Merged
merged 3 commits into from
Nov 22, 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
4 changes: 3 additions & 1 deletion acceptance/acceptance_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -941,7 +941,9 @@ func testAcceptance(
assertOutput = assertions.NewOutputAssertionManager(t, output)
assertOutput.ReportsSuccessfulImageBuild(repoName)
assertLifecycleOutput = assertions.NewLifecycleOutputAssertionManager(t, output)
assertLifecycleOutput.ReportsSkippingBuildpackLayerAnalysis()
if !pack.SupportsFeature(invoke.AnalysisFirst) {
assertLifecycleOutput.ReportsSkippingBuildpackLayerAnalysis()
}
assertLifecycleOutput.ReportsExporterReusingUnchangedLayer(cachedLaunchLayer)
assertLifecycleOutput.ReportsCacheCreation(cachedLaunchLayer)

Expand Down
4 changes: 4 additions & 0 deletions acceptance/invoke/pack.go
Original file line number Diff line number Diff line change
Expand Up @@ -222,6 +222,7 @@ const (
InspectRemoteImage = iota
BuilderNoDuplicateLayers
SourceMetadataFromProjectTOML
AnalysisFirst
)

var featureTests = map[Feature]func(i *PackInvoker) bool{
Expand All @@ -234,6 +235,9 @@ var featureTests = map[Feature]func(i *PackInvoker) bool{
SourceMetadataFromProjectTOML: func(i *PackInvoker) bool {
return i.laterThan("0.20.0")
},
AnalysisFirst: func(i *PackInvoker) bool {
return i.atLeast("0.23.0")
},
}

func (i *PackInvoker) SupportsFeature(f Feature) bool {
Expand Down
4 changes: 2 additions & 2 deletions acceptance/testdata/pack_fixtures/report_output.txt
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@ Pack:
Version: {{ .Version }}
OS/Arch: {{ .OS }}/{{ .Arch }}

Default Lifecycle Version: 0.11.3
Default Lifecycle Version: 0.13.0

Supported Platform APIs: 0.3, 0.4, 0.5, 0.6
Supported Platform APIs: 0.3, 0.4, 0.5, 0.6, 0.7, 0.8

Config:
default-builder-image = "{{ .DefaultBuilder }}"
Expand Down
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ require (
github.com/Masterminds/semver v1.5.0
github.com/apex/log v1.9.0
github.com/buildpacks/imgutil v0.0.0-20211001201950-cf7ae41c3771
github.com/buildpacks/lifecycle v0.12.0
github.com/buildpacks/lifecycle v0.13.0
github.com/docker/cli v20.10.10+incompatible
github.com/docker/docker v20.10.10+incompatible
github.com/docker/go-connections v0.4.0
Expand Down
4 changes: 2 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -137,8 +137,8 @@ github.com/bugsnag/osext v0.0.0-20130617224835-0dd3f918b21b/go.mod h1:obH5gd0Bsq
github.com/bugsnag/panicwrap v0.0.0-20151223152923-e2c28503fcd0/go.mod h1:D/8v3kj0zr8ZAKg1AQ6crr+5VwKN5eIywRkfhyM/+dE=
github.com/buildpacks/imgutil v0.0.0-20211001201950-cf7ae41c3771 h1:QhUkvEeYhnyj80genY7ktXVLttVc52zstwPTUDrImvE=
github.com/buildpacks/imgutil v0.0.0-20211001201950-cf7ae41c3771/go.mod h1:ZfCbsFruoxG0vbEVMsX/afizEo4vn2e88Km7rJ1M2D8=
github.com/buildpacks/lifecycle v0.12.0 h1:H2K4uYfe/y1mfGekOPcR5flmFgmEmaVK9+I5V9Iz+M8=
github.com/buildpacks/lifecycle v0.12.0/go.mod h1:ub/iI72mgJT4d7JgcL06KmtvU4X4HTnFgUyqJKVYH2o=
github.com/buildpacks/lifecycle v0.13.0 h1:Hxc8tCvB5UVeEGVZuOWIeKcJy8XgO6fKnLkYyj1WKOE=
github.com/buildpacks/lifecycle v0.13.0/go.mod h1:s+uQ+driaV0+ffaT4UDIVCWoP/7kTUVsplU+L1Qd4e0=
github.com/census-instrumentation/opencensus-proto v0.2.1/go.mod h1:f6KPmirojxKA12rnyqOA5BBL4O983OfeGPqjHWSTneU=
github.com/cespare/xxhash v1.1.0/go.mod h1:XrSqR1VqqWfGrhpAt58auRo0WTKS1nRRg3ghfAqPWnc=
github.com/cespare/xxhash/v2 v2.1.1/go.mod h1:VGX0DQ3Q6kWi7AoAeZDth3/j3BFtOZR5XLFGgcrjCOs=
Expand Down
74 changes: 55 additions & 19 deletions internal/build/lifecycle_execution.go
Original file line number Diff line number Diff line change
Expand Up @@ -144,16 +144,27 @@ func (l *LifecycleExecution) Run(ctx context.Context, phaseFactoryCreator PhaseF
launchCache := cache.NewVolumeCache(l.opts.Image, "launch", l.docker)

if !l.opts.UseCreator {
l.logger.Info(style.Step("DETECTING"))
if err := l.Detect(ctx, l.opts.Network, l.opts.Volumes, phaseFactory); err != nil {
return err
}
if l.platformAPI.LessThan("0.7") {
l.logger.Info(style.Step("DETECTING"))
if err := l.Detect(ctx, l.opts.Network, l.opts.Volumes, phaseFactory); err != nil {
return err
}

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

l.logger.Info(style.Step("DETECTING"))
if err := l.Detect(ctx, l.opts.Network, l.opts.Volumes, phaseFactory); err != nil {
return err
}
}
l.logger.Info(style.Step("RESTORING"))
if l.opts.ClearCache {
l.logger.Info("Skipping 'restore' due to clearing cache")
Expand Down Expand Up @@ -326,23 +337,26 @@ func (l *LifecycleExecution) Restore(ctx context.Context, networkMode string, bu
return restore.Run(ctx)
}

func (l *LifecycleExecution) Analyze(ctx context.Context, repoName, networkMode string, publish bool, dockerHost string, clearCache bool, cache Cache, phaseFactory PhaseFactory) error {
analyze, err := l.newAnalyze(repoName, networkMode, publish, dockerHost, clearCache, cache, phaseFactory)
func (l *LifecycleExecution) Analyze(ctx context.Context, repoName, networkMode string, publish bool, dockerHost string, clearCache bool, runImage string, additionalTags []string, cache Cache, phaseFactory PhaseFactory) error {
analyze, err := l.newAnalyze(repoName, networkMode, publish, dockerHost, clearCache, runImage, additionalTags, cache, phaseFactory)
if err != nil {
return err
}
defer analyze.Cleanup()
return analyze.Run(ctx)
}

func (l *LifecycleExecution) newAnalyze(repoName, networkMode string, publish bool, dockerHost string, clearCache bool, buildCache Cache, phaseFactory PhaseFactory) (RunnerCleaner, error) {
func (l *LifecycleExecution) newAnalyze(repoName, networkMode string, publish bool, dockerHost string, clearCache bool, runImage string, additionalTags []string, buildCache Cache, phaseFactory PhaseFactory) (RunnerCleaner, error) {
args := []string{
repoName,
}
if clearCache {
args = prependArg("-skip-layers", args)
} else {
args = append([]string{"-cache-dir", l.mountPaths.cacheDir()}, args...)
platformAPILessThan07 := l.platformAPI.LessThan("0.7")
if platformAPILessThan07 {
if clearCache {
args = prependArg("-skip-layers", args)
} else {
args = append([]string{"-cache-dir", l.mountPaths.cacheDir()}, args...)
}
}

cacheOpt := NullOp()
Expand All @@ -353,7 +367,9 @@ func (l *LifecycleExecution) newAnalyze(repoName, networkMode string, publish bo
flagsOpt = WithFlags("-cache-image", buildCache.Name())
}
case cache.Volume:
cacheOpt = WithBinds(fmt.Sprintf("%s:%s", buildCache.Name(), l.mountPaths.cacheDir()))
if platformAPILessThan07 {
cacheOpt = WithBinds(fmt.Sprintf("%s:%s", buildCache.Name(), l.mountPaths.cacheDir()))
}
}

if l.opts.GID >= overrideGID {
Expand Down Expand Up @@ -381,8 +397,22 @@ func (l *LifecycleExecution) newAnalyze(repoName, networkMode string, publish bo
previous-image registry = %s`, image.Context().RegistryStr(), prevImage.Context().RegistryStr())
}
}

l.opts.Image = prevImage
if platformAPILessThan07 {
l.opts.Image = prevImage
} else {
args = append([]string{"-previous-image", l.opts.PreviousImage}, args...)
}
}
stackOpts := NullOp()
if !platformAPILessThan07 {
for _, tag := range additionalTags {
args = append([]string{"-tag", tag}, args...)
}
if runImage != "" {
args = append([]string{"-run-image", runImage}, args...)
}
args = append([]string{"-stack", l.mountPaths.stackPath()}, args...)
stackOpts = WithContainerOperations(WriteStackToml(l.mountPaths.stackPath(), l.opts.Builder.Stack(), l.os))
}

if publish {
Expand All @@ -403,6 +433,7 @@ func (l *LifecycleExecution) newAnalyze(repoName, networkMode string, publish bo
WithNetwork(networkMode),
flagsOpt,
cacheOpt,
stackOpts,
)

return phaseFactory.New(configProvider), nil
Expand Down Expand Up @@ -430,6 +461,7 @@ func (l *LifecycleExecution) newAnalyze(repoName, networkMode string, publish bo
flagsOpt,
WithNetwork(networkMode),
cacheOpt,
stackOpts,
)

return phaseFactory.New(configProvider), nil
Expand Down Expand Up @@ -467,9 +499,13 @@ func (l *LifecycleExecution) newExport(repoName, runImage string, publish bool,
"-app", l.mountPaths.appDir(),
"-cache-dir", l.mountPaths.cacheDir(),
"-stack", l.mountPaths.stackPath(),
"-run-image", runImage,
}

if l.platformAPI.LessThan("0.7") {
flags = append(flags,
"-run-image", runImage,
)
}
processType := determineDefaultProcessType(l.platformAPI, l.opts.DefaultProcessType)
if processType != "" {
flags = append(flags, "-process-type", processType)
Expand Down
Loading