-
Notifications
You must be signed in to change notification settings - Fork 203
/
export_phase.go
75 lines (61 loc) · 1.59 KB
/
export_phase.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
package build
import (
"context"
"github.com/werf/logboek"
"github.com/werf/logboek/pkg/style"
"github.com/werf/logboek/pkg/types"
)
type ExportPhase struct {
BasePhase
ExportPhaseOptions
}
type ExportPhaseOptions struct {
ExportTagFuncList []func(string) string
}
func NewExportPhase(c *Conveyor, opts ExportPhaseOptions) *ExportPhase {
return &ExportPhase{
BasePhase: BasePhase{c},
ExportPhaseOptions: opts,
}
}
func (phase *ExportPhase) Name() string {
return "export"
}
func (phase *ExportPhase) AfterImageStages(ctx context.Context, img *Image) error {
if img.isArtifact {
return nil
}
if err := phase.exportLastStageImage(ctx, img); err != nil {
return err
}
return nil
}
func (phase *ExportPhase) exportLastStageImage(ctx context.Context, img *Image) error {
if len(phase.ExportTagFuncList) == 0 {
return nil
}
return logboek.Context(ctx).Default().LogProcess("Exporting image...").
Options(func(options types.LogProcessOptionsInterface) {
options.Style(style.Highlight())
}).
DoError(func() error {
for _, tagFunc := range phase.ExportTagFuncList {
tag := tagFunc(img.GetName())
if err := logboek.Context(ctx).Default().LogProcess("tag %s", tag).
DoError(func() error {
stageDesc := img.GetLastNonEmptyStage().GetImage().GetStageDescription()
if err := phase.Conveyor.StorageManager.GetStagesStorage().ExportStage(ctx, stageDesc, tag); err != nil {
return err
}
return nil
}); err != nil {
return err
}
}
return nil
})
}
func (phase *ExportPhase) Clone() Phase {
u := *phase
return &u
}