Skip to content

Commit dd465ab

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 dd465ab

7 files changed

Lines changed: 576 additions & 93 deletions

File tree

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: 59 additions & 21 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
@@ -466,10 +498,16 @@ func (l *LifecycleExecution) newExport(repoName, runImage string, publish bool,
466498
flags := []string{
467499
"-app", l.mountPaths.appDir(),
468500
"-cache-dir", l.mountPaths.cacheDir(),
469-
"-stack", l.mountPaths.stackPath(),
470-
"-run-image", runImage,
471501
}
502+
stackOpts := NullOp()
472503

504+
if l.platformAPI.LessThan("0.7") {
505+
flags = append(flags,
506+
"-stack", l.mountPaths.stackPath(),
507+
"-run-image", runImage,
508+
)
509+
stackOpts = WithContainerOperations(WriteStackToml(l.mountPaths.stackPath(), l.opts.Builder.Stack(), l.os))
510+
}
473511
processType := determineDefaultProcessType(l.platformAPI, l.opts.DefaultProcessType)
474512
if processType != "" {
475513
flags = append(flags, "-process-type", processType)
@@ -500,7 +538,7 @@ func (l *LifecycleExecution) newExport(repoName, runImage string, publish bool,
500538
WithRoot(),
501539
WithNetwork(networkMode),
502540
cacheOpt,
503-
WithContainerOperations(WriteStackToml(l.mountPaths.stackPath(), l.opts.Builder.Stack(), l.os)),
541+
stackOpts,
504542
WithContainerOperations(WriteProjectMetadata(l.mountPaths.projectPath(), l.opts.ProjectMetadata, l.os)),
505543
}
506544

0 commit comments

Comments
 (0)