@@ -12,11 +12,11 @@ import (
12
12
13
13
"github.com/moby/buildkit/client/llb"
14
14
"github.com/opencontainers/go-digest"
15
- v1 "github.com/opencontainers/image-spec/specs-go/v1"
16
15
"github.com/siderolabs/gen/xslices"
17
16
18
17
"github.com/siderolabs/bldr/internal/pkg/constants"
19
18
"github.com/siderolabs/bldr/internal/pkg/environment"
19
+ "github.com/siderolabs/bldr/internal/pkg/platform"
20
20
"github.com/siderolabs/bldr/internal/pkg/solver"
21
21
"github.com/siderolabs/bldr/internal/pkg/types/v1alpha2"
22
22
)
@@ -55,17 +55,24 @@ func defaultCopyOptions(options *environment.Options, reproducible bool) *llb.Co
55
55
type NodeLLB struct {
56
56
* solver.PackageNode
57
57
58
- Graph * GraphLLB
59
- Prefix string
58
+ Graph * GraphLLB
59
+ Prefix string
60
+ Platform string
60
61
}
61
62
62
63
// NewNodeLLB wraps PackageNode for LLB conversion.
63
- func NewNodeLLB (node * solver.PackageNode , graph * GraphLLB ) * NodeLLB {
64
+ func NewNodeLLB (node * solver.PackageNode , graph * GraphLLB , platformOverride string ) * NodeLLB {
65
+ // set default platform if not set
66
+ if platformOverride == "" {
67
+ platformOverride = graph .Options .TargetPlatform .String ()
68
+ }
69
+
64
70
return & NodeLLB {
65
71
PackageNode : node ,
66
72
67
- Graph : graph ,
68
- Prefix : graph .Options .CommonPrefix + node .Name + ":" ,
73
+ Graph : graph ,
74
+ Prefix : graph .Options .CommonPrefix + node .Name + ":" ,
75
+ Platform : platformOverride ,
69
76
}
70
77
}
71
78
@@ -96,26 +103,9 @@ func (node *NodeLLB) context(root llb.State) llb.State {
96
103
)
97
104
}
98
105
99
- func (node * NodeLLB ) convertPlatform (platform string ) (v1.Platform , error ) {
100
- switch platform {
101
- case "linux/amd64" :
102
- return v1.Platform {
103
- OS : "linux" ,
104
- Architecture : "amd64" ,
105
- }, nil
106
- case "linux/arm64" :
107
- return v1.Platform {
108
- OS : "linux" ,
109
- Architecture : "arm64" ,
110
- }, nil
111
- default :
112
- return v1.Platform {}, fmt .Errorf ("unknown platform %q" , platform )
113
- }
114
- }
115
-
116
106
func (node * NodeLLB ) convertDependency (dep solver.PackageDependency ) (depState llb.State , srcName string , err error ) {
117
107
if dep .IsInternal () {
118
- depState , err = NewNodeLLB (dep .Node , node .Graph ).Build ()
108
+ depState , err = NewNodeLLB (dep .Node , node .Graph , node . Pkg . Platform ).Build ()
119
109
if err != nil {
120
110
return llb .Scratch (), "" , err
121
111
}
@@ -126,7 +116,7 @@ func (node *NodeLLB) convertDependency(dep solver.PackageDependency) (depState l
126
116
srcName = dep .Image
127
117
128
118
if dep .Platform != "" {
129
- platform , err := node . convertPlatform (dep .Platform )
119
+ platform , err := platform . ToV1Platform (dep .Platform , "" )
130
120
if err != nil {
131
121
return llb .Scratch (), "" , err
132
122
}
@@ -160,11 +150,18 @@ func (node *NodeLLB) dependencies(root llb.State) (llb.State, error) {
160
150
stages := []llb.State {root }
161
151
162
152
for _ , dep := range deps {
163
- if _ , alreadyProcessed := seen [dep .ID ()]; alreadyProcessed {
153
+ depID := dep .ID () + node .Platform
154
+
155
+ // set dep platform to node platform if not set
156
+ if dep .Platform == "" {
157
+ dep .Platform = node .Platform
158
+ }
159
+
160
+ if _ , alreadyProcessed := seen [depID ]; alreadyProcessed {
164
161
continue
165
162
}
166
163
167
- seen [dep . ID () ] = struct {}{}
164
+ seen [depID ] = struct {}{}
168
165
169
166
depState , srcName , err := node .convertDependency (dep )
170
167
if err != nil {
@@ -328,7 +325,12 @@ func (node *NodeLLB) finalize(root llb.State) llb.State {
328
325
329
326
// Build converts PackageNode to buildkit LLB.
330
327
func (node * NodeLLB ) Build () (llb.State , error ) {
331
- if state , ok := node .Graph .cache [node .PackageNode ]; ok {
328
+ cacheSt := cacheKey {
329
+ PackageNode : node .PackageNode ,
330
+ Platform : node .Platform ,
331
+ }
332
+
333
+ if state , ok := node .Graph .cache [cacheSt ]; ok {
332
334
return state , nil
333
335
}
334
336
@@ -348,7 +350,7 @@ func (node *NodeLLB) Build() (llb.State, error) {
348
350
349
351
root = node .finalize (root )
350
352
351
- node .Graph .cache [node . PackageNode ] = root
353
+ node .Graph .cache [cacheSt ] = root
352
354
353
355
return root , nil
354
356
}
0 commit comments