Skip to content

Commit 2bde28c

Browse files
committed
fall back to linux if no /etc/os-release found
1 parent 558a836 commit 2bde28c

File tree

1 file changed

+10
-11
lines changed

1 file changed

+10
-11
lines changed

dockerutil/image.go

Lines changed: 10 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -251,22 +251,21 @@ func GetImageMetadata(ctx context.Context, client Client, img, username string)
251251
}
252252

253253
// Read the /etc/os-release file to get the ID of the OS.
254+
// We only care about the ID field.
255+
var osReleaseID string
254256
out, err = ExecContainer(ctx, client, ExecConfig{
255257
ContainerID: inspect.ID,
256258
Cmd: "cat",
257259
Args: []string{etcOsRelease},
258260
})
259-
if err != nil {
260-
return ImageMetadata{}, xerrors.Errorf("read /etc/os-release: %w", err)
261-
}
262-
// We only care about the ID field.
263-
osReleaseID := ""
264-
for _, line := range strings.Split(string(out), "\n") {
265-
if strings.HasPrefix(line, "ID=") {
266-
osReleaseID = strings.TrimPrefix(line, "ID=")
267-
// The value may be quoted.
268-
osReleaseID = strings.Trim(osReleaseID, "\"")
269-
break
261+
if err == nil {
262+
for _, line := range strings.Split(string(out), "\n") {
263+
if strings.HasPrefix(line, "ID=") {
264+
osReleaseID = strings.TrimPrefix(line, "ID=")
265+
// The value may be quoted.
266+
osReleaseID = strings.Trim(osReleaseID, "\"")
267+
break
268+
}
270269
}
271270
}
272271
if osReleaseID == "" {

0 commit comments

Comments
 (0)