Skip to content

Commit

Permalink
remove hard coded version
Browse files Browse the repository at this point in the history
  • Loading branch information
medcl committed Jan 5, 2018
1 parent bb966da commit 528eed4
Show file tree
Hide file tree
Showing 14 changed files with 84 additions and 44 deletions.
1 change: 0 additions & 1 deletion .gitignore
Expand Up @@ -44,7 +44,6 @@ bin/
.DS_Store
/bin-run/
/leveldb
core/env/commit_log.go*
/dist
gopa
gopa.exe
1 change: 1 addition & 0 deletions CHANGES.md
Expand Up @@ -24,6 +24,7 @@
##### improvement
1. remove goleveldb due to memory leak
2. update logo
3. remove hard coded version
##### bugfix


Expand Down
81 changes: 54 additions & 27 deletions Makefile
@@ -1,10 +1,19 @@
SHELL=/bin/bash

# Default GOPA version
GOPA_VERSION := 0.10.0_SNAPSHOT

# Get release version from environment
ifneq "$(VERSION)" ""
GOPA_VERSION := $(VERSION)
endif

# Ensure GOPATH is set before running build process.
ifeq "$(GOPATH)" ""
$(error Please set the environment variable GOPATH before running `make`)
endif

# Go environment
CURDIR := $(shell pwd)
OLDGOPATH:= $(GOPATH)
NEWGOPATH:= $(CURDIR):$(CURDIR)/vendor:$(GOPATH)
Expand All @@ -24,26 +33,18 @@ PKGS=$(go list ./... | grep -v /vendor/)
default: build

build: config
@echo $(GOPATH)
@#echo $(GOPATH)
@echo $(NEWGOPATH)
$(GOBUILD) -o bin/gopa
$(MAKE) restore-generated-file

build-cluster-test: build
cd bin && mkdir node1 node2 node3 && cp gopa node1 && cp gopa node2 && cp gopa node3

# used to build the binary for gdb debugging
build-race: clean config update-ui
$(GOBUILD) -gcflags "-m -N -l" -race -o bin/gopa

update-ui:
$(GO) get github.com/infinitbyte/esc
(cd static&& esc -ignore="static.go|build_static.sh|.DS_Store" -o static.go -pkg static ../static )

update-template-ui:
$(GO) get github.com/infinitbyte/ego/cmd/ego
cd modules/ui/ && ego
cd modules/index/ui/ && ego
cd plugins/ && ego
$(MAKE) restore-generated-file

tar: build
cd bin && tar cfz ../bin/gopa.tar.gz gopa config gopa.yml
Expand All @@ -53,6 +54,8 @@ cross-build: clean config update-ui
GOOS=windows GOARCH=amd64 $(GOBUILD) -o bin/gopa-windows64.exe
GOOS=darwin GOARCH=amd64 $(GOBUILD) -o bin/gopa-darwin64
GOOS=linux GOARCH=amd64 $(GOBUILD) -o bin/gopa-linux64
$(MAKE) restore-generated-file


build-win:
CC=x86_64-w64-mingw32-gcc CXX=x86_64-w64-mingw32-g++ GOOS=windows GOARCH=amd64 $(GOBUILD) -o bin/gopa-windows64.exe
Expand All @@ -66,12 +69,6 @@ build-darwin:
GOOS=darwin GOARCH=amd64 $(GOBUILD) -o bin/gopa-darwin64
GOOS=darwin GOARCH=386 $(GOBUILD) -o bin/gopa-darwin32

all: clean config update-ui cross-build

all-platform: clean config update-ui cross-build-all-platform

cross-build-all-platform: clean config build-bsd build-linux build-darwin build-win

build-bsd:
GOOS=freebsd GOARCH=amd64 $(GOBUILD) -o bin/gopa-freebsd64
GOOS=freebsd GOARCH=386 $(GOBUILD) -o bin/gopa-freebsd32
Expand All @@ -80,6 +77,12 @@ build-bsd:
GOOS=openbsd GOARCH=amd64 $(GOBUILD) -o bin/gopa-openbsd64
GOOS=openbsd GOARCH=386 $(GOBUILD) -o bin/gopa-openbsd32

all: clean config update-ui cross-build restore-generated-file

all-platform: clean config update-ui cross-build-all-platform restore-generated-file

cross-build-all-platform: clean config build-bsd build-linux build-darwin build-win restore-generated-file

format:
gofmt -l -s -w .

Expand All @@ -92,21 +95,45 @@ clean: clean_data
rm -rif bin
mkdir bin

