@@ -12,7 +12,6 @@ import (
12
12
13
13
"github.com/siderolabs/bldr/internal/pkg/constants"
14
14
"github.com/siderolabs/bldr/internal/pkg/environment"
15
- "github.com/siderolabs/bldr/internal/pkg/platform"
16
15
"github.com/siderolabs/bldr/internal/pkg/solver"
17
16
"github.com/siderolabs/bldr/internal/pkg/types/v1alpha2"
18
17
)
@@ -22,6 +21,7 @@ import (
22
21
// GraphLLB caches common images used in the build.
23
22
type GraphLLB struct {
24
23
* solver.PackageGraph
24
+ solverFn SolverFunc
25
25
26
26
Options * environment.Options
27
27
@@ -30,24 +30,20 @@ type GraphLLB struct {
30
30
LocalContext llb.State
31
31
32
32
baseImageProcessor llbProcessor
33
- cache map [cacheKey ]llb.State
33
+ cache map [* solver. PackageNode ]llb.State
34
34
35
35
commonRunOptions []llb.RunOption
36
36
}
37
37
38
- type cacheKey struct {
39
- * solver.PackageNode
40
- Platform string
41
- }
42
-
43
38
type llbProcessor func (llb.State ) llb.State
44
39
45
40
// NewGraphLLB creates new GraphLLB and initializes shared images.
46
- func NewGraphLLB (graph * solver.PackageGraph , options * environment.Options ) * GraphLLB {
41
+ func NewGraphLLB (graph * solver.PackageGraph , solverFn SolverFunc , options * environment.Options ) * GraphLLB {
47
42
result := & GraphLLB {
48
43
PackageGraph : graph ,
49
44
Options : options ,
50
- cache : make (map [cacheKey ]llb.State ),
45
+ solverFn : solverFn ,
46
+ cache : make (map [* solver.PackageNode ]llb.State ),
51
47
}
52
48
53
49
if options .ProxyEnv != nil {
@@ -92,12 +88,9 @@ func (graph *GraphLLB) buildBaseImages() {
92
88
return addEnv (addPkg (root ))
93
89
}
94
90
95
- platform , _ := platform .ToV1Platform (graph .Root .Pkg .Platform , graph .Options .TargetPlatform .String ()) //nolint:errcheck
96
-
97
91
graph .BaseImages [v1alpha2 .Alpine ] = graph .baseImageProcessor (llb .Image (
98
92
constants .DefaultBaseImage ,
99
93
llb .WithCustomName (graph .Options .CommonPrefix + "base" ),
100
- llb .Platform (platform ),
101
94
).Run (
102
95
append (graph .commonRunOptions ,
103
96
llb .Shlex ("apk --no-cache --update add bash" ),
@@ -114,12 +107,9 @@ func (graph *GraphLLB) buildBaseImages() {
114
107
}
115
108
116
109
func (graph * GraphLLB ) buildChecksummer () {
117
- platform , _ := platform .ToV1Platform (graph .Root .Pkg .Platform , graph .Options .TargetPlatform .String ()) //nolint:errcheck
118
-
119
110
graph .Checksummer = llb .Image (
120
111
constants .DefaultBaseImage ,
121
112
llb .WithCustomName (graph .Options .CommonPrefix + "cksum" ),
122
- llb .Platform (platform ),
123
113
).Run (
124
114
append (graph .commonRunOptions ,
125
115
llb .Shlex ("apk --no-cache --update add coreutils" ),
@@ -143,18 +133,18 @@ func (graph *GraphLLB) buildLocalContext() {
143
133
}
144
134
145
135
// Build converts package graph to LLB.
146
- func (graph * GraphLLB ) Build () (llb.State , error ) {
147
- return NewNodeLLB (graph .Root , graph , graph . Root . Pkg . Platform ).Build ()
136
+ func (graph * GraphLLB ) Build (ctx context. Context ) (llb.State , error ) {
137
+ return NewNodeLLB (graph .Root , graph ).Build (ctx )
148
138
}
149
139
150
140
// Marshal returns marshaled LLB.
151
- func (graph * GraphLLB ) Marshal () (* llb.Definition , error ) {
152
- out , err := graph .Build ()
141
+ func (graph * GraphLLB ) Marshal (ctx context. Context ) (* llb.Definition , error ) {
142
+ out , err := graph .Build (ctx )
153
143
if err != nil {
154
144
return nil , err
155
145
}
156
146
157
147
out = out .SetMarshalDefaults (graph .Options .BuildPlatform .LLBPlatform )
158
148
159
- return out .Marshal (context . TODO () )
149
+ return out .Marshal (ctx )
160
150
}
0 commit comments