mirror of
https://github.com/containers/podman.git
synced 2025-06-20 00:51:16 +08:00
Refactor version handling in cmd tree
* Move from simple string to semver objects * Change client API Version from '1' to 2.0.0 Signed-off-by: Jhon Honce <jhonce@redhat.com>
This commit is contained in:
@ -63,7 +63,7 @@ var (
|
|||||||
PersistentPreRunE: persistentPreRunE,
|
PersistentPreRunE: persistentPreRunE,
|
||||||
RunE: validate.SubCommandExists,
|
RunE: validate.SubCommandExists,
|
||||||
PersistentPostRunE: persistentPostRunE,
|
PersistentPostRunE: persistentPostRunE,
|
||||||
Version: version.Version,
|
Version: version.Version.String(),
|
||||||
}
|
}
|
||||||
|
|
||||||
logLevels = []string{"debug", "info", "warn", "error", "fatal", "panic"}
|
logLevels = []string{"debug", "info", "warn", "error", "fatal", "panic"}
|
||||||
|
@ -83,7 +83,7 @@ func version(cmd *cobra.Command, args []string) error {
|
|||||||
|
|
||||||
func formatVersion(writer io.Writer, version *define.Version) {
|
func formatVersion(writer io.Writer, version *define.Version) {
|
||||||
fmt.Fprintf(writer, "Version:\t%s\n", version.Version)
|
fmt.Fprintf(writer, "Version:\t%s\n", version.Version)
|
||||||
fmt.Fprintf(writer, "API Version:\t%d\n", version.APIVersion)
|
fmt.Fprintf(writer, "API Version:\t%s\n", version.APIVersion)
|
||||||
fmt.Fprintf(writer, "Go Version:\t%s\n", version.GoVersion)
|
fmt.Fprintf(writer, "Go Version:\t%s\n", version.GoVersion)
|
||||||
if version.GitCommit != "" {
|
if version.GitCommit != "" {
|
||||||
fmt.Fprintf(writer, "Git Commit:\t%s\n", version.GitCommit)
|
fmt.Fprintf(writer, "Git Commit:\t%s\n", version.GitCommit)
|
||||||
|
@ -27,7 +27,7 @@ LAST_TAG=$(git describe --tags --abbrev=0)
|
|||||||
write_go_version()
|
write_go_version()
|
||||||
{
|
{
|
||||||
LOCAL_VERSION="$1"
|
LOCAL_VERSION="$1"
|
||||||
sed -i "s/^\(const Version = \"\).*/\1${LOCAL_VERSION}\"/" version/version.go
|
sed -i "s/^\(var Version = semver.MustParse\( \"\).*/\1${LOCAL_VERSION}\"\)/" version/version.go
|
||||||
}
|
}
|
||||||
|
|
||||||
write_spec_version()
|
write_spec_version()
|
||||||
|
@ -18,9 +18,9 @@ var (
|
|||||||
buildInfo string
|
buildInfo string
|
||||||
)
|
)
|
||||||
|
|
||||||
// Version is an output struct for varlink
|
// Version is an output struct for API
|
||||||
type Version struct {
|
type Version struct {
|
||||||
APIVersion int64
|
APIVersion string
|
||||||
Version string
|
Version string
|
||||||
GoVersion string
|
GoVersion string
|
||||||
GitCommit string
|
GitCommit string
|
||||||
@ -29,7 +29,7 @@ type Version struct {
|
|||||||
OsArch string
|
OsArch string
|
||||||
}
|
}
|
||||||
|
|
||||||
// GetVersion returns a VersionOutput struct for varlink and podman
|
// GetVersion returns a VersionOutput struct for API and podman
|
||||||
func GetVersion() (Version, error) {
|
func GetVersion() (Version, error) {
|
||||||
var err error
|
var err error
|
||||||
var buildTime int64
|
var buildTime int64
|
||||||
@ -42,8 +42,8 @@ func GetVersion() (Version, error) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
return Version{
|
return Version{
|
||||||
APIVersion: podmanVersion.APIVersion,
|
APIVersion: podmanVersion.APIVersion.String(),
|
||||||
Version: podmanVersion.Version,
|
Version: podmanVersion.Version.String(),
|
||||||
GoVersion: runtime.Version(),
|
GoVersion: runtime.Version(),
|
||||||
GitCommit: gitCommit,
|
GitCommit: gitCommit,
|
||||||
BuiltTime: time.Unix(buildTime, 0).Format(time.ANSIC),
|
BuiltTime: time.Unix(buildTime, 0).Format(time.ANSIC),
|
||||||
|
@ -22,5 +22,5 @@ var (
|
|||||||
PFalse = &pFalse
|
PFalse = &pFalse
|
||||||
|
|
||||||
// APIVersion - podman will fail to run if this value is wrong
|
// APIVersion - podman will fail to run if this value is wrong
|
||||||
APIVersion = semver.MustParse("1.0.0")
|
APIVersion = semver.MustParse("2.0.0")
|
||||||
)
|
)
|
||||||
|
@ -118,10 +118,10 @@ func Version(ctx context.Context) (*entities.SystemVersionReport, error) {
|
|||||||
if err = response.Process(&component); err != nil {
|
if err = response.Process(&component); err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
f, _ := strconv.ParseFloat(component.APIVersion, 64)
|
|
||||||
b, _ := time.Parse(time.RFC3339, component.BuildTime)
|
b, _ := time.Parse(time.RFC3339, component.BuildTime)
|
||||||
report.Server = &define.Version{
|
report.Server = &define.Version{
|
||||||
APIVersion: int64(f),
|
APIVersion: component.APIVersion,
|
||||||
Version: component.Version.Version,
|
Version: component.Version.Version,
|
||||||
GoVersion: component.GoVersion,
|
GoVersion: component.GoVersion,
|
||||||
GitCommit: component.GitCommit,
|
GitCommit: component.GitCommit,
|
||||||
@ -129,6 +129,12 @@ func Version(ctx context.Context) (*entities.SystemVersionReport, error) {
|
|||||||
Built: b.Unix(),
|
Built: b.Unix(),
|
||||||
OsArch: fmt.Sprintf("%s/%s", component.Os, component.Arch),
|
OsArch: fmt.Sprintf("%s/%s", component.Os, component.Arch),
|
||||||
}
|
}
|
||||||
|
|
||||||
|
for _, c := range component.Components {
|
||||||
|
if c.Name == "Podman Engine" {
|
||||||
|
report.Server.APIVersion = c.Details["APIVersion"]
|
||||||
|
}
|
||||||
|
}
|
||||||
return &report, err
|
return &report, err
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -22,7 +22,7 @@ func (ic *ContainerEngine) VarlinkService(_ context.Context, opts entities.Servi
|
|||||||
service, err := varlink.NewService(
|
service, err := varlink.NewService(
|
||||||
"Atomic",
|
"Atomic",
|
||||||
"podman",
|
"podman",
|
||||||
version.Version,
|
version.Version.String(),
|
||||||
"https://github.com/containers/podman",
|
"https://github.com/containers/podman",
|
||||||
)
|
)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
@ -256,7 +256,7 @@ func executeContainerTemplate(info *containerInfo, options entities.GenerateSyst
|
|||||||
}
|
}
|
||||||
|
|
||||||
if info.PodmanVersion == "" {
|
if info.PodmanVersion == "" {
|
||||||
info.PodmanVersion = version.Version
|
info.PodmanVersion = version.Version.String()
|
||||||
}
|
}
|
||||||
if info.GenerateTimestamp {
|
if info.GenerateTimestamp {
|
||||||
info.TimeStamp = fmt.Sprintf("%v", time.Now().Format(time.UnixDate))
|
info.TimeStamp = fmt.Sprintf("%v", time.Now().Format(time.UnixDate))
|
||||||
|
@ -299,7 +299,7 @@ func executePodTemplate(info *podInfo, options entities.GenerateSystemdOptions)
|
|||||||
info.ExecStopPost = "{{.Executable}} pod rm --ignore -f --pod-id-file {{.PodIDFile}}"
|
info.ExecStopPost = "{{.Executable}} pod rm --ignore -f --pod-id-file {{.PodIDFile}}"
|
||||||
}
|
}
|
||||||
if info.PodmanVersion == "" {
|
if info.PodmanVersion == "" {
|
||||||
info.PodmanVersion = version.Version
|
info.PodmanVersion = version.Version.String()
|
||||||
}
|
}
|
||||||
if info.GenerateTimestamp {
|
if info.GenerateTimestamp {
|
||||||
info.TimeStamp = fmt.Sprintf("%v", time.Now().Format(time.UnixDate))
|
info.TimeStamp = fmt.Sprintf("%v", time.Now().Format(time.UnixDate))
|
||||||
|
@ -37,21 +37,21 @@ var _ = Describe("Podman version", func() {
|
|||||||
session := podmanTest.Podman([]string{"version"})
|
session := podmanTest.Podman([]string{"version"})
|
||||||
session.WaitWithDefaultTimeout()
|
session.WaitWithDefaultTimeout()
|
||||||
Expect(session).Should(Exit(0))
|
Expect(session).Should(Exit(0))
|
||||||
Expect(session.Out.Contents()).Should(ContainSubstring(version.Version))
|
Expect(session.Out.Contents()).Should(ContainSubstring(version.Version.String()))
|
||||||
})
|
})
|
||||||
|
|
||||||
It("podman -v", func() {
|
It("podman -v", func() {
|
||||||
session := podmanTest.Podman([]string{"-v"})
|
session := podmanTest.Podman([]string{"-v"})
|
||||||
session.WaitWithDefaultTimeout()
|
session.WaitWithDefaultTimeout()
|
||||||
Expect(session).Should(Exit(0))
|
Expect(session).Should(Exit(0))
|
||||||
Expect(session.Out.Contents()).Should(ContainSubstring(version.Version))
|
Expect(session.Out.Contents()).Should(ContainSubstring(version.Version.String()))
|
||||||
})
|
})
|
||||||
|
|
||||||
It("podman --version", func() {
|
It("podman --version", func() {
|
||||||
session := podmanTest.Podman([]string{"--version"})
|
session := podmanTest.Podman([]string{"--version"})
|
||||||
session.WaitWithDefaultTimeout()
|
session.WaitWithDefaultTimeout()
|
||||||
Expect(session).Should(Exit(0))
|
Expect(session).Should(Exit(0))
|
||||||
Expect(session.Out.Contents()).Should(ContainSubstring(version.Version))
|
Expect(session.Out.Contents()).Should(ContainSubstring(version.Version.String()))
|
||||||
})
|
})
|
||||||
|
|
||||||
It("podman version --format json", func() {
|
It("podman version --format json", func() {
|
||||||
|
@ -1,12 +1,16 @@
|
|||||||
package version
|
package version
|
||||||
|
|
||||||
|
import (
|
||||||
|
"github.com/blang/semver"
|
||||||
|
)
|
||||||
|
|
||||||
// Version is the version of the build.
|
// Version is the version of the build.
|
||||||
// NOTE: remember to bump the version at the top
|
// NOTE: remember to bump the version at the top
|
||||||
// of the top-level README.md file when this is
|
// of the top-level README.md file when this is
|
||||||
// bumped.
|
// bumped.
|
||||||
const Version = "2.1.0-dev"
|
var Version = semver.MustParse("2.1.0-dev")
|
||||||
|
|
||||||
// APIVersion is the version for the remote
|
// APIVersion is the version for the remote
|
||||||
// client API. It is used to determine compatibility
|
// client API. It is used to determine compatibility
|
||||||
// between a remote podman client and its backend
|
// between a remote podman client and its backend
|
||||||
const APIVersion = 1
|
var APIVersion = semver.MustParse("2.0.0")
|
||||||
|
Reference in New Issue
Block a user