@@ -18,9 +18,9 @@ import (
18
18
)
19
19
20
20
func InitContainerdWorker () {
21
- Register (& containerd {
22
- name : "containerd" ,
23
- containerd : "containerd" ,
21
+ Register (& Containerd {
22
+ ID : "containerd" ,
23
+ Containerd : "containerd" ,
24
24
})
25
25
// defined in Dockerfile
26
26
// e.g. `containerd-1.1=/opt/containerd-1.1/bin,containerd-42.0=/opt/containerd-42.0/bin`
@@ -32,11 +32,11 @@ func InitContainerdWorker() {
32
32
panic (errors .Errorf ("unexpected BUILDKIT_INTEGRATION_CONTAINERD_EXTRA: %q" , s ))
33
33
}
34
34
name , bin := pair [0 ], pair [1 ]
35
- Register (& containerd {
36
- name : name ,
37
- containerd : filepath .Join (bin , "containerd" ),
35
+ Register (& Containerd {
36
+ ID : name ,
37
+ Containerd : filepath .Join (bin , "containerd" ),
38
38
// override PATH to make sure that the expected version of the shim binary is used
39
- extraEnv : []string {fmt .Sprintf ("PATH=%s:%s" , bin , os .Getenv ("PATH" ))},
39
+ ExtraEnv : []string {fmt .Sprintf ("PATH=%s:%s" , bin , os .Getenv ("PATH" ))},
40
40
})
41
41
}
42
42
}
@@ -48,44 +48,44 @@ func InitContainerdWorker() {
48
48
bklog .L .Fatalf ("unexpected BUILDKIT_INTEGRATION_ROOTLESS_IDPAIR: %q" , s )
49
49
}
50
50
if rootlessSupported (uid ) {
51
- Register (& containerd {
52
- name : "containerd-rootless" ,
53
- containerd : "containerd" ,
54
- uid : uid ,
55
- gid : gid ,
56
- snapshotter : "native" , // TODO: test with fuse-overlayfs as well, or automatically determine snapshotter
51
+ Register (& Containerd {
52
+ ID : "containerd-rootless" ,
53
+ Containerd : "containerd" ,
54
+ UID : uid ,
55
+ GID : gid ,
56
+ Snapshotter : "native" , // TODO: test with fuse-overlayfs as well, or automatically determine snapshotter
57
57
})
58
58
}
59
59
}
60
60
61
61
if s := os .Getenv ("BUILDKIT_INTEGRATION_SNAPSHOTTER" ); s != "" {
62
- Register (& containerd {
63
- name : fmt .Sprintf ("containerd-snapshotter-%s" , s ),
64
- containerd : "containerd" ,
65
- snapshotter : s ,
62
+ Register (& Containerd {
63
+ ID : fmt .Sprintf ("containerd-snapshotter-%s" , s ),
64
+ Containerd : "containerd" ,
65
+ Snapshotter : s ,
66
66
})
67
67
}
68
68
}
69
69
70
- type containerd struct {
71
- name string
72
- containerd string
73
- snapshotter string
74
- uid int
75
- gid int
76
- extraEnv []string // e.g. "PATH=/opt/containerd-1.4/bin:/usr/bin:..."
70
+ type Containerd struct {
71
+ ID string
72
+ Containerd string
73
+ Snapshotter string
74
+ UID int
75
+ GID int
76
+ ExtraEnv []string // e.g. "PATH=/opt/containerd-1.4/bin:/usr/bin:..."
77
77
}
78
78
79
- func (c * containerd ) Name () string {
80
- return c .name
79
+ func (c * Containerd ) Name () string {
80
+ return c .ID
81
81
}
82
82
83
- func (c * containerd ) Rootless () bool {
84
- return c .uid != 0
83
+ func (c * Containerd ) Rootless () bool {
84
+ return c .UID != 0
85
85
}
86
86
87
- func (c * containerd ) New (ctx context.Context , cfg * BackendConfig ) (b Backend , cl func () error , err error ) {
88
- if err := lookupBinary (c .containerd ); err != nil {
87
+ func (c * Containerd ) New (ctx context.Context , cfg * BackendConfig ) (b Backend , cl func () error , err error ) {
88
+ if err := lookupBinary (c .Containerd ); err != nil {
89
89
return nil , nil , err
90
90
}
91
91
if err := lookupBinary ("buildkitd" ); err != nil {
@@ -106,9 +106,9 @@ func (c *containerd) New(ctx context.Context, cfg *BackendConfig) (b Backend, cl
106
106
}()
107
107
108
108
rootless := false
109
- if c .uid != 0 {
110
- if c .gid == 0 {
111
- return nil , nil , errors .Errorf ("unsupported id pair: uid=%d, gid=%d" , c .uid , c .gid )
109
+ if c .UID != 0 {
110
+ if c .GID == 0 {
111
+ return nil , nil , errors .Errorf ("unsupported id pair: uid=%d, gid=%d" , c .UID , c .GID )
112
112
}
113
113
rootless = true
114
114
}
@@ -118,7 +118,7 @@ func (c *containerd) New(ctx context.Context, cfg *BackendConfig) (b Backend, cl
118
118
return nil , nil , err
119
119
}
120
120
if rootless {
121
- if err := os .Chown (tmpdir , c .uid , c .gid ); err != nil {
121
+ if err := os .Chown (tmpdir , c .UID , c .GID ); err != nil {
122
122
return nil , nil , err
123
123
}
124
124
}
@@ -141,10 +141,10 @@ disabled_plugins = ["cri"]
141
141
` , filepath .Join (tmpdir , "root" ), filepath .Join (tmpdir , "state" ), address , filepath .Join (tmpdir , "debug.sock" ))
142
142
143
143
var snBuildkitdArgs []string
144
- if c .snapshotter != "" {
144
+ if c .Snapshotter != "" {
145
145
snBuildkitdArgs = append (snBuildkitdArgs ,
146
- fmt .Sprintf ("--containerd-worker-snapshotter=%s" , c .snapshotter ))
147
- if c .snapshotter == "stargz" {
146
+ fmt .Sprintf ("--containerd-worker-snapshotter=%s" , c .Snapshotter ))
147
+ if c .Snapshotter == "stargz" {
148
148
snPath , snCl , err := runStargzSnapshotter (cfg )
149
149
if err != nil {
150
150
return nil , nil , err
@@ -165,21 +165,21 @@ disabled_plugins = ["cri"]
165
165
return nil , nil , err
166
166
}
167
167
168
- containerdArgs := []string {c .containerd , "--config" , configFile }
168
+ containerdArgs := []string {c .Containerd , "--config" , configFile }
169
169
rootlessKitState := filepath .Join (tmpdir , "rootlesskit-containerd" )
170
170
if rootless {
171
- containerdArgs = append (append ([]string {"sudo" , "-u" , fmt .Sprintf ("#%d" , c .uid ), "-i" ,
171
+ containerdArgs = append (append ([]string {"sudo" , "-u" , fmt .Sprintf ("#%d" , c .UID ), "-i" ,
172
172
fmt .Sprintf ("CONTAINERD_ROOTLESS_ROOTLESSKIT_STATE_DIR=%s" , rootlessKitState ),
173
173
// Integration test requires the access to localhost of the host network namespace.
174
174
// TODO: remove these configurations
175
175
"CONTAINERD_ROOTLESS_ROOTLESSKIT_NET=host" ,
176
176
"CONTAINERD_ROOTLESS_ROOTLESSKIT_PORT_DRIVER=none" ,
177
177
"CONTAINERD_ROOTLESS_ROOTLESSKIT_FLAGS=--mtu=0" ,
178
- }, c .extraEnv ... ), "containerd-rootless.sh" , "-c" , configFile )
178
+ }, c .ExtraEnv ... ), "containerd-rootless.sh" , "-c" , configFile )
179
179
}
180
180
181
181
cmd := exec .Command (containerdArgs [0 ], containerdArgs [1 :]... ) //nolint:gosec // test utility
182
- cmd .Env = append (os .Environ (), c .extraEnv ... )
182
+ cmd .Env = append (os .Environ (), c .ExtraEnv ... )
183
183
184
184
ctdStop , err := startCmd (cmd , cfg .Logs )
185
185
if err != nil {
@@ -199,8 +199,8 @@ disabled_plugins = ["cri"]
199
199
"--containerd-worker-labels=org.mobyproject.buildkit.worker.sandbox=true" , // Include use of --containerd-worker-labels to trigger https://github.com/moby/buildkit/pull/603
200
200
}, snBuildkitdArgs ... )
201
201
202
- if runtime .GOOS != "windows" && c .snapshotter != "native" {
203
- c .extraEnv = append (c .extraEnv , "BUILDKIT_DEBUG_FORCE_OVERLAY_DIFF=true" )
202
+ if runtime .GOOS != "windows" && c .Snapshotter != "native" {
203
+ c .ExtraEnv = append (c .ExtraEnv , "BUILDKIT_DEBUG_FORCE_OVERLAY_DIFF=true" )
204
204
}
205
205
if rootless {
206
206
pidStr , err := os .ReadFile (filepath .Join (rootlessKitState , "child_pid" ))
@@ -211,11 +211,11 @@ disabled_plugins = ["cri"]
211
211
if err != nil {
212
212
return nil , nil , err
213
213
}
214
- buildkitdArgs = append ([]string {"sudo" , "-u" , fmt .Sprintf ("#%d" , c .uid ), "-i" , "--" , "exec" ,
214
+ buildkitdArgs = append ([]string {"sudo" , "-u" , fmt .Sprintf ("#%d" , c .UID ), "-i" , "--" , "exec" ,
215
215
"nsenter" , "-U" , "--preserve-credentials" , "-m" , "-t" , fmt .Sprintf ("%d" , pid )},
216
216
append (buildkitdArgs , "--containerd-worker-snapshotter=native" )... )
217
217
}
218
- buildkitdSock , stop , err := runBuildkitd (ctx , cfg , buildkitdArgs , cfg .Logs , c .uid , c .gid , c .extraEnv )
218
+ buildkitdSock , stop , err := runBuildkitd (ctx , cfg , buildkitdArgs , cfg .Logs , c .UID , c .GID , c .ExtraEnv )
219
219
if err != nil {
220
220
printLogs (cfg .Logs , log .Println )
221
221
return nil , nil , err
@@ -226,7 +226,7 @@ disabled_plugins = ["cri"]
226
226
address : buildkitdSock ,
227
227
containerdAddress : address ,
228
228
rootless : rootless ,
229
- snapshotter : c .snapshotter ,
229
+ snapshotter : c .Snapshotter ,
230
230
}, cl , nil
231
231
}
232
232
0 commit comments