Skip to content
This repository has been archived by the owner on Dec 20, 2024. It is now read-only.

Commit

Permalink
Merge pull request #674 from yeya24/feature/add-version
Browse files Browse the repository at this point in the history
feature: add more version information to both cmd and router
  • Loading branch information
allencloud authored Jul 17, 2019
2 parents a3862fb + 9ee5566 commit 21d2390
Show file tree
Hide file tree
Showing 30 changed files with 357 additions and 57 deletions.
38 changes: 38 additions & 0 deletions apis/swagger.yml
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,20 @@ paths:
500:
$ref: "#/responses/500ErrorResponse"

/version:
get:
summary: "Get version and build information"
description: |
Get version and build information, including GoVersion, OS,
Arch, Version, BuildDate, and GitCommit.
responses:
200:
description: "no error"
schema:
$ref: "#/definitions/DragonflyVersion"
500:
$ref: "#/responses/500ErrorResponse"

/peer/registry:
post:
summary: "registry a task"
Expand Down Expand Up @@ -567,6 +581,30 @@ definitions:
message:
type: string

DragonflyVersion:
type: "object"
description: |
Version and build information of Dragonfly components.
properties:
Version:
type: "string"
description: "Version of Dragonfly components"
Revision:
type: "string"
description: "Git commit when building Dragonfly components"
BuildDate:
type: "string"
description: "Build Date of Dragonfly components"
GoVersion:
type: "string"
description: "Golang runtime version"
OS:
type: "string"
description: "Dragonfly components's operating system"
Arch:
type: "string"
description: "Dragonfly components's architecture target"

ResultInfo:
type: "object"
description: |
Expand Down
3 changes: 2 additions & 1 deletion apis/types/df_get_task.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

59 changes: 59 additions & 0 deletions apis/types/dragonfly_version.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions apis/types/error.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions apis/types/error_response.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 2 additions & 1 deletion apis/types/peer_create_request.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions apis/types/peer_create_response.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 2 additions & 1 deletion apis/types/peer_info.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions apis/types/piece_info.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 2 additions & 1 deletion apis/types/piece_pull_request.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 2 additions & 1 deletion apis/types/piece_update_request.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions apis/types/preheat_create_request.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions apis/types/preheat_create_response.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 2 additions & 1 deletion apis/types/preheat_info.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions apis/types/result_info.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 2 additions & 1 deletion apis/types/task_create_request.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions apis/types/task_create_response.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 2 additions & 1 deletion apis/types/task_info.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 2 additions & 1 deletion apis/types/task_register_request.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions apis/types/task_update_request.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

12 changes: 2 additions & 10 deletions cmd/dfdaemon/app/root.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@ package app

import (
"encoding/json"
"fmt"
"os"
"os/exec"
"path/filepath"
Expand All @@ -29,14 +28,13 @@ import (
"github.com/dragonflyoss/Dragonfly/dfdaemon"
"github.com/dragonflyoss/Dragonfly/dfdaemon/config"
"github.com/dragonflyoss/Dragonfly/dfdaemon/constant"
"github.com/dragonflyoss/Dragonfly/version"

"github.com/mitchellh/mapstructure"
"github.com/pkg/errors"
"gopkg.in/yaml.v2"

"github.com/sirupsen/logrus"
"github.com/spf13/cobra"
"github.com/spf13/viper"
"gopkg.in/yaml.v2"
)

var rootCmd = &cobra.Command{
Expand All @@ -45,11 +43,6 @@ var rootCmd = &cobra.Command{
Long: "The dfdaemon is a proxy between container engine and registry used for pulling images.",
DisableAutoGenTag: true, // disable displaying auto generation tag in cli docs
RunE: func(cmd *cobra.Command, args []string) error {
if viper.GetBool("version") {
fmt.Println("dfdaemon version:", version.DFDaemonVersion)
return nil
}

if err := readConfigFile(viper.GetViper(), cmd); err != nil {
return errors.Wrap(err, "read config file")
}
Expand Down Expand Up @@ -83,7 +76,6 @@ func init() {

rf := rootCmd.Flags()

rf.BoolP("version", "v", false, "version")
rf.String("config", constant.DefaultConfigPath, "the path of dfdaemon's configuration file")

rf.Bool("verbose", false, "verbose")
Expand Down
40 changes: 40 additions & 0 deletions cmd/dfdaemon/app/version.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
package app

import (
"fmt"

"github.com/dragonflyoss/Dragonfly/version"

"github.com/spf13/cobra"
)

// versionDescription is used to describe version command in detail and auto generate command doc.
var versionDescription = "Display the version and build information of Dragonfly dfdaemon, " +
"including GoVersion, OS, Arch, Version, BuildDate and GitCommit."

var versionCmd = &cobra.Command{
Use: "version",
Short: "Show the current version of dfdaemon",
Long: versionDescription,
SilenceErrors: true,
SilenceUsage: true,
RunE: func(cmd *cobra.Command, args []string) error {
fmt.Println(version.Print("dfdaemon"))
return nil
},
Example: versionExample(),
}

func init() {
rootCmd.AddCommand(versionCmd)
}

// versionExample shows examples in version command, and is used in auto-generated cli docs.
func versionExample() string {
return `dfdaemon, version 0.4.1
Git commit: 6fd5c8f
Build date: 20190717-15:57:52
Go version: go1.12.6
OS/Arch: linux/amd64
`
}
Loading

0 comments on commit 21d2390

Please sign in to comment.