Skip to content

Commit c321f8e

Browse files
committed
Use fallback for pre-v0.19 buildkit
Earlier buildkits will not support llb symlinks, so fall back to the old implementation. Signed-off-by: Peter Engelbert <[email protected]>
1 parent 08d2e6c commit c321f8e

File tree

7 files changed

+90
-51
lines changed

7 files changed

+90
-51
lines changed

frontend/azlinux/handle_container.go

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -76,9 +76,7 @@ func specToContainerLLB(w worker, spec *dalec.Spec, targetKey string, rpmDir llb
7676
).AddMount(workPath, rootfs)
7777

7878
if post := spec.GetImagePost(targetKey); post != nil && len(post.Symlinks) > 0 {
79-
rootfs = builderImg.
80-
Run(dalec.WithConstraints(opts...), dalec.InstallPostSymlinks(post, workPath)).
81-
AddMount(workPath, rootfs)
79+
rootfs = rootfs.With(dalec.InstallPostSymlinks(builderImg, post, workPath, opts...))
8280
}
8381

8482
return rootfs, nil

frontend/deb/distro/container.go

Lines changed: 3 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,8 @@ func (c *Config) BuildContainer(worker llb.State, sOpt dalec.SourceOpts, client
3636
debug := llb.Scratch().File(llb.Mkfile("debug", 0o644, []byte(`debug=2`)), opts...)
3737
opts = append(opts, dalec.ProgressGroup("Install spec package"))
3838

39+
const workpath = "/tmp/rootfs"
40+
3941
return baseImg.Run(
4042
dalec.WithConstraints(opts...),
4143
withRepos,
@@ -54,25 +56,7 @@ func (c *Config) BuildContainer(worker llb.State, sOpt dalec.SourceOpts, client
5456
}),
5557
InstallLocalPkg(debSt, opts...),
5658
).Root().
57-
With(c.createSymlinks(worker, spec, targetKey, opts...)), nil
58-
}
59-
60-
func (c *Config) createSymlinks(worker llb.State, spec *dalec.Spec, targetKey string, opts ...llb.ConstraintsOpt) llb.StateOption {
61-
return func(in llb.State) llb.State {
62-
post := spec.GetImagePost(targetKey)
63-
if post == nil {
64-
return in
65-
}
66-
67-
if len(post.Symlinks) == 0 {
68-
return in
69-
}
70-
71-
const workPath = "/tmp/rootfs"
72-
return worker.
73-
Run(dalec.WithConstraints(opts...), dalec.InstallPostSymlinks(post, workPath)).
74-
AddMount(workPath, in)
75-
}
59+
With(dalec.InstallPostSymlinks(baseImg, spec.GetImagePost(targetKey), workpath, opts...)), nil
7660
}
7761

