@@ -17,6 +17,7 @@ import (
1717 "github.com/adrianliechti/loop/pkg/kubernetes"
1818 "github.com/adrianliechti/loop/pkg/to"
1919
20+ "github.com/Masterminds/semver/v3"
2021 "github.com/google/go-containerregistry/pkg/name"
2122 "github.com/google/uuid"
2223 "github.com/moby/moby/pkg/archive"
@@ -204,11 +205,11 @@ func Run(ctx context.Context, client kubernetes.Client, namespace string, image
204205
205206 data , _ := json .Marshal (config )
206207
207- if err := client .PodExec (ctx , pod .Namespace , pod .Name , container , []string {"mkdir" , "-p" , "/root /.docker" }, false , nil , io .Discard , io .Discard ); err != nil {
208+ if err := client .PodExec (ctx , pod .Namespace , pod .Name , container , []string {"mkdir" , "-p" , "/home/user /.docker" }, false , nil , io .Discard , io .Discard ); err != nil {
208209 return err
209210 }
210211
211- if err := client .PodExec (ctx , namespace , name , container , []string {"cp" , "/dev/stdin" , "/root /.docker/config.json" }, false , bytes .NewReader (data ), io .Discard , io .Discard ); err != nil {
212+ if err := client .PodExec (ctx , namespace , name , container , []string {"cp" , "/dev/stdin" , "/home/user /.docker/config.json" }, false , bytes .NewReader (data ), io .Discard , io .Discard ); err != nil {
212213 return err
213214 }
214215 }
@@ -244,7 +245,13 @@ func Run(ctx context.Context, client kubernetes.Client, namespace string, image
244245
245246func startPod (ctx context.Context , client kubernetes.Client , namespace , name , image string ) (* corev1.Pod , error ) {
246247 if image == "" {
247- image = "moby/buildkit"
248+ image = "moby/buildkit:rootless"
249+ }
250+
251+ version , err := client .Version (ctx )
252+
253+ if err != nil {
254+ return nil , err
248255 }
249256
250257 probe := & corev1.Probe {
@@ -275,19 +282,61 @@ func startPod(ctx context.Context, client kubernetes.Client, namespace, name, im
275282 Image : image ,
276283 ImagePullPolicy : corev1 .PullAlways ,
277284
285+ Args : []string {
286+ "--oci-worker-no-process-sandbox" ,
287+ },
288+
278289 SecurityContext : & corev1.SecurityContext {
279290 Privileged : to .Ptr (true ),
291+
292+ AppArmorProfile : & corev1.AppArmorProfile {
293+ Type : corev1 .AppArmorProfileTypeUnconfined ,
294+ },
295+
296+ SeccompProfile : & corev1.SeccompProfile {
297+ Type : corev1 .SeccompProfileTypeUnconfined ,
298+ },
299+
300+ RunAsUser : to .Ptr (int64 (1000 )),
301+ RunAsGroup : to .Ptr (int64 (1000 )),
280302 },
281303
282304 ReadinessProbe : probe ,
283305 LivenessProbe : probe ,
306+
307+ VolumeMounts : []corev1.VolumeMount {
308+ {
309+ Name : "data" ,
310+ MountPath : "/home/user/.local/share/buildkit" ,
311+ },
312+ },
284313 },
285314 },
286315
287316 TerminationGracePeriodSeconds : to .Ptr (int64 (10 )),
317+
318+ Volumes : []corev1.Volume {
319+ {
320+ Name : "data" ,
321+ VolumeSource : corev1.VolumeSource {
322+ EmptyDir : & corev1.EmptyDirVolumeSource {},
323+ },
324+ },
325+ },
288326 },
289327 }
290328
329+ c , _ := semver .NewConstraint ("< 1.30" )
330+
331+ if c .Check (version ) {
332+ if pod .Annotations == nil {
333+ pod .Annotations = map [string ]string {}
334+ }
335+
336+ pod .Spec .Containers [0 ].SecurityContext .AppArmorProfile = nil
337+ pod .Annotations ["container.apparmor.security.beta.kubernetes.io/buildkitd" ] = "unconfined"
338+ }
339+
291340 if _ , err := client .CoreV1 ().Pods (namespace ).Create (ctx , pod , metav1.CreateOptions {}); err != nil {
292341 return nil , err
293342 }
0 commit comments