Put default config into binary
This commit is contained in:
parent
deee2d5fa8
commit
e6cf83b8c0
7 changed files with 1097 additions and 53 deletions
|
@ -14,6 +14,7 @@ watch_dirs = [
|
|||
watch_exts = [".go", ".ini"]
|
||||
build_delay = 1500
|
||||
cmds = [
|
||||
#["go-bindata", "-o=modules/bindata/bindata.go", "-ignore=\\.DS_Store|README", "-pkg=bindata", "conf/..."],
|
||||
["go", "install", "-tags", "sqlite cert"],# redis memcache
|
||||
["go", "build", "-tags", "sqlite cert"],
|
||||
["./gogs", "web"]
|
||||
|
|
14
cmd/web.go
14
cmd/web.go
|
@ -34,6 +34,7 @@ import (
|
|||
"github.com/gogits/gogs/modules/auth/apiv1"
|
||||
"github.com/gogits/gogs/modules/avatar"
|
||||
"github.com/gogits/gogs/modules/base"
|
||||
"github.com/gogits/gogs/modules/bindata"
|
||||
"github.com/gogits/gogs/modules/git"
|
||||
"github.com/gogits/gogs/modules/log"
|
||||
"github.com/gogits/gogs/modules/middleware"
|
||||
|
@ -82,7 +83,7 @@ func checkVersion() {
|
|||
{"github.com/macaron-contrib/binding", binding.Version, "0.0.6"},
|
||||
{"github.com/macaron-contrib/cache", cache.Version, "0.0.7"},
|
||||
{"github.com/macaron-contrib/csrf", csrf.Version, "0.0.3"},
|
||||
{"github.com/macaron-contrib/i18n", i18n.Version, "0.0.5"},
|
||||
{"github.com/macaron-contrib/i18n", i18n.Version, "0.0.7"},
|
||||
{"github.com/macaron-contrib/session", session.Version, "0.1.6"},
|
||||
{"gopkg.in/ini.v1", ini.Version, "1.2.0"},
|
||||
}
|
||||
|
@ -123,9 +124,18 @@ func newMacaron() *macaron.Macaron {
|
|||
Funcs: []template.FuncMap{base.TemplateFuncs},
|
||||
IndentJSON: macaron.Env != macaron.PROD,
|
||||
}))
|
||||
|
||||
localeNames, err := bindata.AssetDir("conf/locale")
|
||||
if err != nil {
|
||||
log.Fatal(4, "Fail to list locale files: %v", err)
|
||||
}
|
||||
localFiles := make(map[string][]byte)
|
||||
for _, name := range localeNames {
|
||||
localFiles[name] = bindata.MustAsset("conf/locale/" + name)
|
||||
}
|
||||
m.Use(i18n.I18n(i18n.Options{
|
||||
SubURL: setting.AppSubUrl,
|
||||
Directory: path.Join(setting.ConfRootPath, "locale"),
|
||||
Files: localFiles,
|
||||
CustomDirectory: path.Join(setting.CustomPath, "conf/locale"),
|
||||
Langs: setting.Langs,
|
||||
Names: setting.Names,
|
||||
|
|
7
conf/README
Normal file
7
conf/README
Normal file
|
@ -0,0 +1,7 @@
|
|||
Execute following command in ROOT directory when anything is changed:
|
||||
|
||||
$ go-bindata -o=modules/bindata/bindata.go -ignore="\\.DS_Store|README" -pkg=bindata conf/...
|
||||
|
||||
Add -debug flag to make life easier in development(somehow isn't working):
|
||||
|
||||
$ go-bindata -debug -o=modules/bindata/bindata.go -ignore="\\.DS_Store|README" -pkg=bindata conf/...
|
Binary file not shown.
|
@ -23,6 +23,7 @@ import (
|
|||
"github.com/Unknwon/com"
|
||||
|
||||
"github.com/gogits/gogs/modules/base"
|
||||
"github.com/gogits/gogs/modules/bindata"
|
||||
"github.com/gogits/gogs/modules/git"
|
||||
"github.com/gogits/gogs/modules/log"
|
||||
"github.com/gogits/gogs/modules/process"
|
||||
|
@ -55,7 +56,7 @@ func LoadRepoConfig() {
|
|||
types := []string{"gitignore", "license"}
|
||||
typeFiles := make([][]string, 2)
|
||||
for i, t := range types {
|
||||
files, err := com.StatDir(path.Join("conf", t))
|
||||
files, err := bindata.AssetDir("conf/" + t)
|
||||
if err != nil {
|
||||
log.Fatal(4, "Fail to get %s files: %v", t, err)
|
||||
}
|
||||
|
@ -365,17 +366,6 @@ func MigrateRepository(u *User, name, desc string, private, mirror bool, url str
|
|||
return repo, UpdateRepository(repo, false)
|
||||
}
|
||||
|
||||
// extractGitBareZip extracts git-bare.zip to repository path.
|
||||
func extractGitBareZip(repoPath string) error {
|
||||
z, err := zip.Open(path.Join(setting.ConfRootPath, "content/git-bare.zip"))
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
defer z.Close()
|
||||
|
||||
return z.ExtractTo(repoPath)
|
||||
}
|
||||
|
||||
// initRepoCommit temporarily changes with work directory.
|
||||
func initRepoCommit(tmpPath string, sig *git.Signature) (err error) {
|
||||
var stderr string
|
||||
|
@ -409,9 +399,13 @@ func createUpdateHook(repoPath string) error {
|
|||
func initRepository(e Engine, f string, u *User, repo *Repository, initReadme bool, repoLang, license string) error {
|
||||
repoPath := RepoPath(u.Name, repo.Name)
|
||||
|
||||
// Create bare new repository.
|
||||
if err := extractGitBareZip(repoPath); err != nil {
|
||||
return err
|
||||
// Init bare new repository.
|
||||
os.MkdirAll(repoPath, os.ModePerm)
|
||||
_, stderr, err := process.ExecDir(-1, repoPath,
|
||||
fmt.Sprintf("initRepository(git init --bare): %s", repoPath),
|
||||
"git", "init", "--bare")
|
||||
if err != nil {
|
||||
return errors.New("initRepository(git init --bare): " + stderr)
|
||||
}
|
||||
|
||||
if err := createUpdateHook(repoPath); err != nil {
|
||||
|
@ -434,7 +428,7 @@ func initRepository(e Engine, f string, u *User, repo *Repository, initReadme bo
|
|||
tmpDir := filepath.Join(os.TempDir(), com.ToStr(time.Now().Nanosecond()))
|
||||
os.MkdirAll(tmpDir, os.ModePerm)
|
||||
|
||||
_, stderr, err := process.Exec(
|
||||
_, stderr, err = process.Exec(
|
||||
fmt.Sprintf("initRepository(git clone): %s", repoPath),
|
||||
"git", "clone", repoPath, tmpDir)
|
||||
if err != nil {
|
||||
|
@ -451,43 +445,36 @@ func initRepository(e Engine, f string, u *User, repo *Repository, initReadme bo
|
|||
}
|
||||
}
|
||||
|
||||
// FIXME: following two can be merged.
|
||||
|
||||
// .gitignore
|
||||
filePath := "conf/gitignore/" + repoLang
|
||||
if com.IsFile(filePath) {
|
||||
targetPath := path.Join(tmpDir, fileName["gitign"])
|
||||
if com.IsFile(filePath) {
|
||||
if err = com.Copy(filePath, targetPath); err != nil {
|
||||
return err
|
||||
}
|
||||
} else {
|
||||
// Check custom files.
|
||||
filePath = path.Join(setting.CustomPath, "conf/gitignore", repoLang)
|
||||
if com.IsFile(filePath) {
|
||||
if err := com.Copy(filePath, targetPath); err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
// Copy custom file when available.
|
||||
customPath := path.Join(setting.CustomPath, "conf/gitignore", repoLang)
|
||||
targetPath := path.Join(tmpDir, fileName["gitign"])
|
||||
if com.IsFile(customPath) {
|
||||
if err := com.Copy(customPath, targetPath); err != nil {
|
||||
return fmt.Errorf("copy gitignore: %v", err)
|
||||
}
|
||||
} else if com.IsSliceContainsStr(Gitignores, repoLang) {
|
||||
if err = ioutil.WriteFile(targetPath,
|
||||
bindata.MustAsset(path.Join("conf/gitignore", repoLang)), os.ModePerm); err != nil {
|
||||
return fmt.Errorf("generate gitignore: %v", err)
|
||||
}
|
||||
} else {
|
||||
delete(fileName, "gitign")
|
||||
}
|
||||
|
||||
// LICENSE
|
||||
filePath = "conf/license/" + license
|
||||
if com.IsFile(filePath) {
|
||||
targetPath := path.Join(tmpDir, fileName["license"])
|
||||
if com.IsFile(filePath) {
|
||||
if err = com.Copy(filePath, targetPath); err != nil {
|
||||
return err
|
||||
}
|
||||
} else {
|
||||
// Check custom files.
|
||||
filePath = path.Join(setting.CustomPath, "conf/license", license)
|
||||
if com.IsFile(filePath) {
|
||||
if err := com.Copy(filePath, targetPath); err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
customPath = path.Join(setting.CustomPath, "conf/license", license)
|
||||
targetPath = path.Join(tmpDir, fileName["license"])
|
||||
if com.IsFile(customPath) {
|
||||
if err = com.Copy(customPath, targetPath); err != nil {
|
||||
return fmt.Errorf("copy license: %v", err)
|
||||
}
|
||||
} else if com.IsSliceContainsStr(Licenses, license) {
|
||||
if err = ioutil.WriteFile(targetPath,
|
||||
bindata.MustAsset(path.Join("conf/license", license)), os.ModePerm); err != nil {
|
||||
return fmt.Errorf("generate license: %v", err)
|
||||
}
|
||||
} else {
|
||||
delete(fileName, "license")
|
||||
|
|
1041
modules/bindata/bindata.go
Normal file
1041
modules/bindata/bindata.go
Normal file
File diff suppressed because one or more lines are too long
|
@ -20,6 +20,7 @@ import (
|
|||
"github.com/macaron-contrib/session"
|
||||
"gopkg.in/ini.v1"
|
||||
|
||||
"github.com/gogits/gogs/modules/bindata"
|
||||
"github.com/gogits/gogs/modules/log"
|
||||
// "github.com/gogits/gogs/modules/ssh"
|
||||
)
|
||||
|
@ -131,7 +132,6 @@ var (
|
|||
|
||||
// Global setting objects.
|
||||
Cfg *ini.File
|
||||
ConfRootPath string
|
||||
CustomPath string // Custom directory path.
|
||||
CustomConf string
|
||||
ProdMode bool
|
||||
|
@ -165,8 +165,7 @@ func WorkDir() (string, error) {
|
|||
|
||||
func forcePathSeparator(path string) {
|
||||
if strings.Contains(path, "\\") {
|
||||
fmt.Println("Do not use '\\' or '\\\\' in paths, instead, please use '/' in all places")
|
||||
os.Exit(1)
|
||||
log.Fatal(4, "Do not use '\\' or '\\\\' in paths, instead, please use '/' in all places")
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -177,9 +176,8 @@ func NewConfigContext() {
|
|||
if err != nil {
|
||||
log.Fatal(4, "Fail to get work directory: %v", err)
|
||||
}
|
||||
ConfRootPath = path.Join(workDir, "conf")
|
||||
|
||||
Cfg, err = ini.Load(path.Join(workDir, "conf/app.ini"))
|
||||
Cfg, err = ini.Load(bindata.MustAsset("conf/app.ini"))
|
||||
if err != nil {
|
||||
log.Fatal(4, "Fail to parse 'conf/app.ini': %v", err)
|
||||
}
|
||||
|
|
Reference in a new issue