Skip to content

Commit 40aea38

Browse files
smirafrezbo
authored andcommitted
feat: support per-dependency arch
For internal stages. Signed-off-by: Andrey Smirnov <[email protected]> Signed-off-by: Noel Georgi <[email protected]>
1 parent 65e6a18 commit 40aea38

File tree

21 files changed

+186
-475
lines changed

21 files changed

+186
-475
lines changed

README.md

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -227,8 +227,6 @@ Additionally, hermetic text functions from [Sprig](http://masterminds.github.io/
227227
On the root level, following properties are available:
228228

229229
- `name` (*str*, *required*): name of the package, also used to reference this package from other packages as dependency.
230-
- `platform` (*str*, *optional*): platform override for the build.
231-
If not set, defaults to the platform of the build.
232230
- `variant` (*str*, *optional*): variant of the base image of the build.
233231
Two variants are available:
234232
- `alpine`: Alpine Linux 3.16 image with `bash` package pre-installed
@@ -272,7 +270,7 @@ Properties:
272270
Contents of the stage are poured into the build at the location specified with `to:` parameter.
273271
- `image` (*str*, *external dependency*): reference to the registry container image this package depends on.
274272
Contents of the image are poured into the build at the location specified with `to:` parameter.
275-
- `platform` (*str*, *optional*): platform to pull the image for.
273+
- `platform` (*str*, *optional*): platform to override for the `image` or `stage`.
276274
If not set, defaults to the platform of the build.
277275
- `runtime` (*bool*, *optional*): if set, marks dependency as runtime.
278276
This means that when this package is pulled in into the build, all the runtime dependencies are pulled in automatically as well.

cmd/bldr/cmd/llb.go

Lines changed: 0 additions & 99 deletions
This file was deleted.

go.mod

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@ go 1.21.0
55
require (
66
github.com/Masterminds/semver v1.5.0
77
github.com/Masterminds/sprig/v3 v3.2.3
8-
github.com/alessio/shellescape v1.4.2
98
github.com/containerd/containerd v1.7.13
109
github.com/emicklei/dot v1.6.1
1110
github.com/google/go-github/v60 v60.0.0

go.sum

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,6 @@ github.com/Microsoft/go-winio v0.6.1 h1:9/kr64B9VUZrLm5YYwbGtUJnMgqWVOdUAXu6Migc
1010
github.com/Microsoft/go-winio v0.6.1/go.mod h1:LRdKpFKfdobln8UmuiYcKPot9D2v6svN5+sAH+4kjUM=
1111
github.com/Microsoft/hcsshim v0.11.4 h1:68vKo2VN8DE9AdN4tnkWnmdhqdbpUFM8OF3Airm7fz8=
1212
github.com/Microsoft/hcsshim v0.11.4/go.mod h1:smjE4dvqPX9Zldna+t5FG3rnoHhaB7QYxPRqGcpAD9w=
13-
github.com/alessio/shellescape v1.4.2 h1:MHPfaU+ddJ0/bYWpgIeUnQUqKrlJ1S7BfEYPM4uEoM0=
14-
github.com/alessio/shellescape v1.4.2/go.mod h1:PZAiSCk0LJaZkiCSkPv8qIobYglO3FPpyFjDCtHLS30=
1513
github.com/containerd/containerd v1.7.13 h1:wPYKIeGMN8vaggSKuV1X0wZulpMz4CrgEsZdaCyB6Is=
1614
github.com/containerd/containerd v1.7.13/go.mod h1:zT3up6yTRfEUa6+GsITYIJNgSVL9NQ4x4h1RPzk0Wu4=
1715
github.com/containerd/continuity v0.4.2 h1:v3y/4Yz5jwnvqPKJJ+7Wf93fyWoCB3F5EclWG023MDM=

internal/pkg/convert/graph.go

Lines changed: 10 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,6 @@ import (
1212

1313
"github.com/siderolabs/bldr/internal/pkg/constants"
1414
"github.com/siderolabs/bldr/internal/pkg/environment"
15-
"github.com/siderolabs/bldr/internal/pkg/platform"
1615
"github.com/siderolabs/bldr/internal/pkg/solver"
1716
"github.com/siderolabs/bldr/internal/pkg/types/v1alpha2"
1817
)
@@ -22,6 +21,7 @@ import (
2221
// GraphLLB caches common images used in the build.
2322
type GraphLLB struct {
2423
*solver.PackageGraph
24+
solverFn SolverFunc
2525

2626
Options *environment.Options
2727

@@ -30,24 +30,20 @@ type GraphLLB struct {
3030
LocalContext llb.State
3131

3232
baseImageProcessor llbProcessor
33-
cache map[cacheKey]llb.State
33+
cache map[*solver.PackageNode]llb.State
3434

3535
commonRunOptions []llb.RunOption
3636
}
3737

38-
type cacheKey struct {
39-
*solver.PackageNode
40-
Platform string
41-
}
42-
4338
type llbProcessor func(llb.State) llb.State
4439

4540
// 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 {
4742
result := &GraphLLB{
4843
PackageGraph: graph,
4944
Options: options,
50-
cache: make(map[cacheKey]llb.State),
45+
solverFn: solverFn,
46+
cache: make(map[*solver.PackageNode]llb.State),
5147
}
5248

5349
if options.ProxyEnv != nil {
@@ -92,12 +88,9 @@ func (graph *GraphLLB) buildBaseImages() {
9288
return addEnv(addPkg(root))
9389
}
9490

95-
platform, _ := platform.ToV1Platform(graph.Root.Pkg.Platform, graph.Options.TargetPlatform.String()) //nolint:errcheck
96-
9791
graph.BaseImages[v1alpha2.Alpine] = graph.baseImageProcessor(llb.Image(
9892
constants.DefaultBaseImage,
9993
llb.WithCustomName(graph.Options.CommonPrefix+"base"),
100-
llb.Platform(platform),
10194
).Run(
10295
append(graph.commonRunOptions,
10396
llb.Shlex("apk --no-cache --update add bash"),
@@ -114,12 +107,9 @@ func (graph *GraphLLB) buildBaseImages() {
114107
}
115108

116109
func (graph *GraphLLB) buildChecksummer() {
117-
platform, _ := platform.ToV1Platform(graph.Root.Pkg.Platform, graph.Options.TargetPlatform.String()) //nolint:errcheck
118-
119110
graph.Checksummer = llb.Image(
120111
constants.DefaultBaseImage,
121112
llb.WithCustomName(graph.Options.CommonPrefix+"cksum"),
122-
llb.Platform(platform),
123113
).Run(
124114
append(graph.commonRunOptions,
125115
llb.Shlex("apk --no-cache --update add coreutils"),
@@ -143,18 +133,18 @@ func (graph *GraphLLB) buildLocalContext() {
143133
}
144134

145135
// 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)
148138
}
149139

150140
// 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)
153143
if err != nil {
154144
return nil, err
155145
}
156146

157147
out = out.SetMarshalDefaults(graph.Options.BuildPlatform.LLBPlatform)
158148

159-
return out.Marshal(context.TODO())
149+
return out.Marshal(ctx)
160150
}

internal/pkg/convert/llb.go

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -5,18 +5,19 @@
55
package convert
66

77
import (
8+
"context"
9+
810
"github.com/moby/buildkit/client/llb"
11+
"github.com/moby/buildkit/frontend/gateway/client"
912

1013
"github.com/siderolabs/bldr/internal/pkg/environment"
1114
"github.com/siderolabs/bldr/internal/pkg/solver"
1215
)
1316

14-
// BuildLLB translates package graph into LLB DAG.
15-
func BuildLLB(graph *solver.PackageGraph, options *environment.Options) (llb.State, error) {
16-
return NewGraphLLB(graph, options).Build()
17-
}
17+
// SolverFunc can be called to solve the package into the llb state via buildkit.
18+
type SolverFunc func(ctx context.Context, platform environment.Platform, target string) (*client.Result, error)
1819

1920
// MarshalLLB translates package graph into LLB DAG and marshals it.
20-
func MarshalLLB(graph *solver.PackageGraph, options *environment.Options) (*llb.Definition, error) {
21-
return NewGraphLLB(graph, options).Marshal()
21+
func MarshalLLB(ctx context.Context, graph *solver.PackageGraph, solver SolverFunc, options *environment.Options) (*llb.Definition, error) {
22+
return NewGraphLLB(graph, solver, options).Marshal(ctx)
2223
}

0 commit comments

Comments
 (0)