Skip to content

Commit 95a0454

Browse files
committed
Add support for platform api 0.7 and 0.8
Signed-off-by: Sambhav Kothari <skothari44@bloomberg.net>
1 parent fe92411 commit 95a0454

9 files changed

Lines changed: 579 additions & 92 deletions

File tree

acceptance/acceptance_test.go

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -941,7 +941,9 @@ func testAcceptance(
941941
assertOutput = assertions.NewOutputAssertionManager(t, output)
942942
assertOutput.ReportsSuccessfulImageBuild(repoName)
943943
assertLifecycleOutput = assertions.NewLifecycleOutputAssertionManager(t, output)
944-
assertLifecycleOutput.ReportsSkippingBuildpackLayerAnalysis()
944+
if !pack.SupportsFeature(invoke.AnalysisFirst) {
945+
assertLifecycleOutput.ReportsSkippingBuildpackLayerAnalysis()
946+
}
945947
assertLifecycleOutput.ReportsExporterReusingUnchangedLayer(cachedLaunchLayer)
946948
assertLifecycleOutput.ReportsCacheCreation(cachedLaunchLayer)
947949

acceptance/invoke/pack.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -222,6 +222,7 @@ const (
222222
InspectRemoteImage = iota
223223
BuilderNoDuplicateLayers
224224
SourceMetadataFromProjectTOML
225+
AnalysisFirst
225226
)
226227

227228
var featureTests = map[Feature]func(i *PackInvoker) bool{
@@ -234,6 +235,9 @@ var featureTests = map[Feature]func(i *PackInvoker) bool{
234235
SourceMetadataFromProjectTOML: func(i *PackInvoker) bool {
235236
return i.laterThan("0.20.0")
236237
},
238+
AnalysisFirst: func(i *PackInvoker) bool {
239+
return i.atLeast("0.23.0")
240+
},
237241
}
238242

239243
func (i *PackInvoker) SupportsFeature(f Feature) bool {

acceptance/testdata/pack_fixtures/report_output.txt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,9 @@ Pack:
22
Version: {{ .Version }}
33
OS/Arch: {{ .OS }}/{{ .Arch }}
44

5-
Default Lifecycle Version: 0.11.3
5+
Default Lifecycle Version: 0.13.0
66

7-
Supported Platform APIs: 0.3, 0.4, 0.5, 0.6
7+
Supported Platform APIs: 0.3, 0.4, 0.5, 0.6, 0.7, 0.8
88

99
Config:
1010
default-builder-image = "{{ .DefaultBuilder }}"

go.sum

Lines changed: 313 additions & 0 deletions
Large diffs are not rendered by default.

internal/build/lifecycle_execution.go

Lines changed: 55 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -144,16 +144,27 @@ func (l *LifecycleExecution) Run(ctx context.Context, phaseFactoryCreator PhaseF
144144
launchCache := cache.NewVolumeCache(l.opts.Image, "launch", l.docker)
145145

146146
if !l.opts.UseCreator {
147-
l.logger.Info(style.Step("DETECTING"))
148-
if err := l.Detect(ctx, l.opts.Network, l.opts.Volumes, phaseFactory); err != nil {
149-
return err
150-
}
147+
if l.platformAPI.LessThan("0.7") {
148+
l.logger.Info(style.Step("DETECTING"))
149+
if err := l.Detect(ctx, l.opts.Network, l.opts.Volumes, phaseFactory); err != nil {
150+
return err
151+
}
151152

152-
l.logger.Info(style.Step("ANALYZING"))
153-
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 {
154-
return err
155-
}
153+
l.logger.Info(style.Step("ANALYZING"))
154+
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 {
155+
return err
156+
}
157+
} else {
158+
l.logger.Info(style.Step("ANALYZING"))
159+
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 {
160+
return err
161+
}
156162

163+
l.logger.Info(style.Step("DETECTING"))
164+
if err := l.Detect(ctx, l.opts.Network, l.opts.Volumes, phaseFactory); err != nil {
165+
return err
166+
}
167+
}
157168
l.logger.Info(style.Step("RESTORING"))
158169
if l.opts.ClearCache {
159170
l.logger.Info("Skipping 'restore' due to clearing cache")
@@ -326,23 +337,26 @@ func (l *LifecycleExecution) Restore(ctx context.Context, networkMode string, bu
326337
return restore.Run(ctx)
327338
}
328339

329-
func (l *LifecycleExecution) Analyze(ctx context.Context, repoName, networkMode string, publish bool, dockerHost string, clearCache bool, cache Cache, phaseFactory PhaseFactory) error {
330-
analyze, err := l.newAnalyze(repoName, networkMode, publish, dockerHost, clearCache, cache, phaseFactory)
340+
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 {
341+
analyze, err := l.newAnalyze(repoName, networkMode, publish, dockerHost, clearCache, runImage, additionalTags, cache, phaseFactory)
331342
if err != nil {
332343
return err
333344
}
334345
defer analyze.Cleanup()
335346
return analyze.Run(ctx)
336347
}
337348

338-
func (l *LifecycleExecution) newAnalyze(repoName, networkMode string, publish bool, dockerHost string, clearCache bool, buildCache Cache, phaseFactory PhaseFactory) (RunnerCleaner, error) {
349+
func (l *LifecycleExecution) newAnalyze(repoName, networkMode string, publish bool, dockerHost string, clearCache bool, runImage string, additionalTags []string, buildCache Cache, phaseFactory PhaseFactory) (RunnerCleaner, error) {
339350
args := []string{
340351
repoName,
341352
}
342-
if clearCache {
343-
args = prependArg("-skip-layers", args)
344-
} else {
345-
args = append([]string{"-cache-dir", l.mountPaths.cacheDir()}, args...)
353+
platformAPILessThan07 := l.platformAPI.LessThan("0.7")
354+
if platformAPILessThan07 {
355+
if clearCache {
356+
args = prependArg("-skip-layers", args)
357+
} else {
358+
args = append([]string{"-cache-dir", l.mountPaths.cacheDir()}, args...)
359+
}
346360
}
347361

348362
cacheOpt := NullOp()
@@ -353,7 +367,9 @@ func (l *LifecycleExecution) newAnalyze(repoName, networkMode string, publish bo
353367
flagsOpt = WithFlags("-cache-image", buildCache.Name())
354368
}
355369
case cache.Volume:
356-
cacheOpt = WithBinds(fmt.Sprintf("%s:%s", buildCache.Name(), l.mountPaths.cacheDir()))
370+
if platformAPILessThan07 {
371+
cacheOpt = WithBinds(fmt.Sprintf("%s:%s", buildCache.Name(), l.mountPaths.cacheDir()))
372+
}
357373
}
358374

359375
if l.opts.GID >= overrideGID {
@@ -381,8 +397,22 @@ func (l *LifecycleExecution) newAnalyze(repoName, networkMode string, publish bo
381397
previous-image registry = %s`, image.Context().RegistryStr(), prevImage.Context().RegistryStr())
382398
}
383399
}
384-
385-
l.opts.Image = prevImage
400+
if platformAPILessThan07 {
401+
l.opts.Image = prevImage
402+
} else {
403+
args = append([]string{"-previous-image", l.opts.PreviousImage}, args...)
404+
}
405+
}
406+
stackOpts := NullOp()
407+
if !platformAPILessThan07 {
408+
for _, tag := range additionalTags {
409+
args = append([]string{"-tag", tag}, args...)
410+
}
411+
if runImage != "" {
412+
args = append([]string{"-run-image", runImage}, args...)
413+
}
414+
args = append([]string{"-stack", l.mountPaths.stackPath()}, args...)
415+
stackOpts = WithContainerOperations(WriteStackToml(l.mountPaths.stackPath(), l.opts.Builder.Stack(), l.os))
386416
}
387417

388418
if publish {
@@ -403,6 +433,7 @@ func (l *LifecycleExecution) newAnalyze(repoName, networkMode string, publish bo
403433
WithNetwork(networkMode),
404434
flagsOpt,
405435
cacheOpt,
436+
stackOpts,
406437
)
407438

408439
return phaseFactory.New(configProvider), nil
@@ -430,6 +461,7 @@ func (l *LifecycleExecution) newAnalyze(repoName, networkMode string, publish bo
430461
flagsOpt,
431462
WithNetwork(networkMode),
432463
cacheOpt,
464+
stackOpts,
433465
)
434466

435467
return phaseFactory.New(configProvider), nil
@@ -467,9 +499,13 @@ func (l *LifecycleExecution) newExport(repoName, runImage string, publish bool,
467499
"-app", l.mountPaths.appDir(),
468500
"-cache-dir", l.mountPaths.cacheDir(),
469501
"-stack", l.mountPaths.stackPath(),
470-
"-run-image", runImage,
471502
}
472503

504+
if l.platformAPI.LessThan("0.7") {
505+
flags = append(flags,
506+
"-run-image", runImage,
507+
)
508+
}
473509
processType := determineDefaultProcessType(l.platformAPI, l.opts.DefaultProcessType)
474510
if processType != "" {
475511
flags = append(flags, "-process-type", processType)

0 commit comments

Comments
 (0)