new version format and some cleanup

This commit is contained in:
Anand Babu (AB) Periasamy 2015-09-18 23:27:04 -07:00
parent 2141c9f70f
commit d1f1b7ac31
10 changed files with 109 additions and 151 deletions

View File

@ -47,13 +47,13 @@ test: build
gomake-all: build
@GO15VENDOREXPERIMENT=1 go install github.com/minio/minio
release: genversion
@echo "Installing minio for new version.go:"
release: version
@echo "Installing minio (new version):"
@GO15VENDOREXPERIMENT=1 go install github.com/minio/minio
genversion:
@echo "Generating new minio version.go"
@cd ./pkg/version; go run genversion.go; cd - 1>/dev/null
version:
@echo "Generating new version.go"
@GO15VENDOREXPERIMENT=1 go run buildscripts/genversion.go
pkg-remove:
@GO15VENDOREXPERIMENT=1 govendor remove $(PKG)

View 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
View File

@ -18,33 +18,29 @@ package main
import (
"fmt"
"net/http"
"os"
"os/user"
"runtime"
"strconv"
"time"
"github.com/dustin/go-humanize"
"github.com/minio/cli"
"github.com/minio/minio/pkg/version"
)
func init() {
// Check for the environment early on and gracefuly report.
u, err := user.Current()
_, err := user.Current()
if err != nil {
Fatalf("Unable to obtain user's home directory. \nError: %s\n", err)
}
var uid int
uid, err = strconv.Atoi(u.Uid)
if err != nil {
Fatalf("Unable to convert user id to an integer. \nError: %s\n", err)
if os.Geteuid() == 0 {
Fatalln("Please run minio as a non-root user.")
}
if uid == 0 {
Fatalln("Please run as a normal user, running as root is disallowed")
}
verifyMinioRuntime()
// Check if minio was compiled using a supported version of Golang.
checkGolangRuntimeVersion()
}
// 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 {
var closestCommands []string
for _, value := range commandsTree.PrefixMatch(command) {
@ -134,14 +115,14 @@ GLOBAL FLAGS:
{{range .Flags}}{{.}}
{{end}}{{end}}
VERSION:
` + getFormattedVersion() +
` + minioVersion +
`{{range $key, $value := ExtraInfo}}
{{$key}}:
{{$value}}
{{end}}
`
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)
if len(closestCommands) > 0 {
msg += fmt.Sprintf("\n\nDid you mean one of these?\n")

View File

@ -22,11 +22,9 @@ import (
"encoding/json"
"encoding/xml"
"net/http"
"runtime"
"strconv"
"github.com/minio/minio/pkg/donut"
"github.com/minio/minio/pkg/version"
)
// No encoder interface exists, so we create one.
@ -53,7 +51,10 @@ func generateRequestID() []byte {
func setCommonHeaders(w http.ResponseWriter, acceptsType string, contentLength int) {
// set unique request ID for each reply
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("Content-Type", acceptsType)
w.Header().Set("Connection", "close")

View File

@ -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()
}

View File

@ -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"

View File

@ -93,8 +93,3 @@ func checkGolangRuntimeVersion() {
Errorln("Old Golang runtime version " + v1.String() + " detected., mc requires minimum go1.5.1 or later.")
}
}
func verifyMinioRuntime() {
// add any other checks here.
checkGolangRuntimeVersion()
}

View File

@ -16,13 +16,7 @@
package main
import (
"net/http"
"time"
"github.com/minio/cli"
"github.com/minio/minio/pkg/version"
)
import "github.com/minio/cli"
var versionCmd = cli.Command{
Name: "version",
@ -40,10 +34,6 @@ EXAMPLES:
}
func mainVersion(ctxx *cli.Context) {
t, _ := time.Parse(time.RFC3339Nano, version.Version)
if t.IsZero() {
Println("")
return
}
Println(t.Format(http.TimeFormat))
Println("Version: " + minioVersion)
Println("Release-Tag: " + minioReleaseTag)
}

7
version.go Normal file
View 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"

View File

@ -14,14 +14,13 @@
* limitations under the License.
*/
package version_test
package main
import (
"net/http"
"testing"
"time"
"github.com/minio/minio/pkg/version"
. "gopkg.in/check.v1"
)
@ -32,6 +31,6 @@ type MySuite struct{}
var _ = Suite(&MySuite{})
func (s *MySuite) TestVersion(c *C) {
_, err := time.Parse(version.Version, time.RFC3339Nano)
_, err := time.Parse(minioVersion, http.TimeFormat)
c.Assert(err, NotNil)
}