init-version:
@echo building GOPA $(GOPA_VERSION)


update-generated-file:
@echo "update generated info"
@echo -e "package env\nconst lastCommitLog =\""`git log -1 --pretty=format:"%h, %ad, %an, %s"` "\"\nconst buildDate =\"`date`\"" > core/env/generated.go
@echo -e "\nconst version =\"$(GOPA_VERSION)\"" >> core/env/generated.go


update-commit-log:
echo -e "package env\nconst lastCommitLog =\""`git log -1 --pretty=format:"%h, %ad, %an, %s"` "\"\nconst buildDate =\"`date`\"" > core/env/commit_log.go
restore-generated-file:
@echo "restore generated info"
@echo -e "package env\nconst lastCommitLog =\"N/A\"\nconst buildDate =\"N/A\"" > core/env/generated.go
@echo -e "\nconst version =\"0.0.1\"" >> core/env/generated.go


update-ui:
@echo "generate static files"
@$(GO) get github.com/infinitbyte/esc
@(cd static&& esc -ignore="static.go|build_static.sh|.DS_Store" -o static.go -pkg static ../static )

update-template-ui:
@echo "generate UI pages"
@$(GO) get github.com/infinitbyte/ego/cmd/ego
@cd modules/ui/ && ego
@cd modules/index/ui/ && ego
@cd plugins/ && ego

config: update-commit-log update-ui update-template-ui
@echo "init config"
$(GO) env
mkdir -p bin
cp stop.sh bin/stop.sh
cp gopa.yml bin/gopa.yml
cp -r config bin
config: init-version update-ui update-template-ui update-generated-file
@echo "update configs"
@# $(GO) env
@mkdir -p bin
@cp stop.sh bin/stop.sh
@cp gopa.yml bin/gopa.yml
@cp -r config bin


fetch-depends:
@echo "get Dependencies"
@echo "fetch dependencies"
$(GO) get github.com/cihub/seelog
$(GO) get github.com/PuerkitoBio/purell
$(GO) get github.com/clarkduvall/hyperloglog
Expand Down
5 changes: 5 additions & 0 deletions core/env/generated.go
@@ -0,0 +1,5 @@
package env
const lastCommitLog ="N/A"
const buildDate ="N/A"

const version ="0.0.1"
10 changes: 6 additions & 4 deletions core/env/version.go
Expand Up @@ -18,9 +18,6 @@ package env

import "strings"

// VERSION is the version of this gopa
const VERSION = "0.10.0_SNAPSHOT"

