Browse Source

Put default config into binary

tags/v0.9.99
Unknwon 9 years ago
parent
commit
e6cf83b8c0
7 changed files with 1097 additions and 53 deletions
  1. 1
    0
      .bra.toml
  2. 12
    2
      cmd/web.go
  3. 7
    0
      conf/README
  4. BIN
      conf/content/git-bare.zip
  5. 33
    46
      models/repo.go
  6. 1041
    0
      modules/bindata/bindata.go
  7. 3
    5
      modules/setting/setting.go

+ 1
- 0
.bra.toml View File

watch_exts = [".go", ".ini"] watch_exts = [".go", ".ini"]
build_delay = 1500 build_delay = 1500
cmds = [ cmds = [
#["go-bindata", "-o=modules/bindata/bindata.go", "-ignore=\\.DS_Store|README", "-pkg=bindata", "conf/..."],
["go", "install", "-tags", "sqlite cert"],# redis memcache ["go", "install", "-tags", "sqlite cert"],# redis memcache
["go", "build", "-tags", "sqlite cert"], ["go", "build", "-tags", "sqlite cert"],
["./gogs", "web"] ["./gogs", "web"]

+ 12
- 2
cmd/web.go View File

"github.com/gogits/gogs/modules/auth/apiv1" "github.com/gogits/gogs/modules/auth/apiv1"
"github.com/gogits/gogs/modules/avatar" "github.com/gogits/gogs/modules/avatar"
"github.com/gogits/gogs/modules/base" "github.com/gogits/gogs/modules/base"
"github.com/gogits/gogs/modules/bindata"
"github.com/gogits/gogs/modules/git" "github.com/gogits/gogs/modules/git"
"github.com/gogits/gogs/modules/log" "github.com/gogits/gogs/modules/log"
"github.com/gogits/gogs/modules/middleware" "github.com/gogits/gogs/modules/middleware"
{"github.com/macaron-contrib/binding", binding.Version, "0.0.6"}, {"github.com/macaron-contrib/binding", binding.Version, "0.0.6"},
{"github.com/macaron-contrib/cache", cache.Version, "0.0.7"}, {"github.com/macaron-contrib/cache", cache.Version, "0.0.7"},
{"github.com/macaron-contrib/csrf", csrf.Version, "0.0.3"}, {"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"}, {"github.com/macaron-contrib/session", session.Version, "0.1.6"},
{"gopkg.in/ini.v1", ini.Version, "1.2.0"}, {"gopkg.in/ini.v1", ini.Version, "1.2.0"},
} }
Funcs: []template.FuncMap{base.TemplateFuncs}, Funcs: []template.FuncMap{base.TemplateFuncs},
IndentJSON: macaron.Env != macaron.PROD, 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{ m.Use(i18n.I18n(i18n.Options{
SubURL: setting.AppSubUrl, SubURL: setting.AppSubUrl,
Directory: path.Join(setting.ConfRootPath, "locale"),
Files: localFiles,
CustomDirectory: path.Join(setting.CustomPath, "conf/locale"), CustomDirectory: path.Join(setting.CustomPath, "conf/locale"),
Langs: setting.Langs, Langs: setting.Langs,
Names: setting.Names, Names: setting.Names,

+ 7
- 0
conf/README View File

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/...

BIN
conf/content/git-bare.zip View File


+ 33
- 46
models/repo.go View File

"github.com/Unknwon/com" "github.com/Unknwon/com"


"github.com/gogits/gogs/modules/base" "github.com/gogits/gogs/modules/base"
"github.com/gogits/gogs/modules/bindata"
"github.com/gogits/gogs/modules/git" "github.com/gogits/gogs/modules/git"
"github.com/gogits/gogs/modules/log" "github.com/gogits/gogs/modules/log"
"github.com/gogits/gogs/modules/process" "github.com/gogits/gogs/modules/process"
types := []string{"gitignore", "license"} types := []string{"gitignore", "license"}
typeFiles := make([][]string, 2) typeFiles := make([][]string, 2)
for i, t := range types { for i, t := range types {
files, err := com.StatDir(path.Join("conf", t))
files, err := bindata.AssetDir("conf/" + 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)
} }
return repo, UpdateRepository(repo, false) 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. // initRepoCommit temporarily changes with work directory.
func initRepoCommit(tmpPath string, sig *git.Signature) (err error) { func initRepoCommit(tmpPath string, sig *git.Signature) (err error) {
var stderr string var stderr string
func initRepository(e Engine, f string, u *User, repo *Repository, initReadme bool, repoLang, license string) error { func initRepository(e Engine, f string, u *User, repo *Repository, initReadme bool, repoLang, license string) error {
repoPath := RepoPath(u.Name, repo.Name) 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 { if err := createUpdateHook(repoPath); err != nil {
tmpDir := filepath.Join(os.TempDir(), com.ToStr(time.Now().Nanosecond())) tmpDir := filepath.Join(os.TempDir(), com.ToStr(time.Now().Nanosecond()))
os.MkdirAll(tmpDir, os.ModePerm) os.MkdirAll(tmpDir, os.ModePerm)


_, stderr, err := process.Exec(
_, stderr, err = process.Exec(
fmt.Sprintf("initRepository(git clone): %s", repoPath), fmt.Sprintf("initRepository(git clone): %s", repoPath),
"git", "clone", repoPath, tmpDir) "git", "clone", repoPath, tmpDir)
if err != nil { if err != nil {
} }
} }


// FIXME: following two can be merged.

// .gitignore // .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 { } else {
delete(fileName, "gitign") delete(fileName, "gitign")
} }


// LICENSE // 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 { } else {
delete(fileName, "license") delete(fileName, "license")

+ 1041
- 0
modules/bindata/bindata.go
File diff suppressed because it is too large
View File


+ 3
- 5
modules/setting/setting.go View File

"github.com/macaron-contrib/session" "github.com/macaron-contrib/session"
"gopkg.in/ini.v1" "gopkg.in/ini.v1"


"github.com/gogits/gogs/modules/bindata"
"github.com/gogits/gogs/modules/log" "github.com/gogits/gogs/modules/log"
// "github.com/gogits/gogs/modules/ssh" // "github.com/gogits/gogs/modules/ssh"
) )


// Global setting objects. // Global setting objects.
Cfg *ini.File Cfg *ini.File
ConfRootPath string
CustomPath string // Custom directory path. CustomPath string // Custom directory path.
CustomConf string CustomConf string
ProdMode bool ProdMode bool


func forcePathSeparator(path string) { func forcePathSeparator(path string) {
if strings.Contains(path, "\\") { 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")
} }
} }


if err != nil { if err != nil {
log.Fatal(4, "Fail to get work directory: %v", err) 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 { if err != nil {
log.Fatal(4, "Fail to parse 'conf/app.ini': %v", err) log.Fatal(4, "Fail to parse 'conf/app.ini': %v", err)
} }

Loading…
Cancel
Save