forked from LaconicNetwork/kompose
Merge pull request #864 from cdrage/update-versions
Move version information to separate file
This commit is contained in:
commit
a567cfff4a
2
Makefile
2
Makefile
@ -15,7 +15,7 @@
|
|||||||
|
|
||||||
|
|
||||||
GITCOMMIT := $(shell git rev-parse --short HEAD)
|
GITCOMMIT := $(shell git rev-parse --short HEAD)
|
||||||
BUILD_FLAGS := -ldflags="-w -X github.com/kubernetes/kompose/cmd.GITCOMMIT=$(GITCOMMIT)"
|
BUILD_FLAGS := -ldflags="-w -X github.com/kubernetes/kompose/pkg/version.GITCOMMIT=$(GITCOMMIT)"
|
||||||
PKGS = $(shell glide novendor)
|
PKGS = $(shell glide novendor)
|
||||||
TEST_IMAGE := kompose/tests:latest
|
TEST_IMAGE := kompose/tests:latest
|
||||||
|
|
||||||
|
|||||||
@ -19,24 +19,17 @@ package cmd
|
|||||||
import (
|
import (
|
||||||
"fmt"
|
"fmt"
|
||||||
|
|
||||||
|
"github.com/kubernetes/kompose/pkg/version"
|
||||||
"github.com/spf13/cobra"
|
"github.com/spf13/cobra"
|
||||||
)
|
)
|
||||||
|
|
||||||
var (
|
|
||||||
// VERSION is version number that wil be displayed when running ./kompose version
|
|
||||||
VERSION = "1.4.0"
|
|
||||||
// GITCOMMIT is hash of the commit that wil be displayed when running ./kompose version
|
|
||||||
// this will be overwritten when running build like this: go build -ldflags="-X github.com/kubernetes/kompose/cmd.GITCOMMIT=$(GITCOMMIT)"
|
|
||||||
// HEAD is default indicating that this was not set during build
|
|
||||||
GITCOMMIT = "HEAD"
|
|
||||||
)
|
|
||||||
|
|
||||||
// versionCmd represents the version command
|
// versionCmd represents the version command
|
||||||
var versionCmd = &cobra.Command{
|
var versionCmd = &cobra.Command{
|
||||||
Use: "version",
|
Use: "version",
|
||||||
Short: "Print the version of Kompose",
|
Short: "Print the version of Kompose",
|
||||||
Run: func(cmd *cobra.Command, args []string) {
|
Run: func(cmd *cobra.Command, args []string) {
|
||||||
fmt.Println(VERSION + " (" + GITCOMMIT + ")")
|
// See pkg/version/version.go for more information as to why we use the git commit / hash value
|
||||||
|
fmt.Println(version.VERSION + " (" + version.GITCOMMIT + ")")
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@ -31,6 +31,8 @@ import (
|
|||||||
|
|
||||||
"github.com/kubernetes/kompose/pkg/utils/docker"
|
"github.com/kubernetes/kompose/pkg/utils/docker"
|
||||||
|
|
||||||
|
"github.com/kubernetes/kompose/pkg/version"
|
||||||
|
|
||||||
"github.com/pkg/errors"
|
"github.com/pkg/errors"
|
||||||
"k8s.io/kubernetes/pkg/api"
|
"k8s.io/kubernetes/pkg/api"
|
||||||
)
|
)
|
||||||
@ -117,13 +119,19 @@ func ConfigAnnotations(service kobject.ServiceConfig) map[string]string {
|
|||||||
annotations[key] = value
|
annotations[key] = value
|
||||||
}
|
}
|
||||||
annotations["kompose.cmd"] = strings.Join(os.Args, " ")
|
annotations["kompose.cmd"] = strings.Join(os.Args, " ")
|
||||||
version := exec.Command("kompose", "version")
|
versionCmd := exec.Command("kompose", "version")
|
||||||
out, err := version.Output()
|
out, err := versionCmd.Output()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
errors.Wrap(err, "Failed to get kompose version")
|
errors.Wrap(err, "Failed to get kompose version")
|
||||||
|
|
||||||
}
|
}
|
||||||
annotations["kompose.version"] = strings.Trim(string(out), " \n")
|
annotations["kompose.version"] = strings.Trim(string(out), " \n")
|
||||||
|
|
||||||
|
// If the version is blank (couldn't retrieve the kompose version for whatever reason)
|
||||||
|
if annotations["kompose.version"] == "" {
|
||||||
|
annotations["kompose.version"] = version.VERSION + " (" + version.GITCOMMIT + ")"
|
||||||
|
}
|
||||||
|
|
||||||
return annotations
|
return annotations
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
10
pkg/version/version.go
Normal file
10
pkg/version/version.go
Normal file
@ -0,0 +1,10 @@
|
|||||||
|
package version
|
||||||
|
|
||||||
|
var (
|
||||||
|
// VERSION is version number that wil be displayed when running ./kompose version
|
||||||
|
VERSION = "1.4.0"
|
||||||
|
// GITCOMMIT is hash of the commit that wil be displayed when running ./kompose version
|
||||||
|
// this will be overwritten when running build like this: go build -ldflags="-X github.com/kubernetes/kompose/pkg/version.GITCOMMIT=$(GITCOMMIT)"
|
||||||
|
// HEAD is default indicating that this was not set during build
|
||||||
|
GITCOMMIT = "HEAD"
|
||||||
|
)
|
||||||
@ -91,8 +91,8 @@ init_sync() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
replaceversion() {
|
replaceversion() {
|
||||||
echo "Replaced version in version.go"
|
echo "Replaced version in pkg/version/version.go"
|
||||||
sed -i "s/$1/$2/g" cmd/version.go
|
sed -i "s/$1/$2/g" pkg/version/version.go
|
||||||
|
|
||||||
echo "Replaced version in README.md"
|
echo "Replaced version in README.md"
|
||||||
sed -i "s/$1/$2/g" README.md
|
sed -i "s/$1/$2/g" README.md
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user