mirror of
https://github.com/minio/minio.git
synced 2024-12-25 22:55:54 -05:00
Merge pull request #849 from abperiasamy/version-format
new version format and some cleanup
This commit is contained in:
commit
ec0fdf95e5
10
Makefile
10
Makefile
@ -47,13 +47,13 @@ test: build
|
|||||||
gomake-all: build
|
gomake-all: build
|
||||||
@GO15VENDOREXPERIMENT=1 go install github.com/minio/minio
|
@GO15VENDOREXPERIMENT=1 go install github.com/minio/minio
|
||||||
|
|
||||||
release: genversion
|
release: version
|
||||||
@echo "Installing minio for new version.go:"
|
@echo "Installing minio (new version):"
|
||||||
@GO15VENDOREXPERIMENT=1 go install github.com/minio/minio
|
@GO15VENDOREXPERIMENT=1 go install github.com/minio/minio
|
||||||
|
|
||||||
genversion:
|
version:
|
||||||
@echo "Generating new minio version.go"
|
@echo "Generating new version.go"
|
||||||
@cd ./pkg/version; go run genversion.go; cd - 1>/dev/null
|
@GO15VENDOREXPERIMENT=1 go run buildscripts/genversion.go
|
||||||
|
|
||||||
pkg-remove:
|
pkg-remove:
|
||||||
@GO15VENDOREXPERIMENT=1 govendor remove $(PKG)
|
@GO15VENDOREXPERIMENT=1 govendor remove $(PKG)
|
||||||
|
77
buildscripts/genversion.go
Normal file
77
buildscripts/genversion.go
Normal file
@ -0,0 +1,77 @@
|
|||||||
|
// +build ignore
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Minio Cloud Storage, (C) 2015 Minio, Inc.
|
||||||
|
*
|
||||||
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
|
* you may not use this file except in compliance with the License.
|
||||||
|
* You may obtain a copy of the License at
|
||||||
|
*
|
||||||
|
* http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
*
|
||||||
|
* Unless required by applicable law or agreed to in writing, software
|
||||||
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
|
* See the License for the specific language governing permissions and
|
||||||
|
* limitations under the License.
|
||||||
|
*/
|
||||||
|
|
||||||
|
package main
|
||||||
|
|
||||||
|
import (
|
||||||
|
"fmt"
|
||||||
|
"net/http"
|
||||||
|
"os"
|
||||||
|
"strings"
|
||||||
|
"text/template"
|
||||||
|
"time"
|
||||||
|
)
|
||||||
|
|
||||||
|
var versionTemplate = `// -------- DO NOT EDIT --------
|
||||||
|
// This file is autogenerated by genversion.go during the release process.
|
||||||
|
|
||||||
|
package main
|
||||||
|
|
||||||
|
const minioVersion = {{if .Version}}"{{.Version}}"{{else}}""{{end}}
|
||||||
|
const minioReleaseTag = {{if .ReleaseTag}}"{{.ReleaseTag}}"{{else}}""{{end}}
|
||||||
|
`
|
||||||
|
|
||||||
|
// genVersion generates ‘version.go’.
|
||||||
|
func genVersion(version string) {
|
||||||
|
t := template.Must(template.New("version").Parse(versionTemplate))
|
||||||
|
versionFile, err := os.OpenFile("version.go", os.O_WRONLY|os.O_CREATE|os.O_TRUNC, 0600)
|
||||||
|
if err != nil {
|
||||||
|
fmt.Println("genversion: Unable to generate ‘version.go’. Error: %s.", err)
|
||||||
|
os.Exit(1)
|
||||||
|
}
|
||||||
|
defer versionFile.Close()
|
||||||
|
|
||||||
|
err = t.Execute(versionFile, struct {
|
||||||
|
Version string
|
||||||
|
ReleaseTag string
|
||||||
|
}{version, genReleaseTag(version)})
|
||||||
|
|
||||||
|
if err != nil {
|
||||||
|
fmt.Println("genversion: Unable to generate ‘version.go’. Error: %s.", err)
|
||||||
|
os.Exit(1)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// genReleaseTag prints release tag to the console for easy git tagging.
|
||||||
|
func genReleaseTag(version string) string {
|
||||||
|
relTag := strings.Replace(version, " ", "-", -1)
|
||||||
|
relTag = strings.Replace(relTag, ":", "-", -1)
|
||||||
|
relTag = strings.Replace(relTag, ",", "", -1)
|
||||||
|
return "RELEASE." + relTag
|
||||||
|
}
|
||||||
|
|
||||||
|
func main() {
|
||||||
|
// Version is in HTTP TimeFormat.
|
||||||
|
version := time.Now().UTC().Format(http.TimeFormat)
|
||||||
|
|
||||||
|
// generate ‘version.go’ file.
|
||||||
|
genVersion(version)
|
||||||
|
|
||||||
|
fmt.Println("Version: \"" + version + "\"")
|
||||||
|
fmt.Println("Release-Tag: " + genReleaseTag(version))
|
||||||
|
}
|
39
main.go
39
main.go
@ -18,33 +18,29 @@ package main
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"fmt"
|
"fmt"
|
||||||
"net/http"
|
|
||||||
"os"
|
"os"
|
||||||
"os/user"
|
"os/user"
|
||||||
"runtime"
|
"runtime"
|
||||||
"strconv"
|
"strconv"
|
||||||
"time"
|
|
||||||
|
|
||||||
"github.com/dustin/go-humanize"
|
"github.com/dustin/go-humanize"
|
||||||
"github.com/minio/cli"
|
"github.com/minio/cli"
|
||||||
"github.com/minio/minio/pkg/version"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
func init() {
|
func init() {
|
||||||
// Check for the environment early on and gracefuly report.
|
// Check for the environment early on and gracefuly report.
|
||||||
u, err := user.Current()
|
|
||||||
|
_, err := user.Current()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
Fatalf("Unable to obtain user's home directory. \nError: %s\n", err)
|
Fatalf("Unable to obtain user's home directory. \nError: %s\n", err)
|
||||||
}
|
}
|
||||||
var uid int
|
|
||||||
uid, err = strconv.Atoi(u.Uid)
|
if os.Geteuid() == 0 {
|
||||||
if err != nil {
|
Fatalln("Please run ‘minio’ as a non-root user.")
|
||||||
Fatalf("Unable to convert user id to an integer. \nError: %s\n", err)
|
|
||||||
}
|
}
|
||||||
if uid == 0 {
|
|
||||||
Fatalln("Please run as a normal user, running as root is disallowed")
|
// Check if minio was compiled using a supported version of Golang.
|
||||||
}
|
checkGolangRuntimeVersion()
|
||||||
verifyMinioRuntime()
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Tries to get os/arch/platform specific information
|
// Tries to get os/arch/platform specific information
|
||||||
@ -73,21 +69,6 @@ func getSystemData() map[string]string {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func init() {
|
|
||||||
if _, err := user.Current(); err != nil {
|
|
||||||
Fatalf("Unable to determine current user. Reason: %s\n", err)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// getFormattedVersion -
|
|
||||||
func getFormattedVersion() string {
|
|
||||||
t, _ := time.Parse(time.RFC3339Nano, version.Version)
|
|
||||||
if t.IsZero() {
|
|
||||||
return ""
|
|
||||||
}
|
|
||||||
return t.Format(http.TimeFormat)
|
|
||||||
}
|
|
||||||
|
|
||||||
func findClosestCommands(command string) []string {
|
func findClosestCommands(command string) []string {
|
||||||
var closestCommands []string
|
var closestCommands []string
|
||||||
for _, value := range commandsTree.PrefixMatch(command) {
|
for _, value := range commandsTree.PrefixMatch(command) {
|
||||||
@ -134,14 +115,14 @@ GLOBAL FLAGS:
|
|||||||
{{range .Flags}}{{.}}
|
{{range .Flags}}{{.}}
|
||||||
{{end}}{{end}}
|
{{end}}{{end}}
|
||||||
VERSION:
|
VERSION:
|
||||||
` + getFormattedVersion() +
|
` + minioVersion +
|
||||||
`{{range $key, $value := ExtraInfo}}
|
`{{range $key, $value := ExtraInfo}}
|
||||||
{{$key}}:
|
{{$key}}:
|
||||||
{{$value}}
|
{{$value}}
|
||||||
{{end}}
|
{{end}}
|
||||||
`
|
`
|
||||||
app.CommandNotFound = func(ctx *cli.Context, command string) {
|
app.CommandNotFound = func(ctx *cli.Context, command string) {
|
||||||
msg := fmt.Sprintf("‘%s’ is not a mc command. See ‘minio help’.", command)
|
msg := fmt.Sprintf("‘%s’ is not a minio sub-command. See ‘minio help’.", command)
|
||||||
closestCommands := findClosestCommands(command)
|
closestCommands := findClosestCommands(command)
|
||||||
if len(closestCommands) > 0 {
|
if len(closestCommands) > 0 {
|
||||||
msg += fmt.Sprintf("\n\nDid you mean one of these?\n")
|
msg += fmt.Sprintf("\n\nDid you mean one of these?\n")
|
||||||
|
@ -19,8 +19,6 @@ package rpc
|
|||||||
import (
|
import (
|
||||||
"net/http"
|
"net/http"
|
||||||
"runtime"
|
"runtime"
|
||||||
|
|
||||||
"github.com/minio/minio/pkg/version"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
// VersionArgs basic json RPC params
|
// VersionArgs basic json RPC params
|
||||||
@ -40,7 +38,8 @@ type VersionReply struct {
|
|||||||
// Get version
|
// Get version
|
||||||
func (v *VersionService) Get(r *http.Request, args *VersionArgs, reply *VersionReply) error {
|
func (v *VersionService) Get(r *http.Request, args *VersionArgs, reply *VersionReply) error {
|
||||||
reply.Version = "0.0.1"
|
reply.Version = "0.0.1"
|
||||||
reply.BuildDate = version.Version
|
//TODO: Better approach needed here to pass global states like version. --ab.
|
||||||
|
// reply.BuildDate = version.Version
|
||||||
reply.Architecture = runtime.GOARCH
|
reply.Architecture = runtime.GOARCH
|
||||||
reply.OperatingSystem = runtime.GOOS
|
reply.OperatingSystem = runtime.GOOS
|
||||||
return nil
|
return nil
|
||||||
|
@ -22,11 +22,9 @@ import (
|
|||||||
"encoding/json"
|
"encoding/json"
|
||||||
"encoding/xml"
|
"encoding/xml"
|
||||||
"net/http"
|
"net/http"
|
||||||
"runtime"
|
|
||||||
"strconv"
|
"strconv"
|
||||||
|
|
||||||
"github.com/minio/minio/pkg/donut"
|
"github.com/minio/minio/pkg/donut"
|
||||||
"github.com/minio/minio/pkg/version"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
// No encoder interface exists, so we create one.
|
// No encoder interface exists, so we create one.
|
||||||
@ -53,7 +51,10 @@ func generateRequestID() []byte {
|
|||||||
func setCommonHeaders(w http.ResponseWriter, acceptsType string, contentLength int) {
|
func setCommonHeaders(w http.ResponseWriter, acceptsType string, contentLength int) {
|
||||||
// set unique request ID for each reply
|
// set unique request ID for each reply
|
||||||
w.Header().Set("X-Amz-Request-Id", string(generateRequestID()))
|
w.Header().Set("X-Amz-Request-Id", string(generateRequestID()))
|
||||||
w.Header().Set("Server", ("Minio/" + version.Version + " (" + runtime.GOOS + ";" + runtime.GOARCH + ")"))
|
|
||||||
|
// TODO: Modularity comes in the way of passing global state like "version". A better approach needed here. -ab
|
||||||
|
// w.Header().Set("Server", ("Minio/" + version + " (" + runtime.GOOS + ";" + runtime.GOARCH + ")"))
|
||||||
|
|
||||||
w.Header().Set("Accept-Ranges", "bytes")
|
w.Header().Set("Accept-Ranges", "bytes")
|
||||||
w.Header().Set("Content-Type", acceptsType)
|
w.Header().Set("Content-Type", acceptsType)
|
||||||
w.Header().Set("Connection", "close")
|
w.Header().Set("Connection", "close")
|
||||||
|
@ -1,85 +0,0 @@
|
|||||||
// +build ignore
|
|
||||||
|
|
||||||
/*
|
|
||||||
* Minio Cloud Storage, (C) 2015 Minio, Inc.
|
|
||||||
*
|
|
||||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
||||||
* you may not use this file except in compliance with the License.
|
|
||||||
* You may obtain a copy of the License at
|
|
||||||
*
|
|
||||||
* http://www.apache.org/licenses/LICENSE-2.0
|
|
||||||
*
|
|
||||||
* Unless required by applicable law or agreed to in writing, software
|
|
||||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
||||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
||||||
* See the License for the specific language governing permissions and
|
|
||||||
* limitations under the License.
|
|
||||||
*/
|
|
||||||
|
|
||||||
package main
|
|
||||||
|
|
||||||
import (
|
|
||||||
"fmt"
|
|
||||||
"net/http"
|
|
||||||
"os"
|
|
||||||
"text/template"
|
|
||||||
"time"
|
|
||||||
)
|
|
||||||
|
|
||||||
// Version version string
|
|
||||||
type Version struct {
|
|
||||||
Date string
|
|
||||||
}
|
|
||||||
|
|
||||||
func writeVersion(version Version) error {
|
|
||||||
var versionTemplate = `// -------- DO NOT EDIT --------
|
|
||||||
// This file is autogenerated by genversion.go during the release process.
|
|
||||||
|
|
||||||
package version
|
|
||||||
|
|
||||||
// Version autogenerated
|
|
||||||
const Version = {{if .Date}}"{{.Date}}"{{else}}""{{end}}
|
|
||||||
`
|
|
||||||
t := template.Must(template.New("version").Parse(versionTemplate))
|
|
||||||
versionFile, err := os.OpenFile("version.go", os.O_WRONLY|os.O_CREATE|os.O_TRUNC, 0600)
|
|
||||||
if err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
defer versionFile.Close()
|
|
||||||
err = t.Execute(versionFile, version)
|
|
||||||
if err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
return nil
|
|
||||||
}
|
|
||||||
|
|
||||||
func genVersion() {
|
|
||||||
t := time.Now().UTC()
|
|
||||||
date := t.Format(time.RFC3339Nano)
|
|
||||||
// Tag is of following format
|
|
||||||
//
|
|
||||||
// RELEASE.[WeekDay]-[Month]-[Day]-[Hour]-[Min]-[Sec]-GMT-[Year]
|
|
||||||
//
|
|
||||||
tag := fmt.Sprintf(
|
|
||||||
"RELEASE.%s-%s-%02d-%02d-%02d-%02d-GMT-%d",
|
|
||||||
t.Weekday().String()[0:3],
|
|
||||||
t.Month().String()[0:3],
|
|
||||||
t.Day(),
|
|
||||||
t.Hour(),
|
|
||||||
t.Minute(),
|
|
||||||
t.Second(),
|
|
||||||
t.Year())
|
|
||||||
fmt.Println("Release-Tag: " + tag)
|
|
||||||
fmt.Println("Release-Version: " + t.Format(http.TimeFormat))
|
|
||||||
version := Version{Date: date}
|
|
||||||
err := writeVersion(version)
|
|
||||||
if err != nil {
|
|
||||||
fmt.Print(err)
|
|
||||||
os.Exit(1)
|
|
||||||
}
|
|
||||||
fmt.Println("Successfully generated ‘version.go’")
|
|
||||||
}
|
|
||||||
|
|
||||||
func main() {
|
|
||||||
genVersion()
|
|
||||||
}
|
|
@ -1,7 +0,0 @@
|
|||||||
// -------- DO NOT EDIT --------
|
|
||||||
// This file is autogenerated by genversion.go during the release process.
|
|
||||||
|
|
||||||
package version
|
|
||||||
|
|
||||||
// Version autogenerated
|
|
||||||
const Version = "2015-08-14T03:23:47.250240049Z"
|
|
@ -93,8 +93,3 @@ func checkGolangRuntimeVersion() {
|
|||||||
Errorln("Old Golang runtime version ‘" + v1.String() + "’ detected., ‘mc’ requires minimum go1.5.1 or later.")
|
Errorln("Old Golang runtime version ‘" + v1.String() + "’ detected., ‘mc’ requires minimum go1.5.1 or later.")
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func verifyMinioRuntime() {
|
|
||||||
// add any other checks here.
|
|
||||||
checkGolangRuntimeVersion()
|
|
||||||
}
|
|
||||||
|
@ -16,13 +16,7 @@
|
|||||||
|
|
||||||
package main
|
package main
|
||||||
|
|
||||||
import (
|
import "github.com/minio/cli"
|
||||||
"net/http"
|
|
||||||
"time"
|
|
||||||
|
|
||||||
"github.com/minio/cli"
|
|
||||||
"github.com/minio/minio/pkg/version"
|
|
||||||
)
|
|
||||||
|
|
||||||
var versionCmd = cli.Command{
|
var versionCmd = cli.Command{
|
||||||
Name: "version",
|
Name: "version",
|
||||||
@ -40,10 +34,6 @@ EXAMPLES:
|
|||||||
}
|
}
|
||||||
|
|
||||||
func mainVersion(ctxx *cli.Context) {
|
func mainVersion(ctxx *cli.Context) {
|
||||||
t, _ := time.Parse(time.RFC3339Nano, version.Version)
|
Println("Version: " + minioVersion)
|
||||||
if t.IsZero() {
|
Println("Release-Tag: " + minioReleaseTag)
|
||||||
Println("")
|
|
||||||
return
|
|
||||||
}
|
|
||||||
Println(t.Format(http.TimeFormat))
|
|
||||||
}
|
}
|
||||||
|
7
version.go
Normal file
7
version.go
Normal file
@ -0,0 +1,7 @@
|
|||||||
|
// -------- DO NOT EDIT --------
|
||||||
|
// This file is autogenerated by genversion.go during the release process.
|
||||||
|
|
||||||
|
package main
|
||||||
|
|
||||||
|
const minioVersion = "Sat, 19 Sep 2015 06:15:16 GMT"
|
||||||
|
const minioReleaseTag = "RELEASE.Sat-19-Sep-2015-06-15-16-GMT"
|
@ -14,14 +14,13 @@
|
|||||||
* limitations under the License.
|
* limitations under the License.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
package version_test
|
package main
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"net/http"
|
||||||
"testing"
|
"testing"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
"github.com/minio/minio/pkg/version"
|
|
||||||
|
|
||||||
. "gopkg.in/check.v1"
|
. "gopkg.in/check.v1"
|
||||||
)
|
)
|
||||||
|
|
||||||
@ -32,6 +31,6 @@ type MySuite struct{}
|
|||||||
var _ = Suite(&MySuite{})
|
var _ = Suite(&MySuite{})
|
||||||
|
|
||||||
func (s *MySuite) TestVersion(c *C) {
|
func (s *MySuite) TestVersion(c *C) {
|
||||||
_, err := time.Parse(version.Version, time.RFC3339Nano)
|
_, err := time.Parse(minioVersion, http.TimeFormat)
|
||||||
c.Assert(err, NotNil)
|
c.Assert(err, NotNil)
|
||||||
}
|
}
|
Loading…
Reference in New Issue
Block a user