@@ -22,6 +22,19 @@ import (
22
22
23
23
const diskFullStorageDriver = "vfs"
24
24
25
+ // Adapted from github.com/NVIDIA/nvidia-container-toolkit/internal/lookup/library.go
26
+ // These are destination candidates for the /usr/lib directory in the container,
27
+ // in order of priority.
28
+ // Depending on the inner image, the desired location may vary.
29
+ // Note that we are excluding some nvidia-specific directories here and also
30
+ // include a fallback to /usr/lib.
31
+ var usrLibCandidates = []string {
32
+ "/usr/lib/x86_64-linux-gnu" , // Debian uses a multiarch /usr/lib directory
33
+ "/usr/lib/aarch64-linux-gnu" , // Above but for arm64.
34
+ "/usr/lib64" , // Red Hat and friends.
35
+ "/usr/lib" , // Fallback.
36
+ }
37
+
25
38
type PullImageConfig struct {
26
39
Client Client
27
40
Image string
@@ -148,10 +161,11 @@ func processImagePullEvents(r io.Reader, fn ImagePullProgressFn) error {
148
161
}
149
162
150
163
type ImageMetadata struct {
151
- UID string
152
- GID string
153
- HomeDir string
154
- HasInit bool
164
+ UID string
165
+ GID string
166
+ HomeDir string
167
+ HasInit bool
168
+ UsrLibDir string
155
169
}
156
170
157
171
// GetImageMetadata returns metadata about an image such as the UID/GID of the
@@ -226,11 +240,29 @@ func GetImageMetadata(ctx context.Context, client Client, img, username string)
226
240
return ImageMetadata {}, xerrors .Errorf ("no users returned for username %s" , username )
227
241
}
228
242
243
+ // Find the "best" usr lib directory for the container.
244
+ var foundUsrLibDir string
245
+ for _ , candidate := range usrLibCandidates {
246
+ _ , err := ExecContainer (ctx , client , ExecConfig {
247
+ ContainerID : inspect .ID ,
248
+ Cmd : "stat" ,
249
+ Args : []string {candidate },
250
+ })
251
+ if err == nil {
252
+ foundUsrLibDir = candidate
253
+ break
254
+ }
255
+ }
256
+ if foundUsrLibDir == "" {
257
+ return ImageMetadata {}, xerrors .Errorf ("no eligible /usr/lib directory found in container" )
258
+ }
259
+
229
260
return ImageMetadata {
230
- UID : users [0 ].Uid ,
231
- GID : users [0 ].Gid ,
232
- HomeDir : users [0 ].HomeDir ,
233
- HasInit : initExists ,
261
+ UID : users [0 ].Uid ,
262
+ GID : users [0 ].Gid ,
263
+ HomeDir : users [0 ].HomeDir ,
264
+ HasInit : initExists ,
265
+ UsrLibDir : foundUsrLibDir ,
234
266
}, nil
235
267
}
236
268
0 commit comments