/
stage_builder.go
123 lines (100 loc) · 3.95 KB
/
stage_builder.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
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
package builder
import (
"context"
"github.com/werf/werf/pkg/container_runtime"
)
type StageBuilderAccessorInterface interface {
StapelStageBuilder() StapelStageBuilderInterface
NativeDockerfileStageBuilder() NativeDockerfileStageBuilderInterface
LegacyStapelStageBuilder() LegacyStapelStageBuilderInterface
}
type StageBuilderAccessor struct {
ContainerRuntime container_runtime.ContainerRuntime
Image container_runtime.LegacyImageInterface
DockerfileImageBuilder *container_runtime.DockerfileImageBuilder
}
func NewStageBuilderAccessor(containerRuntime container_runtime.ContainerRuntime, image container_runtime.LegacyImageInterface) *StageBuilderAccessor {
return &StageBuilderAccessor{
ContainerRuntime: containerRuntime,
Image: image,
}
}
func (accessor *StageBuilderAccessor) StapelStageBuilder() StapelStageBuilderInterface {
return NewStapelStageBuilder()
}
func (accessor *StageBuilderAccessor) LegacyStapelStageBuilder() LegacyStapelStageBuilderInterface {
return NewLegacyStapelStageBuilder(accessor.ContainerRuntime, accessor.Image)
}
func (accessor *StageBuilderAccessor) NativeDockerfileStageBuilder() NativeDockerfileStageBuilderInterface {
if accessor.DockerfileImageBuilder == nil {
accessor.DockerfileImageBuilder = container_runtime.NewDockerfileImageBuilder(accessor.ContainerRuntime, accessor.Image)
}
return accessor.DockerfileImageBuilder
}
type StapelStageBuilderInterface interface {
AppendPrepareContainerAction(action PrepareContainerAction) StapelStageBuilderInterface
AddLabels(map[string]string) StapelStageBuilderInterface
AddContainerVolumes(volumes ...string) StapelStageBuilderInterface
}
type PrepareContainerAction interface {
PrepareContainer(containerRoot string) error
}
type stapelStageBuilder struct {
ContainerRuntime container_runtime.ContainerRuntime
labels map[string]string
volumes []string
}
func NewStapelStageBuilder() *stapelStageBuilder {
return &stapelStageBuilder{}
}
func (builder *stapelStageBuilder) AddLabels(labels map[string]string) StapelStageBuilderInterface {
for k, v := range labels {
builder.labels[k] = v
}
return builder
}
func (builder *stapelStageBuilder) AddContainerVolumes(volumes ...string) StapelStageBuilderInterface {
builder.volumes = append(builder.volumes, volumes...)
return builder
}
func (builder *stapelStageBuilder) AppendPrepareContainerAction(action PrepareContainerAction) StapelStageBuilderInterface {
panic("FIXME")
return builder
}
type NativeDockerfileStageBuilderInterface interface {
Build(ctx context.Context) error
Cleanup(ctx context.Context) error
SetDockerfile(dockerfile []byte)
SetDockerfileCtxRelPath(dockerfileCtxRelPath string)
SetTarget(target string)
AppendBuildArgs(args ...string)
AppendAddHost(addHost ...string)
SetNetwork(network string)
SetSSH(ssh string)
AppendLabels(labels ...string)
SetContextArchivePath(contextArchivePath string)
}
type LegacyStapelStageBuilderInterface interface {
Container() container_runtime.LegacyContainer
BuilderContainer() container_runtime.LegacyBuilderContainer
Build(ctx context.Context, opts container_runtime.LegacyBuildOptions) error
}
type legacyStapelStageBuilder struct {
ContainerRuntime container_runtime.ContainerRuntime
Image container_runtime.LegacyImageInterface
}
func NewLegacyStapelStageBuilder(containerRuntime container_runtime.ContainerRuntime, image container_runtime.LegacyImageInterface) *legacyStapelStageBuilder {
return &legacyStapelStageBuilder{
ContainerRuntime: containerRuntime,
Image: image,
}
}
func (builder *legacyStapelStageBuilder) Container() container_runtime.LegacyContainer {
return builder.Image.Container()
}
func (builder *legacyStapelStageBuilder) BuilderContainer() container_runtime.LegacyBuilderContainer {
return builder.Image.BuilderContainer()
}
func (builder *legacyStapelStageBuilder) Build(ctx context.Context, opts container_runtime.LegacyBuildOptions) error {
return builder.Image.Build(ctx, opts)
}