// GetWelcomeMessage print welcome message
func GetWelcomeMessage() string {
s := (" ________ ________ __________ _____ \n")
Expand All @@ -34,7 +31,7 @@ func GetWelcomeMessage() string {
if len(lastCommitLog) > 0 {
commitLog = "\n///last commit: " + GetLastCommitLog() + "///"
}
s += ("[gopa] " + VERSION + commitLog + "\n")
s += ("[gopa] " + GetVersion() + commitLog + "\n")
return (s)
}

Expand All @@ -56,3 +53,8 @@ func GetLastCommitHash() string {
func GetBuildDate() string {
return strings.TrimSpace(buildDate)
}

// GetVersion returns the version of this gopa build
func GetVersion() string {
return strings.TrimSpace(version)
}
5 changes: 5 additions & 0 deletions docs/contribute.md
Expand Up @@ -3,3 +3,8 @@

- Modules is enabled by default
- Plugins is disabled by default


* Build with custom version

make VERSION=2.0.0 config build
4 changes: 2 additions & 2 deletions gopa.yml
Expand Up @@ -320,8 +320,8 @@ modules:
ui:
enabled: true
site_name: Elasticsearch
logo: https://static-www.elastic.co/cn/assets/blt6050efb80ceabd47/elastic-logo (2).svg?q=294
favicon: https://www.elastic.co/favicon.ico
# logo: https://static-www.elastic.co/cn/assets/blt6050efb80ceabd47/elastic-logo (2).svg?q=294
# favicon: https://www.elastic.co/favicon.ico
elasticsearch:
endpoint: http://dev:9200
index_prefix: gopa-
Expand Down
2 changes: 1 addition & 1 deletion main.go
Expand Up @@ -65,7 +65,7 @@ func onShutdown(isDaemon bool) {
fmt.Println(" _` | _ \\ _ \\ _` | _ \\ | | -_) ")
fmt.Println(" \\__, | \\___/ \\___/ \\__,_| _.__/ \\_, | \\___| ")
fmt.Println(" ____/ ___/ ")
fmt.Println("[gopa] "+env.VERSION+", uptime:", time.Since(env.GetStartTime()))
fmt.Println("[gopa] "+env.GetVersion()+", uptime:", time.Since(env.GetStartTime()))
fmt.Println(" ")
}

Expand Down
9 changes: 5 additions & 4 deletions modules/api/handlers/index_handler.go
Expand Up @@ -17,11 +17,11 @@ limitations under the License.
package http

import (
"github.com/ararog/timeago"
"github.com/infinitbyte/gopa/core/env"
"github.com/infinitbyte/gopa/core/global"
"github.com/julienschmidt/httprouter"
"net/http"
"time"
)

// IndexAction returns cluster health information
Expand All @@ -35,14 +35,15 @@ func (handler API) IndexAction(w http.ResponseWriter, req *http.Request, _ httpr
data := map[string]interface{}{}
data["cluster_name"] = global.Env().SystemConfig.ClusterConfig.Name
data["name"] = global.Env().SystemConfig.NodeConfig.Name

version := map[string]interface{}{}
version["number"] = env.VERSION
version["number"] = env.GetVersion()
version["build_commit"] = env.GetLastCommitLog()
version["build_date"] = env.GetBuildDate()

data["version"] = version
data["tagline"] = "You Know, for Web"
uptime, _ := timeago.TimeAgoFromNowWithTime(env.GetStartTime())
data["uptime"] = uptime
data["uptime"] = time.Since(env.GetStartTime()).String()

handler.WriteJSON(w, &data, http.StatusOK)
}
2 changes: 1 addition & 1 deletion modules/index/ui/common/copyright.html
@@ -1,3 +1,3 @@
<%! func Copyright(w io.Writer,config *UIConfig) error %>
<%% import "github.com/infinitbyte/gopa/core/env" %%>
<%= config.SiteName %> ©2017, Powered by <a target="_blank" href="https://github.com/infinitbyte/gopa" >Gopa</a> v<%= env.VERSION %> #<a title="<%= env.GetLastCommitLog() %>" href="https://github.com/infinitbyte/gopa/commit/<%= env.GetLastCommitHash() %>"><%= env.GetLastCommitHash() %></a>.
<%= config.SiteName %> ©2017, Powered by <a target="_blank" href="https://github.com/infinitbyte/gopa" >Gopa</a> v<%= env.GetVersion() %> #<a title="<%= env.GetLastCommitLog() %>" href="https://github.com/infinitbyte/gopa/commit/<%= env.GetLastCommitHash() %>"><%= env.GetLastCommitHash() %></a>.
2 changes: 1 addition & 1 deletion modules/index/ui/common/ego.go
Expand Up @@ -16,7 +16,7 @@ func Copyright(w io.Writer, config *UIConfig) error {
_, _ = io.WriteString(w, "\n")
_, _ = io.WriteString(w, html.EscapeString(fmt.Sprint(config.SiteName)))
_, _ = io.WriteString(w, " ©2017, Powered by <a target=\"_blank\" href=\"https://github.com/infinitbyte/gopa\" >Gopa</a> v")
_, _ = io.WriteString(w, html.EscapeString(fmt.Sprint(env.VERSION)))
_, _ = io.WriteString(w, html.EscapeString(fmt.Sprint(env.GetVersion())))
_, _ = io.WriteString(w, " #<a title=\"")
_, _ = io.WriteString(w, html.EscapeString(fmt.Sprint(env.GetLastCommitLog())))
_, _ = io.WriteString(w, "\" href=\"https://github.com/infinitbyte/gopa/commit/")
Expand Down
2 changes: 1 addition & 1 deletion modules/index/ui/handler/ego.go
Expand Up @@ -22,7 +22,7 @@ func CommonFooter(w io.Writer) error {
}
func CommonHeader(w io.Writer, config *common.UIConfig) error {
_, _ = io.WriteString(w, "\n")
_, _ = io.WriteString(w, "\n\n<meta content=IE=7 http-equiv=X-UA-Compatible>\n<meta content=text/html;charset=utf-8 http-equiv=content-type>\n\n<meta name=\"robots\" content=\"all\">\n<meta name=\"license\" content=\"keep-copyright-footprint,no-KPI-shit,respect-first\">\n<meta name=\"creator\" content=\"medcl\">\n<meta name=\"generator\" content=\"https://github.com/infinitbyte/gopa\">\n<meta name=\"copyright\" content=\"Apache License, Version 2.0\">\n<meta name=\"viewport\" content=\"width=device-width, initial-scale=1, user-scalable=no, minimal-ui\">\n<meta name=\"logo-credit\" content=\"Comic eyes was designed by Freepik(http://www.freepik.com)\">\n\n<link rel=\"icon\" href=\"")
_, _ = io.WriteString(w, "\n\n<meta content=IE=7 http-equiv=X-UA-Compatible>\n<meta content=text/html;charset=utf-8 http-equiv=content-type>\n\n<meta name=\"robots\" content=\"all\">\n<meta name=\"license\" content=\"keep-copyright-footprint,no-KPI-shit,respect-first\">\n<meta name=\"creator\" content=\"medcl\">\n<meta name=\"generator\" content=\"https://github.com/infinitbyte/gopa\">\n<meta name=\"copyright\" content=\"Apache License, Version 2.0\">\n<meta name=\"viewport\" content=\"width=device-width, initial-scale=1, user-scalable=no, minimal-ui\">\n\n<link rel=\"icon\" href=\"")
_, _ = io.WriteString(w, html.EscapeString(fmt.Sprint(config.SiteFavicon)))
_, _ = io.WriteString(w, "\" type=\"image/x-icon\" />\n\n<link rel=\"stylesheet\" href=\"/static/assets/uikit-2.27.1/css/uikit.min.css\" />\n<link rel=\"stylesheet\" href=\"/static/assets/css/style.css?v=5\" rel=\"stylesheet\" type=\"text/css\"/>\n<link rel=\"stylesheet\" href=\"/static/assets/css/search_style.css?v=1\" rel=\"stylesheet\" type=\"text/css\"/>\n<script type=\"text/javascript\" src=\"/static/assets/js/jquery.min.js\"></script>\n<script>\n if(/Android|Windows Phone|webOS|iPhone|iPad|iPod|BlackBerry/i.test(navigator.userAgent)){\n window.location.href = location.origin + \"/m/\" + location.search;\n }\n</script>\n")
return nil
Expand Down
2 changes: 1 addition & 1 deletion modules/index/ui/m/handler/ego.go
Expand Up @@ -70,7 +70,7 @@ func CommonFooter(w io.Writer) error {
}
func CommonHeader(w io.Writer, config *common.UIConfig) error {
_, _ = io.WriteString(w, "\n")
_, _ = io.WriteString(w, "\n\n<meta content=IE=7 http-equiv=X-UA-Compatible>\n<meta content=text/html;charset=utf-8 http-equiv=content-type>\n\n<meta name=\"robots\" content=\"all\">\n<meta name=\"license\" content=\"keep-copyright-footprint,no-KPI-shit,respect-first\">\n<meta name=\"creator\" content=\"medcl\">\n<meta name=\"generator\" content=\"https://github.com/infinitbyte/gopa\">\n<meta name=\"copyright\" content=\"Apache License, Version 2.0\">\n<meta name=\"viewport\" content=\"width=device-width, initial-scale=1, user-scalable=no, minimal-ui\">\n<meta name=\"logo-credit\" content=\"Comic eyes was designed by Freepik(http://www.freepik.com)\">\n\n<link rel=\"icon\" href=\"")
_, _ = io.WriteString(w, "\n\n<meta content=IE=7 http-equiv=X-UA-Compatible>\n<meta content=text/html;charset=utf-8 http-equiv=content-type>\n\n<meta name=\"robots\" content=\"all\">\n<meta name=\"license\" content=\"keep-copyright-footprint,no-KPI-shit,respect-first\">\n<meta name=\"creator\" content=\"medcl\">\n<meta name=\"generator\" content=\"https://github.com/infinitbyte/gopa\">\n<meta name=\"copyright\" content=\"Apache License, Version 2.0\">\n<meta name=\"viewport\" content=\"width=device-width, initial-scale=1, user-scalable=no, minimal-ui\">\n\n<link rel=\"icon\" href=\"")
_, _ = io.WriteString(w, html.EscapeString(fmt.Sprint(config.SiteFavicon)))
_, _ = io.WriteString(w, "\" type=\"image/x-icon\" />\n\n<link rel=\"stylesheet\" href=\"/static/assets/uikit-2.27.1/css/uikit.min.css\" />\n<link rel=\"stylesheet\" href=\"/static/assets/css/m/style.css?v=4\" rel=\"stylesheet\" type=\"text/css\"/>\n<link rel=\"stylesheet\" href=\"/static/assets/css/m/search_style.css\" rel=\"stylesheet\" type=\"text/css\"/>\n<link rel=\"stylesheet\" href=\"/static/assets/css/m/loadmore.css\" rel=\"stylesheet\" type=\"text/css\"/>\n<script type=\"text/javascript\" src=\"/static/assets/js/jquery.min.js\"></script>\n<script>\n if(! /Android|Windows Phone|webOS|iPhone|iPad|iPod|BlackBerry/i.test(navigator.userAgent)){\n window.location.href = location.origin + location.search;\n }\n</script>\n")
return nil
Expand Down
2 changes: 1 addition & 1 deletion modules/ui/common/ego.go
Expand Up @@ -21,7 +21,7 @@ func Footer(w io.Writer) error {
func Head(w io.Writer, title string, customHeaderBlock string) error {
_, _ = io.WriteString(w, "\n<!DOCTYPE html>\n<!--[if lt IE 7 ]> <html class=\"no-js ie6\" lang=\"en-US\"> <![endif]-->\n<!--[if IE 7 ]> <html class=\"no-js ie7\" lang=\"en-US\"> <![endif]-->\n<!--[if IE 8 ]> <html class=\"no-js ie8\" lang=\"en-US\"> <![endif]-->\n<!--[if (gte IE 9)|!(IE)]><!--> <html lang=\"en-US\"> <!--<![endif]-->\n<html>\n<head>\n <title>")
_, _ = io.WriteString(w, html.EscapeString(fmt.Sprint(title)))
_, _ = io.WriteString(w, " - GOPA</title>\n\n <meta content=IE=7 http-equiv=X-UA-Compatible>\n <meta content=text/html;charset=utf-8 http-equiv=content-type>\n\n <meta name=\"robots\" content=\"all\">\n <meta name=\"license\" content=\"keep-copyright-footprint,no-KPI-shit,respect-first\">\n <meta name=\"creator\" content=\"medcl\">\n <meta name=\"generator\" content=\"https://github.com/infinitbyte/gopa\">\n <meta name=\"copyright\" content=\"Apache License, Version 2.0\">\n <meta name=\"viewport\" content=\"width=device-width, initial-scale=1\">\n <meta name=\"logo-credit\" content=\"Comic eyes was designed by Freepik(http://www.freepik.com)\">\n\n <link rel=\"stylesheet\" href=\"/static/assets/uikit-2.27.1/css/uikit.min.css\" />\n <link rel=\"icon\" href=\"/static/assets/img/favicon.ico\" type=\"image/x-icon\" />\n <link rel=\"shortcut icon\" href=\"/static/assets/img/favicon.ico\" type=\"image/x-icon\" />\n\n <script src=\"/static/assets/js/jquery.min.js\"></script>\n <script src=\"/static/assets/uikit-2.27.1/js/uikit.min.js\"></script>\n\n <meta charset=\"utf-8\">\n ")
_, _ = io.WriteString(w, " - GOPA</title>\n\n <meta content=IE=7 http-equiv=X-UA-Compatible>\n <meta content=text/html;charset=utf-8 http-equiv=content-type>\n\n <meta name=\"robots\" content=\"all\">\n <meta name=\"license\" content=\"keep-copyright-footprint,no-KPI-shit,respect-first\">\n <meta name=\"creator\" content=\"medcl\">\n <meta name=\"generator\" content=\"https://github.com/infinitbyte/gopa\">\n <meta name=\"copyright\" content=\"Apache License, Version 2.0\">\n <meta name=\"viewport\" content=\"width=device-width, initial-scale=1\">\n\n <link rel=\"stylesheet\" href=\"/static/assets/uikit-2.27.1/css/uikit.min.css\" />\n <link rel=\"icon\" href=\"/static/assets/img/favicon.ico\" type=\"image/x-icon\" />\n <link rel=\"shortcut icon\" href=\"/static/assets/img/favicon.ico\" type=\"image/x-icon\" />\n\n <script src=\"/static/assets/js/jquery.min.js\"></script>\n <script src=\"/static/assets/uikit-2.27.1/js/uikit.min.js\"></script>\n\n <meta charset=\"utf-8\">\n ")
if len(customHeaderBlock) > 0 {
_, _ = io.WriteString(w, "\n ")
_, _ = io.WriteString(w, html.EscapeString(fmt.Sprint(customHeaderBlock)))
Expand Down

0 comments on commit 528eed4

Please sign in to comment.