7862
func (c *Config) HandleContainer(ctx context.Context, client gwclient.Client) (*gwclient.Result, error) {

frontend/gateway.go

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -131,6 +131,9 @@ func SourceOptFromClient(ctx context.Context, c gwclient.Client) (dalec.SourceOp
131131
var (
132132
supportsDiffMergeOnce sync.Once
133133
supportsDiffMerge atomic.Bool
134+
135+
supportsSymlinksOnce sync.Once
136+
supportsSymlinks atomic.Bool
134137
)
135138

136139
// SupportsDiffMerge checks if the given client supports the diff and merge operations.
@@ -145,6 +148,14 @@ func SupportsDiffMerge(client gwclient.Client) bool {
145148
return supportsDiffMerge.Load()
146149
}
147150

151+
// SupportsSymlinks checks if the given client supports the diff and merge operations.
152+
func SupportsSymlinks(client gwclient.Client) bool {
153+
supportsSymlinksOnce.Do(func() {
154+
supportsSymlinks.Store(checkSymlinks(client))
155+
})
156+
return supportsSymlinks.Load()
157+
}
158+
148159
func checkDiffMerge(client gwclient.Client) bool {
149160
caps := client.BuildOpts().LLBCaps
150161
if caps.Supports(pb.CapMergeOp) != nil {
@@ -157,6 +168,15 @@ func checkDiffMerge(client gwclient.Client) bool {
157168
return true
158169
}
159170

171+
func checkSymlinks(client gwclient.Client) bool {
172+
caps := client.BuildOpts().LLBCaps
173+
if err := caps.Supports(pb.CapFileSymlinkCreate); err != nil {
174+
return false
175+
}
176+
177+
return true
178+
}
179+
160180
// copyForForward copies all the inputs and build opts from the initial request in order to forward to another frontend.
161181
func copyForForward(ctx context.Context, client gwclient.Client) solveRequestOpt {
162182
return func(req *gwclient.SolveRequest) error {

frontend/mux.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -540,6 +540,9 @@ func (m *BuildMux) Handler(opts ...func(context.Context, gwclient.Client, *Build
540540
if !SupportsDiffMerge(client) {
541541
dalec.DisableDiffMerge(true)
542542
}
543+
if !SupportsSymlinks(client) {
544+
dalec.DisableSymlinks(true)
545+
}
543546
for _, opt := range opts {
544547
if err := opt(ctx, client, m); err != nil {
545548
return nil, err

go.mod

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ require (
1010
github.com/google/go-cmp v0.6.0
1111
github.com/google/shlex v0.0.0-20191202100458-e7afc7fbc510
1212
github.com/invopop/jsonschema v0.12.0
13-
github.com/moby/buildkit v0.18.2
13+
github.com/moby/buildkit v0.18.1-0.20250107231614-4c6878571c4e
1414
github.com/moby/docker-image-spec v1.3.1
1515
github.com/opencontainers/go-digest v1.0.0
1616
github.com/opencontainers/image-spec v1.1.0
@@ -66,15 +66,16 @@ require (
6666
github.com/pmezard/go-difflib v1.0.0 // indirect
6767
github.com/secure-systems-lab/go-securesystemslib v0.4.0 // indirect
6868
github.com/shibumi/go-pathspec v1.3.0 // indirect
69+
github.com/tonistiigi/dchapes-mode v0.0.0-20241001053921-ca0759fec205 // indirect
6970
github.com/tonistiigi/go-csvvalue v0.0.0-20240710180619-ddb21b71c0b4 // indirect
7071
github.com/tonistiigi/units v0.0.0-20180711220420-6950e57a87ea // indirect
7172
github.com/tonistiigi/vt100 v0.0.0-20240514184818-90bafcd6abab // indirect
7273
github.com/wk8/go-ordered-map/v2 v2.1.8 // indirect
73-
go.opentelemetry.io/contrib/instrumentation/google.golang.org/grpc/otelgrpc v0.46.1 // indirect
74-
go.opentelemetry.io/contrib/instrumentation/net/http/httptrace/otelhttptrace v0.46.1 // indirect
74+
go.opentelemetry.io/contrib/instrumentation/google.golang.org/grpc/otelgrpc v0.53.0 // indirect
75+
go.opentelemetry.io/contrib/instrumentation/net/http/httptrace/otelhttptrace v0.53.0 // indirect
7576
go.opentelemetry.io/contrib/instrumentation/net/http/otelhttp v0.53.0 // indirect
76-
go.opentelemetry.io/otel/exporters/otlp/otlpmetric/otlpmetricgrpc v0.44.0 // indirect
77-
go.opentelemetry.io/otel/exporters/otlp/otlpmetric/otlpmetrichttp v0.44.0 // indirect
77+
go.opentelemetry.io/otel/exporters/otlp/otlpmetric/otlpmetricgrpc v1.28.0 // indirect
78+
go.opentelemetry.io/otel/exporters/otlp/otlpmetric/otlpmetrichttp v1.28.0 // indirect
7879
go.opentelemetry.io/otel/exporters/otlp/otlptrace v1.28.0 // indirect
7980
go.opentelemetry.io/otel/exporters/otlp/otlptrace/otlptracegrpc v1.28.0 // indirect
8081
go.opentelemetry.io/otel/exporters/otlp/otlptrace/otlptracehttp v1.28.0 // indirect

go.sum

Lines changed: 14 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,3 @@
1-
cloud.google.com/go v0.112.0 h1:tpFCD7hpHFlQ8yPwT3x+QeXqc2T6+n6T+hmABHfDUSM=
2-
cloud.google.com/go/compute v1.23.3 h1:6sVlXXBmbd7jNX0Ipq0trII3e4n1/MsADLK6a+aiVlk=
3-
cloud.google.com/go/compute/metadata v0.3.0 h1:Tz+eQXMEqDIKRsmY3cHTL6FVaynIjX2QxYC4trgAKZc=
4-
cloud.google.com/go/compute/metadata v0.3.0/go.mod h1:zFmK7XCadkQkj6TtorcaGlCW1hT1fIilQDwofLpJ20k=
51
github.com/AdaLogics/go-fuzz-headers v0.0.0-20230811130428-ced1acdcaa24 h1:bvDV9vkmnHYOMsOr4WLk+Vo07yKIzd94sVoIqshQ4bU=
62
github.com/AdaLogics/go-fuzz-headers v0.0.0-20230811130428-ced1acdcaa24/go.mod h1:8o94RPi1/7XTJvwPpRSzSUedZrtlirdB3r9Z20bi2f8=
73
github.com/AdamKorcz/go-118-fuzz-build v0.0.0-20230306123547-8075edf89bb0 h1:59MxjQVfjXsBpLy+dbd2/ELV5ofnUkUZBvWSC85sheA=
@@ -20,8 +16,6 @@ github.com/buger/jsonparser v1.1.1 h1:2PnMjfWD7wBILjqQbt530v576A/cAbQvEW9gGIpYMU
2016
github.com/buger/jsonparser v1.1.1/go.mod h1:6RYKKt7H4d4+iWqouImQ9R2FZql3VbhNgx27UK13J/0=
2117
github.com/cenkalti/backoff/v4 v4.3.0 h1:MyRJ/UdXutAwSAT+s3wNd7MfTIcy71VQueUuFK343L8=
2218
github.com/cenkalti/backoff/v4 v4.3.0/go.mod h1:Y3VNntkOUPxTVeUxJ/G5vcM//AlwfmyYozVcomhLiZE=
23-
github.com/cncf/xds/go v0.0.0-20240423153145-555b57ec207b h1:ga8SEFjZ60pxLcmhnThWgvH2wg8376yUJmPhEH4H3kw=
24-
github.com/cncf/xds/go v0.0.0-20240423153145-555b57ec207b/go.mod h1:W+zGtBO5Y1IgJhy4+A9GOqVhqLpfZi+vwmdNXUehLA8=
2519
github.com/codahale/rfc6979 v0.0.0-20141003034818-6a90f24967eb h1:EDmT6Q9Zs+SbUoc7Ik9EfrFqcylYqgPZ9ANSbTAntnE=
2620
github.com/codahale/rfc6979 v0.0.0-20141003034818-6a90f24967eb/go.mod h1:ZjrT6AXHbDs86ZSdt/osfBi5qfexBrKUdONk989Wnk4=
2721
github.com/containerd/cgroups v1.1.0 h1:v8rEWFl6EoqHB+swVNjVoCJE8o3jX7e8nqBGPLaDFBM=
@@ -57,16 +51,14 @@ github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c
5751
github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
5852
github.com/distribution/reference v0.6.0 h1:0IXCQ5g4/QMHHkarYzh5l+u8T3t73zM5QvfrDyIgxBk=
5953
github.com/distribution/reference v0.6.0/go.mod h1:BbU0aIcezP1/5jX/8MP0YiH4SdvB5Y4f/wlDRiLyi3E=
60-
github.com/docker/docker v27.4.0-rc.2+incompatible h1:9OJjVGtelk/zGC3TyKweJ29b9Axzh0s/0vtU4mneumE=
61-
github.com/docker/docker v27.4.0-rc.2+incompatible/go.mod h1:eEKB0N0r5NX/I1kEveEz05bcu8tLC/8azJZsviup8Sk=
54+
github.com/docker/docker v27.4.1+incompatible h1:ZJvcY7gfwHn1JF48PfbyXg7Jyt9ZCWDW+GGXOIxEwp4=
55+
github.com/docker/docker v27.4.1+incompatible/go.mod h1:eEKB0N0r5NX/I1kEveEz05bcu8tLC/8azJZsviup8Sk=
6256
github.com/docker/go-connections v0.5.0 h1:USnMq7hx7gwdVZq1L49hLXaFtUdTADjXGp+uj1Br63c=
6357
github.com/docker/go-connections v0.5.0/go.mod h1:ov60Kzw0kKElRwhNs9UlUHAE/F9Fe6GLaXnqyDdmEXc=
6458
github.com/docker/go-events v0.0.0-20190806004212-e31b211e4f1c h1:+pKlWGMw7gf6bQ+oDZB4KHQFypsfjYlq/C4rfL7D3g8=
6559
github.com/docker/go-events v0.0.0-20190806004212-e31b211e4f1c/go.mod h1:Uw6UezgYA44ePAFQYUehOuCzmy5zmg/+nl2ZfMWGkpA=
6660
github.com/docker/go-units v0.5.0 h1:69rxXcBk27SvSaaxTtLh/8llcHD8vYHT7WSdRZ/jvr4=
6761
github.com/docker/go-units v0.5.0/go.mod h1:fgPhTUdO+D/Jk86RDLlptpiXQzgHJF7gydDDbaIK4Dk=
68-
github.com/envoyproxy/protoc-gen-validate v1.0.4 h1:gVPz/FMfvh57HdSJQyvBtF00j8JU4zdyUgIUNhlgg0A=
69-
github.com/envoyproxy/protoc-gen-validate v1.0.4/go.mod h1:qys6tmnRsYrQqIhm2bvKZH4Blx/1gTIZ2UKVY1M+Yew=
7062
github.com/felixge/httpsnoop v1.0.4 h1:NFTV2Zj1bL4mc9sqWACXbQFVBBg2W3GPvqp8/ESS2Wg=
7163
github.com/felixge/httpsnoop v1.0.4/go.mod h1:m8KPJKqk1gH5J9DgRY2ASl2lWCfGKXixSwevea8zH2U=
7264
github.com/go-logr/logr v1.2.2/go.mod h1:jdQByPbusPIv2/zmleS9BjJVeZ6kBagPoEUsqbVz/1A=
@@ -112,8 +104,8 @@ github.com/kr/text v0.2.0 h1:5Nx0Ya0ZqY2ygV366QzturHI13Jq95ApcVaJBhpS+AY=
112104
github.com/kr/text v0.2.0/go.mod h1:eLer722TekiGuMkidMxC/pM04lWEeraHUUmBw8l2grE=
113105
github.com/mailru/easyjson v0.7.7 h1:UGYAvKxe3sBsEDzO8ZeWOSlIQfWFlxbzLZe7hwFURr0=
114106
github.com/mailru/easyjson v0.7.7/go.mod h1:xzfreul335JAWq5oZzymOObrkdz5UnU4kGfJJLY9Nlc=
115-
github.com/moby/buildkit v0.18.2 h1:l86uBvxh4ntNoUUg3Y0eGTbKg1PbUh6tawJ4Xt75SpQ=
116-
github.com/moby/buildkit v0.18.2/go.mod h1:vCR5CX8NGsPTthTg681+9kdmfvkvqJBXEv71GZe5msU=
107+
github.com/moby/buildkit v0.18.1-0.20250107231614-4c6878571c4e h1:R15mpvqMMPljJiAboePG5MKC3wWIAfQSg/VKDSgA7Q8=
108+
github.com/moby/buildkit v0.18.1-0.20250107231614-4c6878571c4e/go.mod h1:WcWFLJnPbuEKMBia00EKfM8rTsordZG7V2h6/GUtJJg=
117109
github.com/moby/docker-image-spec v1.3.1 h1:jMKff3w6PgbfSa69GfNg+zN/XLhfXJGnEx3Nl2EsFP0=
118110
github.com/moby/docker-image-spec v1.3.1/go.mod h1:eKmb5VW8vQEh/BAr2yvVNvuiJuY6UIocYsFu/DxxRpo=
119111
github.com/moby/locker v1.0.1 h1:fOXqR41zeveg4fFODix+1Ch4mj/gT0NE1XJbp/epuBg=
@@ -165,6 +157,8 @@ github.com/stretchr/testify v1.3.0/go.mod h1:M5WIy9Dh21IEIfnGCwXGc5bZfKNJtfHm1UV
165157
github.com/stretchr/testify v1.7.0/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg=
166158
github.com/stretchr/testify v1.9.0 h1:HtqpIVDClZ4nwg75+f6Lvsy/wHu+3BoSGCbBAcpTsTg=
167159
github.com/stretchr/testify v1.9.0/go.mod h1:r2ic/lqez/lEtzL7wO/rwa5dbSLXVDPFyf8C91i36aY=
160+
github.com/tonistiigi/dchapes-mode v0.0.0-20241001053921-ca0759fec205 h1:eUk79E1w8yMtXeHSzjKorxuC8qJOnyXQnLaJehxpJaI=
161+
github.com/tonistiigi/dchapes-mode v0.0.0-20241001053921-ca0759fec205/go.mod h1:3Iuxbr0P7D3zUzBMAZB+ois3h/et0shEz0qApgHYGpY=
168162
github.com/tonistiigi/fsutil v0.0.0-20241121093142-31cf1f437184 h1:RgyoSI38Y36zjQaszel/0RAcIehAnjA1B0RiUV9SDO4=
169163
github.com/tonistiigi/fsutil v0.0.0-20241121093142-31cf1f437184/go.mod h1:Dl/9oEjK7IqnjAm21Okx/XIxUCFJzvh+XdVHUlBwXTw=
170164
github.com/tonistiigi/go-csvvalue v0.0.0-20240710180619-ddb21b71c0b4 h1:7I5c2Ig/5FgqkYOh/N87NzoyI9U15qUPXhDD8uCupv8=
@@ -181,18 +175,18 @@ github.com/yuin/goldmark v1.1.27/go.mod h1:3hX8gzYuyVAZsxl0MRgGTJEmQBFcNTphYh9de
181175
github.com/yuin/goldmark v1.2.1/go.mod h1:3hX8gzYuyVAZsxl0MRgGTJEmQBFcNTphYh9decYSb74=
182176
go.opencensus.io v0.24.0 h1:y73uSU6J157QMP2kn2r30vwW1A2W2WFwSCGnAVxeaD0=
183177
go.opencensus.io v0.24.0/go.mod h1:vNK8G9p7aAivkbmorf4v+7Hgx+Zs0yY+0fOtgBfjQKo=
184-
go.opentelemetry.io/contrib/instrumentation/google.golang.org/grpc/otelgrpc v0.46.1 h1:SpGay3w+nEwMpfVnbqOLH5gY52/foP8RE8UzTZ1pdSE=
185-
go.opentelemetry.io/contrib/instrumentation/google.golang.org/grpc/otelgrpc v0.46.1/go.mod h1:4UoMYEZOC0yN/sPGH76KPkkU7zgiEWYWL9vwmbnTJPE=
186-
go.opentelemetry.io/contrib/instrumentation/net/http/httptrace/otelhttptrace v0.46.1 h1:gbhw/u49SS3gkPWiYweQNJGm/uJN5GkI/FrosxSHT7A=
187-
go.opentelemetry.io/contrib/instrumentation/net/http/httptrace/otelhttptrace v0.46.1/go.mod h1:GnOaBaFQ2we3b9AGWJpsBa7v1S5RlQzlC3O7dRMxZhM=
178+
go.opentelemetry.io/contrib/instrumentation/google.golang.org/grpc/otelgrpc v0.53.0 h1:9G6E0TXzGFVfTnawRzrPl83iHOAV7L8NJiR8RSGYV1g=
179+
go.opentelemetry.io/contrib/instrumentation/google.golang.org/grpc/otelgrpc v0.53.0/go.mod h1:azvtTADFQJA8mX80jIH/akaE7h+dbm/sVuaHqN13w74=
180+
go.opentelemetry.io/contrib/instrumentation/net/http/httptrace/otelhttptrace v0.53.0 h1:IVtyPth4Rs5P8wIf0mP2KVKFNTJ4paX9qQ4Hkh5gFdc=
181+
go.opentelemetry.io/contrib/instrumentation/net/http/httptrace/otelhttptrace v0.53.0/go.mod h1:ImRBLMJv177/pwiLZ7tU7HDGNdBv7rS0HQ99eN/zBl8=
188182
go.opentelemetry.io/contrib/instrumentation/net/http/otelhttp v0.53.0 h1:4K4tsIXefpVJtvA/8srF4V4y0akAoPHkIslgAkjixJA=
189183
go.opentelemetry.io/contrib/instrumentation/net/http/otelhttp v0.53.0/go.mod h1:jjdQuTGVsXV4vSs+CJ2qYDeDPf9yIJV23qlIzBm73Vg=
190184
go.opentelemetry.io/otel v1.28.0 h1:/SqNcYk+idO0CxKEUOtKQClMK/MimZihKYMruSMViUo=
191185
go.opentelemetry.io/otel v1.28.0/go.mod h1:q68ijF8Fc8CnMHKyzqL6akLO46ePnjkgfIMIjUIX9z4=
192-
go.opentelemetry.io/otel/exporters/otlp/otlpmetric/otlpmetricgrpc v0.44.0 h1:jd0+5t/YynESZqsSyPz+7PAFdEop0dlN0+PkyHYo8oI=
193-
go.opentelemetry.io/otel/exporters/otlp/otlpmetric/otlpmetricgrpc v0.44.0/go.mod h1:U707O40ee1FpQGyhvqnzmCJm1Wh6OX6GGBVn0E6Uyyk=
194-
go.opentelemetry.io/otel/exporters/otlp/otlpmetric/otlpmetrichttp v0.44.0 h1:bflGWrfYyuulcdxf14V6n9+CoQcu5SAAdHmDPAJnlps=
195-
go.opentelemetry.io/otel/exporters/otlp/otlpmetric/otlpmetrichttp v0.44.0/go.mod h1:qcTO4xHAxZLaLxPd60TdE88rxtItPHgHWqOhOGRr0as=
186+
go.opentelemetry.io/otel/exporters/otlp/otlpmetric/otlpmetricgrpc v1.28.0 h1:U2guen0GhqH8o/G2un8f/aG/y++OuW6MyCo6hT9prXk=
187+
go.opentelemetry.io/otel/exporters/otlp/otlpmetric/otlpmetricgrpc v1.28.0/go.mod h1:yeGZANgEcpdx/WK0IvvRFC+2oLiMS2u4L/0Rj2M2Qr0=
188+
go.opentelemetry.io/otel/exporters/otlp/otlpmetric/otlpmetrichttp v1.28.0 h1:aLmmtjRke7LPDQ3lvpFz+kNEH43faFhzW7v8BFIEydg=
189+
go.opentelemetry.io/otel/exporters/otlp/otlpmetric/otlpmetrichttp v1.28.0/go.mod h1:TC1pyCt6G9Sjb4bQpShH+P5R53pO6ZuGnHuuln9xMeE=
196190
go.opentelemetry.io/otel/exporters/otlp/otlptrace v1.28.0 h1:3Q/xZUyC1BBkualc9ROb4G8qkH90LXEIICcs5zv1OYY=
197191
go.opentelemetry.io/otel/exporters/otlp/otlptrace v1.28.0/go.mod h1:s75jGIWA9OfCMzF0xr+ZgfrB5FEbbV7UuYo32ahUiFI=
198192
go.opentelemetry.io/otel/exporters/otlp/otlptrace/otlptracegrpc v1.28.0 h1:R3X6ZXmNPRR8ul6i3WgFURCHzaXjHdm0karRG/+dj3s=
@@ -228,8 +222,6 @@ golang.org/x/net v0.0.0-20200226121028-0de0cce0169b/go.mod h1:z5CRVTTTmAJ677TzLL
228222
golang.org/x/net v0.0.0-20201021035429-f5854403a974/go.mod h1:sp8m0HH+o8qH0wwXwYZr8TS3Oi6o0r6Gce1SSxlDquU=
229223
golang.org/x/net v0.29.0 h1:5ORfpBpCs4HzDYoodCDBbwHzdR5UrLBZ3sOnUJmFoHo=
230224
golang.org/x/net v0.29.0/go.mod h1:gLkgy8jTGERgjzMic6DS9+SP0ajcu6Xu3Orq/SpETg0=
231-
golang.org/x/oauth2 v0.21.0 h1:tsimM75w1tF/uws5rbeHzIWxEqElMehnc+iW793zsZs=
232-
golang.org/x/oauth2 v0.21.0/go.mod h1:XYTD2NtWslqkgxebSiOHnXEap4TF09sJSc7H1sXbhtI=
233225
golang.org/x/sync v0.0.0-20190423024810-112230192c58/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
234226
golang.org/x/sync v0.0.0-20190911185100-cd5d95a43a6e/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
235227
golang.org/x/sync v0.0.0-20201020160332-67f06af15bc9/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=

helpers.go

Lines changed: 43 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@ const (
3232
)
3333

3434
var disableDiffMerge atomic.Bool
35+
var disableSymlinks atomic.Bool
3536

3637
// DisableDiffMerge allows disabling the use of [llb.Diff] and [llb.Merge] in favor of [llb.Copy].
3738
// This is needed when the buildkit version does not support [llb.Diff] and [llb.Merge].
@@ -45,6 +46,12 @@ func DisableDiffMerge(v bool) {
4546
disableDiffMerge.Store(v)
4647
}
4748

49+
// DisableSymlinks allows disabling the use of the [llb.Symlink] FileAction.
50+
// This is needed when the buildkit version does not support [llb.Symlink].
51+
func DisableSymlinks(v bool) {
52+
disableSymlinks.Store(v)
53+
}
54+
4855
type copyOptionFunc func(*llb.CopyInfo)
4956

5057
func (f copyOptionFunc) SetCopyOption(i *llb.CopyInfo) {
@@ -367,8 +374,25 @@ func ShArgsf(format string, args ...interface{}) llb.RunOption {
367374
return ShArgs(fmt.Sprintf(format, args...))
368375
}
369376

370-
// InstallPostSymlinks returns a RunOption that adds symlinks defined in the [PostInstall] underneath the provided rootfs path.
371-
func InstallPostSymlinks(post *PostInstall, rootfsPath string) llb.RunOption {
377+
func InstallPostSymlinks(builderImg llb.State, post *PostInstall, rootfsPath string, opts ...llb.ConstraintsOpt) llb.StateOption {
378+
if disableDiffMerge.Load() {
379+
return installPostSymlinksShell(builderImg, post, rootfsPath, opts...)
380+
}
381+
382+
return installPostSymlinksLLB(post)
383+
}
384+
385+
func installPostSymlinksShell(builderImg llb.State, post *PostInstall, rootfsPath string, opts ...llb.ConstraintsOpt) llb.StateOption {
386+
return func(rootfs llb.State) llb.State {
387+
return builderImg.Run(
388+
WithConstraints(opts...),
389+
withSymlinkInstallScript(post, rootfsPath),
390+
).AddMount(rootfsPath, rootfs)
391+
}
392+
}
393+
394+
// withSymlinkInstallScript returns a RunOption that adds symlinks defined in the [PostInstall] underneath the provided rootfs path.
395+
func withSymlinkInstallScript(post *PostInstall, rootfsPath string) llb.RunOption {
372396
return runOptionFunc(func(ei *llb.ExecInfo) {
373397
if post == nil {
374398
return
@@ -397,6 +421,23 @@ func InstallPostSymlinks(post *PostInstall, rootfsPath string) llb.RunOption {
397421
})
398422
}
399423

424+
// InstallPostSymlinks returns a RunOption that adds symlinks defined in the [PostInstall] underneath the provided rootfs path.
425+
func installPostSymlinksLLB(post *PostInstall, opts ...llb.ConstraintsOpt) llb.StateOption {
426+
return func(s llb.State) llb.State {
427+
if post == nil {
428+
return s
429+
}
430+
431+
ret := s
432+
pg := llb.ProgressGroup(identity.NewID(), "add symlinks", false)
433+
for oldpath, sl := range post.Symlinks {
434+
ret = ret.File(llb.Symlink(oldpath, sl.Path), pg)
435+
}
436+
437+
return ret
438+
}
439+
}
440+
400441
func (s *Spec) GetSigner(targetKey string) (*PackageSigner, bool) {
401442
if s.Targets != nil {
402443
targetOverridesRootSigningConfig := hasValidSigner(s.PackageConfig)

0 commit comments

Comments
 (0)