diff --git a/.travis.yml b/.travis.yml index b22d1719..f429cb04 100644 --- a/.travis.yml +++ b/.travis.yml @@ -1,6 +1,7 @@ language: go go: - 1.x +gobuild_args: -x -ldflags "-X main.buildversion $(date -u +.%Y%m%d.%H%M%S)" before_install: - sudo apt-get install gcc-mingw-w64 gcc-mingw-w64-i686 gcc-mingw-w64-x86-64 binutils-mingw-w64-i686 binutils-mingw-w64-x86-64 - go get -u github.com/tools/godep diff --git a/README.md b/README.md index e2bcd44b..99ebd407 100644 --- a/README.md +++ b/README.md @@ -20,7 +20,10 @@ All tested versions of Ubuntu fail to build, use a different OS or docker * Install [Golang](https://golang.org/doc/install) (version >=1.8) * `go get -u github.com/tools/godep` * `go get github.com/NyaaPantsu/nyaa` +Either use: * `godep go build` +Or use this to have the build version in index.html: +* `go build -ldflags "-X main.buildversion=$(date -u +.%Y%m%d.%H%M%S)"` * Download the DB and place it in your root folder named as "nyaa.db" (You want the merged.sqlite3 database, see the dev IRC for more info) * `./nyaa` * You can now access your local site over on [localhost:9999](http://localhost:9999) diff --git a/config/default_config.yml b/config/default_config.yml index d0d866fa..5d77bd26 100644 --- a/config/default_config.yml +++ b/config/default_config.yml @@ -3,6 +3,8 @@ # Host of server host: localhost +# Version of the app +version: "0.9" # port of server port: 9999 # database type diff --git a/config/types.go b/config/types.go index 8cb0d2a7..edee876c 100644 --- a/config/types.go +++ b/config/types.go @@ -13,6 +13,8 @@ type Config struct { // structure depends on the dialect for each db type DBParams string `json:"db_params" yaml:"db_params,omitempty"` DBLogMode string `json:"db_logmode" yaml:"db_logmode,omitempty"` + Version string `json:"version" yaml:"version,omitempty"` + Build string `yaml:"-"` // tracker scraper config (required) Scrape ScraperConfig `json:"scraper" yaml:"scraper,flow,omitempty"` // cache config diff --git a/main.go b/main.go index 41413191..7621769f 100644 --- a/main.go +++ b/main.go @@ -23,6 +23,8 @@ import ( "github.com/NyaaPantsu/nyaa/util/signals" ) +var buildversion string + // RunServer runs webapp mainloop func RunServer(conf *config.Config) { // TODO Use config from cli @@ -112,6 +114,11 @@ func RunMetainfoFetcher(conf *config.Config) { func main() { conf := config.Conf + if buildversion != "" { + conf.Build = buildversion + } else { + conf.Build = "unknown" + } processFlags := conf.BindFlags() defaults := flag.Bool("print-defaults", false, "print the default configuration file on stdout") mode := flag.String("mode", "webapp", "which mode to run daemon in, either webapp, scraper or metainfo_fetcher") diff --git a/package.sh b/package.sh index 7540763a..b253c7cf 100755 --- a/package.sh +++ b/package.sh @@ -15,7 +15,7 @@ for i in "${OSes[@]}"; do cc=${arr[1]} rm -f nyaa nyaa.exe echo -e "\nBuilding $os..." - echo GOOS=$os GOARCH=amd64 CC=$cc CGO_ENABLED=1 go build -v - GOOS=$os GOARCH=amd64 CC=$cc CGO_ENABLED=1 go build -v + echo GOOS=$os GOARCH=amd64 CC=$cc CGO_ENABLED=1 go build -v -ldflags="-X main.buildversion=$(date -u +.%Y%m%d.%H%M%S)" + GOOS=$os GOARCH=amd64 CC=$cc CGO_ENABLED=1 go build -v -ldflags="-X main.buildversion=$(date -u +.%Y%m%d.%H%M%S)" zip -9 -r dist/nyaa-${version}_${os}_amd64.zip os public templates service/user/locale *.md nyaa nyaa.exe done diff --git a/router/template_variables.go b/router/template_variables.go index 1c4c2780..6b6c1b39 100644 --- a/router/template_variables.go +++ b/router/template_variables.go @@ -6,6 +6,7 @@ import ( "net/url" "github.com/NyaaPantsu/nyaa/common" + "github.com/NyaaPantsu/nyaa/config" "github.com/NyaaPantsu/nyaa/model" "github.com/NyaaPantsu/nyaa/service/user" userForms "github.com/NyaaPantsu/nyaa/service/user/form" @@ -106,6 +107,7 @@ type commonTemplateVariables struct { URL *url.URL // for parsing URL in templates Route *mux.Route // for getting current route in templates CsrfField template.HTML + Config *config.Config } type navigation struct { @@ -158,5 +160,6 @@ func newCommonVariables(r *http.Request) commonTemplateVariables { URL: r.URL, Route: mux.CurrentRoute(r), CsrfField: csrf.TemplateField(r), + Config: config.Conf, } } diff --git a/templates/index.html b/templates/index.html index 2de836c0..5cd585a5 100755 --- a/templates/index.html +++ b/templates/index.html @@ -85,7 +85,7 @@ - Powered by NyaaPantsu + Powered by NyaaPantsu v{{ .Config.Version }}{{ .Config.Build }}