@@ -158,30 +158,48 @@ func ServerSemVer(ctx context.Context, client *containerd.Client) (*semver.Versi
158
158
}
159
159
160
160
func buildctlVersion () dockercompat.ComponentVersion {
161
- const buildctl = "buildctl"
162
161
buildctlBinary , err := buildkitutil .BuildctlBinary ()
163
162
if err != nil {
164
163
logrus .Warnf ("unable to determine buildctl version: %s" , err .Error ())
165
- return dockercompat.ComponentVersion {Name : buildctl }
164
+ return dockercompat.ComponentVersion {Name : "builctl" }
166
165
}
167
166
168
167
stdout , err := exec .Command (buildctlBinary , "--version" ).Output ()
169
168
if err != nil {
170
169
logrus .Warnf ("unable to determine buildctl version: %s" , err .Error ())
171
- return dockercompat.ComponentVersion {Name : buildctl }
170
+ return dockercompat.ComponentVersion {Name : " buildctl" }
172
171
}
173
172
174
- versionStr := strings . Fields ( strings . TrimSpace ( string ( stdout )) )
175
- if len ( versionStr ) != 4 {
176
- logrus .Errorf ( "unable to determine buildctl version got: %s" , versionStr )
177
- return dockercompat.ComponentVersion {Name : buildctl }
173
+ v , err := parseBuildctlVersion ( stdout )
174
+ if err != nil {
175
+ logrus .Warn ( err )
176
+ return dockercompat.ComponentVersion {Name : " buildctl" }
178
177
}
178
+ return * v
179
+ }
179
180
180
- return dockercompat.ComponentVersion {
181
- Name : buildctl ,
182
- Version : versionStr [2 ],
183
- Details : map [string ]string {"GitCommit" : versionStr [3 ]},
181
+ func parseBuildctlVersion (buildctlVersionStdout []byte ) (* dockercompat.ComponentVersion , error ) {
182
+ fields := strings .Fields (strings .TrimSpace (string (buildctlVersionStdout )))
183
+ var v * dockercompat.ComponentVersion
184
+ switch len (fields ) {
185
+ case 4 :
186
+ v = & dockercompat.ComponentVersion {
187
+ Name : fields [0 ],
188
+ Version : fields [2 ],
189
+ Details : map [string ]string {"GitCommit" : fields [3 ]},
190
+ }
191
+ case 3 :
192
+ v = & dockercompat.ComponentVersion {
193
+ Name : fields [0 ],
194
+ Version : fields [2 ],
195
+ }
196
+ default :
197
+ return nil , fmt .Errorf ("unable to determine buildctl version, got %q" , string (buildctlVersionStdout ))
184
198
}
199
+ if v .Name != "buildctl" {
200
+ return nil , fmt .Errorf ("unable to determine buildctl version, got %q" , string (buildctlVersionStdout ))
201
+ }
202
+ return v , nil
185
203
}
186
204
187
205
func runcVersion () dockercompat.ComponentVersion {
@@ -190,30 +208,40 @@ func runcVersion() dockercompat.ComponentVersion {
190
208
logrus .Warnf ("unable to determine runc version: %s" , err .Error ())
191
209
return dockercompat.ComponentVersion {Name : "runc" }
192
210
}
211
+ v , err := parseRuncVersion (stdout )
212
+ if err != nil {
213
+ logrus .Warn (err )
214
+ return dockercompat.ComponentVersion {Name : "runc" }
215
+ }
216
+ return * v
217
+ }
193
218
194
- var versionList = strings .Split (strings .TrimSpace (string (stdout )), "\n " )
219
+ func parseRuncVersion (runcVersionStdout []byte ) (* dockercompat.ComponentVersion , error ) {
220
+ var versionList = strings .Split (strings .TrimSpace (string (runcVersionStdout )), "\n " )
195
221
firstLine := strings .Fields (versionList [0 ])
196
- if len (firstLine ) != 3 {
197
- logrus .Errorf ("unable to determine runc version, got: %s" , firstLine )
198
- return dockercompat.ComponentVersion {Name : "runc" }
222
+ if len (firstLine ) != 3 || firstLine [0 ] != "runc" {
223
+ return nil , fmt .Errorf ("unable to determine runc version, got: %s" , string (runcVersionStdout ))
199
224
}
200
225
version := firstLine [2 ]
201
226
202
227
details := map [string ]string {}
203
228
for _ , detailsLine := range versionList [1 :] {
204
- detail := strings .Split (detailsLine , ": " )
229
+ detail := strings .SplitN (detailsLine , ":" , 2 )
205
230
if len (detail ) != 2 {
206
231
logrus .Warnf ("unable to determine one of runc details, got: %s, %d" , detail , len (detail ))
207
232
continue
208
233
}
209
- details [detail [0 ]] = detail [1 ]
234
+ switch strings .TrimSpace (detail [0 ]) {
235
+ case "commit" :
236
+ details ["GitCommit" ] = strings .TrimSpace (detail [1 ])
237
+ }
210
238
}
211
239
212
- return dockercompat.ComponentVersion {
240
+ return & dockercompat.ComponentVersion {
213
241
Name : "runc" ,
214
242
Version : version ,
215
243
Details : details ,
216
- }
244
+ }, nil
217
245
}
218
246
219
247
//BlockIOWeight return whether Block IO weight is supported or not
0 commit comments