Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Display buildkit and runc version in nerdctl #1209

Merged
merged 1 commit into from
Jul 15, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions cmd/nerdctl/version.go
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,13 @@ func versionAction(cmd *cobra.Command, args []string) error {
fmt.Fprintf(w, " Version:\t%s\n", v.Client.Version)
fmt.Fprintf(w, " OS/Arch:\t%s/%s\n", v.Client.Os, v.Client.Arch)
fmt.Fprintf(w, " Git commit:\t%s\n", v.Client.GitCommit)
for _, compo := range v.Client.Components {
fmt.Fprintf(w, " %s:\n", compo.Name)
fmt.Fprintf(w, " Version:\t%s\n", compo.Version)
for detailK, detailV := range compo.Details {
fmt.Fprintf(w, " %s:\t%s\n", detailK, detailV)
}
}
if v.Server != nil {
fmt.Fprintf(w, "\n")
fmt.Fprintf(w, "Server:\n")
Expand Down
67 changes: 66 additions & 1 deletion pkg/infoutil/infoutil.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ import (
"context"
"fmt"
"os"
"os/exec"
"runtime"
"strings"
"time"
Expand All @@ -28,10 +29,12 @@ import (
"github.com/containerd/containerd"
ptypes "github.com/containerd/containerd/protobuf/types"
"github.com/containerd/containerd/services/introspection"
"github.com/containerd/nerdctl/pkg/buildkitutil"
"github.com/containerd/nerdctl/pkg/inspecttypes/dockercompat"
"github.com/containerd/nerdctl/pkg/inspecttypes/native"
"github.com/containerd/nerdctl/pkg/logging"
"github.com/containerd/nerdctl/pkg/version"
"github.com/sirupsen/logrus"
)

func NativeDaemonInfo(ctx context.Context, client *containerd.Client) (*native.DaemonInfo, error) {
Expand Down Expand Up @@ -117,6 +120,9 @@ func ClientVersion() dockercompat.ClientVersion {
GoVersion: runtime.Version(),
Os: runtime.GOOS,
Arch: runtime.GOARCH,
Components: []dockercompat.ComponentVersion{
buildctlVersion(),
},
}
}

Expand All @@ -133,8 +139,8 @@ func ServerVersion(ctx context.Context, client *containerd.Client) (*dockercompa
Version: daemonVersion.Version,
Details: map[string]string{"GitCommit": daemonVersion.Revision},
},
runcVersion(),
},
// TODO: add runc version
}
return v, nil
}
Expand All @@ -151,6 +157,65 @@ func ServerSemVer(ctx context.Context, client *containerd.Client) (*semver.Versi
return sv, nil
}

func buildctlVersion() dockercompat.ComponentVersion {
const buildctl = "buildctl"
buildctlBinary, err := buildkitutil.BuildctlBinary()
if err != nil {
logrus.Warnf("unable to determine buildctl version: %s", err.Error())
return dockercompat.ComponentVersion{Name: buildctl}
}

stdout, err := exec.Command(buildctlBinary, "--version").Output()
if err != nil {
logrus.Warnf("unable to determine buildctl version: %s", err.Error())
return dockercompat.ComponentVersion{Name: buildctl}
}

versionStr := strings.Fields(strings.TrimSpace(string(stdout)))
if len(versionStr) != 4 {
logrus.Errorf("unable to determine buildctl version got: %s", versionStr)
return dockercompat.ComponentVersion{Name: buildctl}
}

return dockercompat.ComponentVersion{
Name: buildctl,
Version: versionStr[2],
manugupt1 marked this conversation as resolved.
Show resolved Hide resolved
Details: map[string]string{"GitCommit": versionStr[3]},
}
}

func runcVersion() dockercompat.ComponentVersion {
stdout, err := exec.Command("runc", "--version").Output()
if err != nil {
logrus.Warnf("unable to determine runc version: %s", err.Error())
return dockercompat.ComponentVersion{Name: "runc"}
}

var versionList = strings.Split(strings.TrimSpace(string(stdout)), "\n")
firstLine := strings.Fields(versionList[0])
if len(firstLine) != 3 {
logrus.Errorf("unable to determine runc version, got: %s", firstLine)
return dockercompat.ComponentVersion{Name: "runc"}
}
version := firstLine[2]

details := map[string]string{}
for _, detailsLine := range versionList[1:] {
detail := strings.Split(detailsLine, ": ")
if len(detail) != 2 {
logrus.Warnf("unable to determine one of runc details, got: %s, %d", detail, len(detail))
continue
}
details[detail[0]] = detail[1]
}

return dockercompat.ComponentVersion{
Name: "runc",
Version: version,
Details: details,
}
}

//BlockIOWeight return whether Block IO weight is supported or not
func BlockIOWeight(cgroupManager string) bool {
var info *dockercompat.Info
Expand Down
11 changes: 6 additions & 5 deletions pkg/inspecttypes/dockercompat/info.go
Original file line number Diff line number Diff line change
Expand Up @@ -76,11 +76,12 @@ type VersionInfo struct {

// ClientVersion is from https://github.com/docker/cli/blob/v20.10.8/cli/command/system/version.go#L74-L87
type ClientVersion struct {
Version string
GitCommit string
GoVersion string
Os string // GOOS
Arch string // GOARCH
Version string
GitCommit string
GoVersion string
Os string // GOOS
Arch string // GOARCH
Components []ComponentVersion // nerdctl extension
}

// ComponentVersion describes the version information for a specific component.
Expand Down