Bindata is optional and over-writable on restart (#354)

* Moved conf assets into options folder

* Dropped old bindata

* Started to integrate options bindata and accessors

* Do not enforce a builtin app.ini

* Replaced bindata calls with options

* Dropped bindata task from makefile, it's the generate task now

* Always embedd app.ini to provide sane config defaults

* Use sane defaults for the configuration

* Defined default value for SSH_KEYGEN_PATH

* Dropped "NEVER EVER MODIFY THIS FILE" header from app.ini

* Fixed new paths in latest test additions

* Drop bindata with make clean task

* Set more proper default values
tokarchuk/v1.17
Thomas Boerger 8 years ago committed by GitHub
parent c21e2c4151
commit b33078fa33
  1. 1
      .gitignore
  2. 22
      Makefile
  3. 27
      cmd/web.go
  4. 3
      conf/README.md
  5. 3
      conf/app.ini
  6. 21
      models/repo.go
  7. 2
      modules/base/tool_test.go
  8. 5353
      modules/bindata/bindata.go
  9. 94
      modules/options/dynamic.go
  10. 51
      modules/options/options.go
  11. 84
      modules/options/static.go
  12. 35
      modules/setting/setting.go
  13. 0
      options/gitignore/Actionscript
  14. 0
      options/gitignore/Ada
  15. 0
      options/gitignore/Agda
  16. 0
      options/gitignore/Android
  17. 0
      options/gitignore/Anjuta
  18. 0
      options/gitignore/AppEngine
  19. 0
      options/gitignore/AppceleratorTitanium
  20. 0
      options/gitignore/ArchLinuxPackages
  21. 0
      options/gitignore/Archives
  22. 0
      options/gitignore/Autotools
  23. 0
      options/gitignore/BricxCC
  24. 0
      options/gitignore/C
  25. 0
      options/gitignore/C Sharp
  26. 0
      options/gitignore/C++
  27. 0
      options/gitignore/CFWheels
  28. 0
      options/gitignore/CMake
  29. 0
      options/gitignore/CUDA
  30. 0
      options/gitignore/CVS
  31. 0
      options/gitignore/CakePHP
  32. 0
      options/gitignore/ChefCookbook
  33. 0
      options/gitignore/Cloud9
  34. 0
      options/gitignore/CodeIgniter
  35. 0
      options/gitignore/CodeKit
  36. 0
      options/gitignore/CommonLisp
  37. 0
      options/gitignore/Composer
  38. 0
      options/gitignore/Concrete5
  39. 0
      options/gitignore/Coq
  40. 0
      options/gitignore/CraftCMS
  41. 0
      options/gitignore/DM
  42. 0
      options/gitignore/Dart
  43. 0
      options/gitignore/DartEditor
  44. 0
      options/gitignore/Delphi
  45. 0
      options/gitignore/Dreamweaver
  46. 0
      options/gitignore/Drupal
  47. 0
      options/gitignore/EPiServer
  48. 0
      options/gitignore/Eagle
  49. 0
      options/gitignore/Eclipse
  50. 0
      options/gitignore/EiffelStudio
  51. 0
      options/gitignore/Elisp
  52. 0
      options/gitignore/Elixir
  53. 0
      options/gitignore/Emacs
  54. 0
      options/gitignore/Ensime
  55. 0
      options/gitignore/Erlang
  56. 0
      options/gitignore/Espresso
  57. 0
      options/gitignore/ExpressionEngine
  58. 0
      options/gitignore/ExtJs
  59. 0
      options/gitignore/Fancy
  60. 0
      options/gitignore/Finale
  61. 0
      options/gitignore/FlexBuilder
  62. 0
      options/gitignore/ForceDotCom
  63. 0
      options/gitignore/FuelPHP
  64. 0
      options/gitignore/GWT
  65. 0
      options/gitignore/Gcov
  66. 0
      options/gitignore/GitBook
  67. 0
      options/gitignore/Go
  68. 0
      options/gitignore/Gradle
  69. 0
      options/gitignore/Grails
  70. 0
      options/gitignore/Haskell
  71. 0
      options/gitignore/IGORPro
  72. 0
      options/gitignore/IPythonNotebook
  73. 0
      options/gitignore/Idris
  74. 0
      options/gitignore/JDeveloper
  75. 0
      options/gitignore/Java
  76. 0
      options/gitignore/Jboss
  77. 0
      options/gitignore/Jekyll
  78. 0
      options/gitignore/JetBrains
  79. 0
      options/gitignore/Joomla
  80. 0
      options/gitignore/KDevelop4
  81. 0
      options/gitignore/Kate
  82. 0
      options/gitignore/KiCAD
  83. 0
      options/gitignore/Kohana
  84. 0
      options/gitignore/LabVIEW
  85. 0
      options/gitignore/Laravel
  86. 0
      options/gitignore/Lazarus
  87. 0
      options/gitignore/Leiningen
  88. 0
      options/gitignore/LemonStand
  89. 0
      options/gitignore/LibreOffice
  90. 0
      options/gitignore/Lilypond
  91. 0
      options/gitignore/Linux
  92. 0
      options/gitignore/Lithium
  93. 0
      options/gitignore/Lua
  94. 0
      options/gitignore/LyX
  95. 0
      options/gitignore/Magento
  96. 0
      options/gitignore/Matlab
  97. 0
      options/gitignore/Maven
  98. 0
      options/gitignore/Mercurial
  99. 0
      options/gitignore/Mercury
  100. 0
      options/gitignore/MetaProgrammingSystem
  101. Some files were not shown because too many files have changed in this diff Show More

1
.gitignore vendored

@ -28,6 +28,7 @@ _testmain.go
coverage.out coverage.out
/modules/options/bindata.go
/modules/public/bindata.go /modules/public/bindata.go
/modules/templates/bindata.go /modules/templates/bindata.go

@ -2,10 +2,7 @@ DIST := dist
EXECUTABLE := gitea EXECUTABLE := gitea
IMPORT := code.gitea.io/gitea IMPORT := code.gitea.io/gitea
SHA := $(shell git rev-parse --short HEAD) BINDATA := modules/{options,public,templates}/bindata.go
DATE := $(shell date -u '+%Y-%m-%d %I:%M:%S %Z')
BINDATA := $(shell find conf | sed 's/ /\\ /g')
STYLESHEETS := $(wildcard public/less/index.less public/less/_*.less) STYLESHEETS := $(wildcard public/less/index.less public/less/_*.less)
JAVASCRIPTS := JAVASCRIPTS :=
@ -33,7 +30,7 @@ all: build
.PHONY: clean .PHONY: clean
clean: clean:
go clean -i ./... go clean -i ./...
rm -rf $(EXECUTABLE) $(DIST) rm -rf $(EXECUTABLE) $(DIST) $(BINDATA)
.PHONY: fmt .PHONY: fmt
fmt: fmt:
@ -119,19 +116,6 @@ release-copy:
release-check: release-check:
cd $(DIST)/release; $(foreach file,$(wildcard $(DIST)/release/$(EXECUTABLE)-*),sha256sum $(notdir $(file)) > $(notdir $(file)).sha256;) cd $(DIST)/release; $(foreach file,$(wildcard $(DIST)/release/$(EXECUTABLE)-*),sha256sum $(notdir $(file)) > $(notdir $(file)).sha256;)
.PHONY: bindata
bindata: modules/bindata/bindata.go
.IGNORE: modules/bindata/bindata.go
modules/bindata/bindata.go: $(BINDATA)
@which go-bindata > /dev/null; if [ $$? -ne 0 ]; then \
go get -u github.com/jteeuwen/go-bindata/...; \
fi
go-bindata -o=$@ -ignore="\\.go|README.md|TRANSLATORS" -pkg=bindata conf/...
go fmt $@
sed -i.bak 's/confLocaleLocale_/confLocaleLocale/' $@
rm $@.bak
.PHONY: javascripts .PHONY: javascripts
javascripts: public/js/index.js javascripts: public/js/index.js
@ -147,4 +131,4 @@ public/css/index.css: $(STYLESHEETS)
lessc $< $@ lessc $< $@
.PHONY: assets .PHONY: assets
assets: bindata javascripts stylesheets assets: javascripts stylesheets

@ -16,9 +16,9 @@ import (
"code.gitea.io/gitea/models" "code.gitea.io/gitea/models"
"code.gitea.io/gitea/modules/auth" "code.gitea.io/gitea/modules/auth"
"code.gitea.io/gitea/modules/bindata"
"code.gitea.io/gitea/modules/context" "code.gitea.io/gitea/modules/context"
"code.gitea.io/gitea/modules/log" "code.gitea.io/gitea/modules/log"
"code.gitea.io/gitea/modules/options"
"code.gitea.io/gitea/modules/public" "code.gitea.io/gitea/modules/public"
"code.gitea.io/gitea/modules/setting" "code.gitea.io/gitea/modules/setting"
"code.gitea.io/gitea/modules/templates" "code.gitea.io/gitea/modules/templates"
@ -99,22 +99,29 @@ func newMacaron() *macaron.Macaron {
m.Use(templates.Renderer()) m.Use(templates.Renderer())
models.InitMailRender(templates.Mailer()) models.InitMailRender(templates.Mailer())
localeNames, err := bindata.AssetDir("conf/locale") localeNames, err := options.Dir("locale")
if err != nil { if err != nil {
log.Fatal(4, "Fail to list locale files: %v", err) log.Fatal(4, "Fail to list locale files: %v", err)
} }
localFiles := make(map[string][]byte) localFiles := make(map[string][]byte)
for _, name := range localeNames { for _, name := range localeNames {
localFiles[name] = bindata.MustAsset("conf/locale/" + name) localFiles[name], err = options.Locale(name)
if err != nil {
log.Fatal(4, "Failed to load %s locale file. %v", name, err)
}
} }
m.Use(i18n.I18n(i18n.Options{ m.Use(i18n.I18n(i18n.Options{
SubURL: setting.AppSubURL, SubURL: setting.AppSubURL,
Files: localFiles, Files: localFiles,
CustomDirectory: path.Join(setting.CustomPath, "conf/locale"), Langs: setting.Langs,
Langs: setting.Langs, Names: setting.Names,
Names: setting.Names, DefaultLang: "en-US",
DefaultLang: "en-US", Redirect: true,
Redirect: true,
})) }))
m.Use(cache.Cacher(cache.Options{ m.Use(cache.Cacher(cache.Options{
Adapter: setting.CacheAdapter, Adapter: setting.CacheAdapter,

@ -1,3 +0,0 @@
Execute following command in ROOT directory when anything is changed:
$ make bindata

@ -1,6 +1,3 @@
# NEVER EVER MODIFY THIS FILE
# PLEASE MAKE CHANGES ON CORRESPONDING CUSTOM CONFIG FILE
; App name that shows on every page title ; App name that shows on every page title
APP_NAME = Gitea: Git with a cup of tea APP_NAME = Gitea: Git with a cup of tea
; Change it if you run locally ; Change it if you run locally

@ -20,9 +20,9 @@ import (
"time" "time"
"code.gitea.io/git" "code.gitea.io/git"
"code.gitea.io/gitea/modules/bindata"
"code.gitea.io/gitea/modules/log" "code.gitea.io/gitea/modules/log"
"code.gitea.io/gitea/modules/markdown" "code.gitea.io/gitea/modules/markdown"
"code.gitea.io/gitea/modules/options"
"code.gitea.io/gitea/modules/process" "code.gitea.io/gitea/modules/process"
"code.gitea.io/gitea/modules/setting" "code.gitea.io/gitea/modules/setting"
"code.gitea.io/gitea/modules/sync" "code.gitea.io/gitea/modules/sync"
@ -80,11 +80,11 @@ func LoadRepoConfig() {
types := []string{"gitignore", "license", "readme", "label"} types := []string{"gitignore", "license", "readme", "label"}
typeFiles := make([][]string, 4) typeFiles := make([][]string, 4)
for i, t := range types { for i, t := range types {
files, err := bindata.AssetDir("conf/" + t) files, err := options.Dir(t)
if err != nil { if err != nil {
log.Fatal(4, "Fail to get %s files: %v", t, err) log.Fatal(4, "Fail to get %s files: %v", t, err)
} }
customPath := path.Join(setting.CustomPath, "conf", t) customPath := path.Join(setting.CustomPath, "options", t)
if com.IsDir(customPath) { if com.IsDir(customPath) {
customFiles, err := com.StatDir(customPath) customFiles, err := com.StatDir(customPath)
if err != nil { if err != nil {
@ -827,14 +827,25 @@ type CreateRepoOptions struct {
} }
func getRepoInitFile(tp, name string) ([]byte, error) { func getRepoInitFile(tp, name string) ([]byte, error) {
relPath := path.Join("conf", tp, strings.TrimLeft(name, "./")) cleanedName := strings.TrimLeft(name, "./")
relPath := path.Join("options", tp, cleanedName)
// Use custom file when available. // Use custom file when available.
customPath := path.Join(setting.CustomPath, relPath) customPath := path.Join(setting.CustomPath, relPath)
if com.IsFile(customPath) { if com.IsFile(customPath) {
return ioutil.ReadFile(customPath) return ioutil.ReadFile(customPath)
} }
return bindata.Asset(relPath)
switch tp {
case "readme":
return options.Readme(cleanedName)
case "gitignore":
return options.Gitignore(cleanedName)
case "license":
return options.License(cleanedName)
default:
return []byte{}, fmt.Errorf("Invalid init file type")
}
} }
func prepareRepoCommit(repo *Repository, tmpDir, repoPath string, opts CreateRepoOptions) error { func prepareRepoCommit(repo *Repository, tmpDir, repoPath string, opts CreateRepoOptions) error {

@ -25,7 +25,7 @@ const (
func TestMain(m *testing.M) { func TestMain(m *testing.M) {
// setup // setup
macaroni18n.I18n(macaroni18n.Options{ macaroni18n.I18n(macaroni18n.Options{
Directory: "../../conf/locale/", Directory: "../../options/locale/",
DefaultLang: "en-US", DefaultLang: "en-US",
Langs: []string{"en-US"}, Langs: []string{"en-US"},
Names: []string{"english"}, Names: []string{"english"},

File diff suppressed because one or more lines are too long

@ -0,0 +1,94 @@
// +build !bindata
// Copyright 2016 The Gitea Authors. All rights reserved.
// Use of this source code is governed by a MIT-style
// license that can be found in the LICENSE file.
package options
import (
"fmt"
"io/ioutil"
"path"
"code.gitea.io/gitea/modules/setting"
"github.com/Unknwon/com"
)
var (
directories = make(directorySet)
)
// Dir returns all files from static or custom directory.
func Dir(name string) ([]string, error) {
if directories.Filled(name) {
return directories.Get(name), nil
}
var (
result []string
)
customDir := path.Join(setting.CustomPath, "options", name)
if com.IsDir(customDir) {
files, err := com.StatDir(customDir, true)
if err != nil {
return []string{}, fmt.Errorf("Failed to read custom directory. %v", err)
}
result = append(result, files...)
}
staticDir := path.Join(setting.StaticRootPath, "options", name)
if com.IsDir(staticDir) {
files, err := com.StatDir(staticDir, true)
if err != nil {
return []string{}, fmt.Errorf("Failed to read static directory. %v", err)
}
result = append(result, files...)
}
return directories.AddAndGet(name, result), nil
}
// Locale reads the content of a specific locale from static or custom path.
func Locale(name string) ([]byte, error) {
return fileFromDir(path.Join("locale", name))
}
// Readme reads the content of a specific readme from static or custom path.
func Readme(name string) ([]byte, error) {
return fileFromDir(path.Join("readme", name))
}
// Gitignore reads the content of a specific gitignore from static or custom path.
func Gitignore(name string) ([]byte, error) {
return fileFromDir(path.Join("gitignore", name))
}
// License reads the content of a specific license from static or custom path.
func License(name string) ([]byte, error) {
return fileFromDir(path.Join("license", name))
}
// fileFromDir is a helper to read files from static or custom path.
func fileFromDir(name string) ([]byte, error) {
customPath := path.Join(setting.CustomPath, "options", name)
if com.IsFile(customPath) {
return ioutil.ReadFile(customPath)
}
staticPath := path.Join(setting.StaticRootPath, "options", name)
if com.IsFile(staticPath) {
return ioutil.ReadFile(staticPath)
}
return []byte{}, fmt.Errorf("Asset file does not exist: %s", name)
}

@ -0,0 +1,51 @@
// Copyright 2016 The Gitea Authors. All rights reserved.
// Use of this source code is governed by a MIT-style
// license that can be found in the LICENSE file.
package options
//go:generate go-bindata -tags "bindata" -ignore "TRANSLATORS" -pkg "options" -o "bindata.go" ../../options/...
//go:generate go fmt bindata.go
//go:generate sed -i.bak s/..\/..\/options\/// bindata.go
//go:generate rm -f bindata.go.bak
type directorySet map[string][]string
func (s directorySet) Add(key string, value []string) {
_, ok := s[key]
if !ok {
s[key] = make([]string, 0, len(value))
}
s[key] = append(s[key], value...)
}
func (s directorySet) Get(key string) []string {
_, ok := s[key]
if ok {
result := []string{}
seen := map[string]string{}
for _, val := range s[key] {
if _, ok := seen[val]; !ok {
result = append(result, val)
seen[val] = val
}
}
return result
}
return []string{}
}
func (s directorySet) AddAndGet(key string, value []string) []string {
s.Add(key, value)
return s.Get(key)
}
func (s directorySet) Filled(key string) bool {
return len(s[key]) > 0
}

@ -0,0 +1,84 @@
// +build bindata
// Copyright 2016 The Gitea Authors. All rights reserved.
// Use of this source code is governed by a MIT-style
// license that can be found in the LICENSE file.
package options
import (
"fmt"
"io/ioutil"
"path"
"code.gitea.io/gitea/modules/setting"
"github.com/Unknwon/com"
)
var (
directories = make(directorySet)
)
// Dir returns all files from bindata or custom directory.
func Dir(name string) ([]string, error) {
if directories.Filled(name) {
return directories.Get(name), nil
}
var (
result []string
)
customDir := path.Join(setting.CustomPath, "options", name)
if com.IsDir(customDir) {
files, err := com.StatDir(customDir, true)
if err != nil {
return []string{}, fmt.Errorf("Failed to read custom directory. %v", err)
}
result = append(result, files...)
}
files, err := AssetDir(path.Join("..", "..", "options", name))
if err != nil {
return []string{}, fmt.Errorf("Failed to read embedded directory. %v", err)
}
result = append(result, files...)
return directories.AddAndGet(name, result), nil
}
// Locale reads the content of a specific locale from bindata or custom path.
func Locale(name string) ([]byte, error) {
return fileFromDir(path.Join("locale", name))
}
// Readme reads the content of a specific readme from bindata or custom path.
func Readme(name string) ([]byte, error) {
return fileFromDir(path.Join("readme", name))
}
// Gitignore reads the content of a gitignore locale from bindata or custom path.
func Gitignore(name string) ([]byte, error) {
return fileFromDir(path.Join("gitignore", name))
}
// License reads the content of a specific license from bindata or custom path.
func License(name string) ([]byte, error) {
return fileFromDir(path.Join("license", name))
}
// fileFromDir is a helper to read files from bindata or custom path.
func fileFromDir(name string) ([]byte, error) {
customPath := path.Join(setting.CustomPath, "options", name)
if com.IsFile(customPath) {
return ioutil.ReadFile(customPath)
}
return Asset(name)
}

@ -17,6 +17,8 @@ import (
"strings" "strings"
"time" "time"
"code.gitea.io/gitea/modules/log"
"code.gitea.io/gitea/modules/user"
"github.com/Unknwon/com" "github.com/Unknwon/com"
_ "github.com/go-macaron/cache/memcache" // memcache plugin for cache _ "github.com/go-macaron/cache/memcache" // memcache plugin for cache
_ "github.com/go-macaron/cache/redis" _ "github.com/go-macaron/cache/redis"
@ -25,10 +27,6 @@ import (
_ "github.com/kardianos/minwinsvc" // import minwinsvc for windows services _ "github.com/kardianos/minwinsvc" // import minwinsvc for windows services
"gopkg.in/ini.v1" "gopkg.in/ini.v1"
"strk.kbt.io/projects/go/libravatar" "strk.kbt.io/projects/go/libravatar"
"code.gitea.io/gitea/modules/bindata"
"code.gitea.io/gitea/modules/log"
"code.gitea.io/gitea/modules/user"
) )
// Scheme describes protocol types // Scheme describes protocol types
@ -349,9 +347,10 @@ func NewContext() {
log.Fatal(4, "Fail to get work directory: %v", err) log.Fatal(4, "Fail to get work directory: %v", err)
} }
Cfg, err = ini.Load(bindata.MustAsset("conf/app.ini")) Cfg = ini.Empty()
if err != nil { if err != nil {
log.Fatal(4, "Fail to parse 'conf/app.ini': %v", err) log.Fatal(4, "Fail to parse 'app.ini': %v", err)
} }
CustomPath = os.Getenv("GITEA_CUSTOM") CustomPath = os.Getenv("GITEA_CUSTOM")
@ -444,6 +443,10 @@ please consider changing to GITEA_CUSTOM`)
if err = Cfg.Section("server").MapTo(&SSH); err != nil { if err = Cfg.Section("server").MapTo(&SSH); err != nil {
log.Fatal(4, "Fail to map SSH settings: %v", err) log.Fatal(4, "Fail to map SSH settings: %v", err)
} }
SSH.KeygenPath = sec.Key("SSH_KEYGEN_PATH").MustString("ssh-keygen")
SSH.Port = sec.Key("SSH_PORT").MustInt(22)
// When disable SSH, start builtin server value is ignored. // When disable SSH, start builtin server value is ignored.
if SSH.Disabled { if SSH.Disabled {
SSH.StartBuiltinServer = false SSH.StartBuiltinServer = false
@ -502,7 +505,7 @@ please consider changing to GITEA_CUSTOM`)
"StampNano": time.StampNano, "StampNano": time.StampNano,
}[Cfg.Section("time").Key("FORMAT").MustString("RFC1123")] }[Cfg.Section("time").Key("FORMAT").MustString("RFC1123")]
RunUser = Cfg.Section("").Key("RUN_USER").String() RunUser = Cfg.Section("").Key("RUN_USER").MustString(user.CurrentUsername())
// Does not check run user when the install lock is off. // Does not check run user when the install lock is off.
if InstallLock { if InstallLock {
currentUser, match := IsRunUserMatchCurrentUser(RunUser) currentUser, match := IsRunUserMatchCurrentUser(RunUser)
@ -593,7 +596,17 @@ please consider changing to GITEA_CUSTOM`)
} }
Langs = Cfg.Section("i18n").Key("LANGS").Strings(",") Langs = Cfg.Section("i18n").Key("LANGS").Strings(",")
if len(Langs) == 0 {
Langs = []string{
"en-US",
}
}
Names = Cfg.Section("i18n").Key("NAMES").Strings(",") Names = Cfg.Section("i18n").Key("NAMES").Strings(",")
if len(Names) == 0 {
Names = []string{
"English",
}
}
dateLangs = Cfg.Section("i18n.datelang").KeysHash() dateLangs = Cfg.Section("i18n.datelang").KeysHash()
ShowFooterBranding = Cfg.Section("other").Key("SHOW_FOOTER_BRANDING").MustBool() ShowFooterBranding = Cfg.Section("other").Key("SHOW_FOOTER_BRANDING").MustBool()
@ -639,16 +652,18 @@ var logLevels = map[string]string{
} }
func newLogService() { func newLogService() {
log.Info("%s %s", AppName, AppVer) log.Info("Gitea v%s", AppVer)
// Get and check log mode.
LogModes = strings.Split(Cfg.Section("log").Key("MODE").MustString("console"), ",") LogModes = strings.Split(Cfg.Section("log").Key("MODE").MustString("console"), ",")
LogConfigs = make([]string, len(LogModes)) LogConfigs = make([]string, len(LogModes))
for i, mode := range LogModes { for i, mode := range LogModes {
mode = strings.TrimSpace(mode) mode = strings.TrimSpace(mode)
sec, err := Cfg.GetSection("log." + mode) sec, err := Cfg.GetSection("log." + mode)
if err != nil { if err != nil {
log.Fatal(4, "Unknown log mode: %s", mode) sec, _ = Cfg.NewSection("log." + mode)
} }
validLevels := []string{"Trace", "Debug", "Info", "Warn", "Error", "Critical"} validLevels := []string{"Trace", "Debug", "Info", "Warn", "Error", "Critical"}

Some files were not shown because too many files have changed in this diff Show More

Loading…
Cancel
Save