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

Commit 21d2390

Browse files
authored
Merge pull request #674 from yeya24/feature/add-version
feature: add more version information to both cmd and router
2 parents a3862fb + 9ee5566 commit 21d2390

30 files changed

+357
-57
lines changed

apis/swagger.yml

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,20 @@ paths:
4444
500:
4545
$ref: "#/responses/500ErrorResponse"
4646

47+
/version:
48+
get:
49+
summary: "Get version and build information"
50+
description: |
51+
Get version and build information, including GoVersion, OS,
52+
Arch, Version, BuildDate, and GitCommit.
53+
responses:
54+
200:
55+
description: "no error"
56+
schema:
57+
$ref: "#/definitions/DragonflyVersion"
58+
500:
59+
$ref: "#/responses/500ErrorResponse"
60+
4761
/peer/registry:
4862
post:
4963
summary: "registry a task"
@@ -567,6 +581,30 @@ definitions:
567581
message:
568582
type: string
569583

584+
DragonflyVersion:
585+
type: "object"
586+
description: |
587+
Version and build information of Dragonfly components.
588+
properties:
589+
Version:
590+
type: "string"
591+
description: "Version of Dragonfly components"
592+
Revision:
593+
type: "string"
594+
description: "Git commit when building Dragonfly components"
595+
BuildDate:
596+
type: "string"
597+
description: "Build Date of Dragonfly components"
598+
GoVersion:
599+
type: "string"
600+
description: "Golang runtime version"
601+
OS:
602+
type: "string"
603+
description: "Dragonfly components's operating system"
604+
Arch:
605+
type: "string"
606+
description: "Dragonfly components's architecture target"
607+
570608
ResultInfo:
571609
type: "object"
572610
description: |

apis/types/df_get_task.go

Lines changed: 2 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

apis/types/dragonfly_version.go

Lines changed: 59 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

apis/types/error.go

Lines changed: 1 addition & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

apis/types/error_response.go

Lines changed: 1 addition & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

apis/types/peer_create_request.go

Lines changed: 2 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

apis/types/peer_create_response.go

Lines changed: 1 addition & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

apis/types/peer_info.go

Lines changed: 2 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

apis/types/piece_info.go

Lines changed: 1 addition & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

apis/types/piece_pull_request.go

Lines changed: 2 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

apis/types/piece_update_request.go

Lines changed: 2 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

apis/types/preheat_create_request.go

Lines changed: 1 addition & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

apis/types/preheat_create_response.go

Lines changed: 1 addition & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

apis/types/preheat_info.go

Lines changed: 2 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

apis/types/result_info.go

Lines changed: 1 addition & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

apis/types/task_create_request.go

Lines changed: 2 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

apis/types/task_create_response.go

Lines changed: 1 addition & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

apis/types/task_info.go

Lines changed: 2 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

apis/types/task_register_request.go

Lines changed: 2 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

apis/types/task_update_request.go

Lines changed: 1 addition & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

cmd/dfdaemon/app/root.go

Lines changed: 2 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,6 @@ package app
1818

1919
import (
2020
"encoding/json"
21-
"fmt"
2221
"os"
2322
"os/exec"
2423
"path/filepath"
@@ -29,14 +28,13 @@ import (
2928
"github.com/dragonflyoss/Dragonfly/dfdaemon"
3029
"github.com/dragonflyoss/Dragonfly/dfdaemon/config"
3130
"github.com/dragonflyoss/Dragonfly/dfdaemon/constant"
32-
"github.com/dragonflyoss/Dragonfly/version"
31+
3332
"github.com/mitchellh/mapstructure"
3433
"github.com/pkg/errors"
35-
"gopkg.in/yaml.v2"
36-
3734
"github.com/sirupsen/logrus"
3835
"github.com/spf13/cobra"
3936
"github.com/spf13/viper"
37+
"gopkg.in/yaml.v2"
4038
)
4139

4240
var rootCmd = &cobra.Command{
@@ -45,11 +43,6 @@ var rootCmd = &cobra.Command{
4543
Long: "The dfdaemon is a proxy between container engine and registry used for pulling images.",
4644
DisableAutoGenTag: true, // disable displaying auto generation tag in cli docs
4745
RunE: func(cmd *cobra.Command, args []string) error {
48-
if viper.GetBool("version") {
49-
fmt.Println("dfdaemon version:", version.DFDaemonVersion)
50-
return nil
51-
}
52-
5346
if err := readConfigFile(viper.GetViper(), cmd); err != nil {
5447
return errors.Wrap(err, "read config file")
5548
}
@@ -83,7 +76,6 @@ func init() {
8376

8477
rf := rootCmd.Flags()
8578

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

8981
rf.Bool("verbose", false, "verbose")

cmd/dfdaemon/app/version.go

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
package app
2+
3+
import (
4+
"fmt"
5+
6+
"github.com/dragonflyoss/Dragonfly/version"
7+
8+
"github.com/spf13/cobra"
9+
)
10+
11+
// versionDescription is used to describe version command in detail and auto generate command doc.
12+
var versionDescription = "Display the version and build information of Dragonfly dfdaemon, " +
13+
"including GoVersion, OS, Arch, Version, BuildDate and GitCommit."
14+
15+
var versionCmd = &cobra.Command{
16+
Use: "version",
17+
Short: "Show the current version of dfdaemon",
18+
Long: versionDescription,
19+
SilenceErrors: true,
20+
SilenceUsage: true,
21+
RunE: func(cmd *cobra.Command, args []string) error {
22+
fmt.Println(version.Print("dfdaemon"))
23+
return nil
24+
},
25+
Example: versionExample(),
26+
}
27+
28+
func init() {
29+
rootCmd.AddCommand(versionCmd)
30+
}
31+
32+
// versionExample shows examples in version command, and is used in auto-generated cli docs.
33+
func versionExample() string {
34+
return `dfdaemon, version 0.4.1
35+
Git commit: 6fd5c8f
36+
Build date: 20190717-15:57:52
37+
Go version: go1.12.6
38+
OS/Arch: linux/amd64
39+
`
40+
}

0 commit comments

Comments
 (0)