Skip to content

Commit

Permalink
Display buildkit version in nerdctl
Browse files Browse the repository at this point in the history
Fixes#1082

Signed-off-by: Manu Gupta <manugupt1@gmail.com>
  • Loading branch information
manugupt1 committed Jul 8, 2022
1 parent b1ae460 commit c73f694
Showing 1 changed file with 28 additions and 0 deletions.
28 changes: 28 additions & 0 deletions cmd/nerdctl/version.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,13 @@ import (
"fmt"
"io"
"os"
"os/exec"
"strings"
"text/template"

"github.com/sirupsen/logrus"

"github.com/containerd/nerdctl/pkg/buildkitutil"
"github.com/containerd/nerdctl/pkg/infoutil"
"github.com/containerd/nerdctl/pkg/inspecttypes/dockercompat"
"github.com/spf13/cobra"
Expand Down Expand Up @@ -86,6 +91,8 @@ func versionAction(cmd *cobra.Command, args []string) error {
}
}
}
fmt.Fprintf(w, "\n")
fmt.Fprint(w, getBuildKitVersion())
return vErr
}

Expand All @@ -102,3 +109,24 @@ func versionInfo(cmd *cobra.Command) (dockercompat.VersionInfo, error) {
v.Server, err = infoutil.ServerVersion(ctx, client)
return v, err
}

func getBuildKitVersion() string {
buildctlBinary, err := buildkitutil.BuildctlBinary()
if err != nil {
logrus.Warnf("unable to determine buildkit version: %s", err.Error())
return "buildkit: not installed"
}

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

versionStr := strings.Fields(strings.TrimSpace(string(stdout)))
formattedStr := fmt.Sprintf("buildkit:\n"+
" Version: \t%s\n"+
" Git commit: \t%s\n", versionStr[2], versionStr[3])

return formattedStr
}

0 comments on commit c73f694

Please sign in to comment.