aboutsummaryrefslogtreecommitdiffstats
path: root/modules/setting/lfs.go
diff options
context:
space:
mode:
authorLunny Xiao <xiaolunwen@gmail.com>2020-09-29 17:05:13 +0800
committerGitHub <noreply@github.com>2020-09-29 12:05:13 +0300
commit3878e985b66cc6d4cb4d2b0e7406d5cf91af6191 (patch)
tree31229c29c2b57041d1941ec28b043165cbe4642d /modules/setting/lfs.go
parent4c6ac08182b5a14eaaffaafafef160bd90c4ae81 (diff)
downloadgitea-3878e985b66cc6d4cb4d2b0e7406d5cf91af6191.tar.gz
gitea-3878e985b66cc6d4cb4d2b0e7406d5cf91af6191.zip
Add default storage configurations (#12813)
Signed-off-by: Andrew Thornton <art27@cantab.net> Co-authored-by: zeripath <art27@cantab.net>
Diffstat (limited to 'modules/setting/lfs.go')
-rw-r--r--modules/setting/lfs.go62
1 files changed, 36 insertions, 26 deletions
diff --git a/modules/setting/lfs.go b/modules/setting/lfs.go
index a740a6d629..da34d3a5ff 100644
--- a/modules/setting/lfs.go
+++ b/modules/setting/lfs.go
@@ -21,27 +21,14 @@ import (
// LFS represents the configuration for Git LFS
var LFS = struct {
StartServer bool `ini:"LFS_START_SERVER"`
- ContentPath string `ini:"LFS_CONTENT_PATH"`
JWTSecretBase64 string `ini:"LFS_JWT_SECRET"`
JWTSecretBytes []byte `ini:"-"`
HTTPAuthExpiry time.Duration `ini:"LFS_HTTP_AUTH_EXPIRY"`
MaxFileSize int64 `ini:"LFS_MAX_FILE_SIZE"`
LocksPagingNum int `ini:"LFS_LOCKS_PAGING_NUM"`
- StoreType string
- ServeDirect bool
- Minio struct {
- Endpoint string
- AccessKeyID string
- SecretAccessKey string
- UseSSL bool
- Bucket string
- Location string
- BasePath string
- }
-}{
- StoreType: "local",
-}
+ Storage
+}{}
func newLFSService() {
sec := Cfg.Section("server")
@@ -49,10 +36,41 @@ func newLFSService() {
log.Fatal("Failed to map LFS settings: %v", err)
}
- LFS.ContentPath = sec.Key("LFS_CONTENT_PATH").MustString(filepath.Join(AppDataPath, "lfs"))
- if !filepath.IsAbs(LFS.ContentPath) {
- LFS.ContentPath = filepath.Join(AppWorkPath, LFS.ContentPath)
+ lfsSec := Cfg.Section("lfs")
+ LFS.Storage.Type = lfsSec.Key("STORAGE_TYPE").MustString("")
+ if LFS.Storage.Type == "" {
+ LFS.Storage.Type = "default"
+ }
+
+ if LFS.Storage.Type != LocalStorageType && LFS.Storage.Type != MinioStorageType {
+ storage, ok := storages[LFS.Storage.Type]
+ if !ok {
+ log.Fatal("Failed to get lfs storage type: %s", LFS.Storage.Type)
+ }
+ LFS.Storage = storage
}
+
+ // Override
+ LFS.ServeDirect = lfsSec.Key("SERVE_DIRECT").MustBool(LFS.ServeDirect)
+ switch LFS.Storage.Type {
+ case LocalStorageType:
+ // keep compatible
+ LFS.Path = sec.Key("LFS_CONTENT_PATH").MustString(filepath.Join(AppDataPath, "lfs"))
+ LFS.Path = lfsSec.Key("PATH").MustString(LFS.Path)
+ if !filepath.IsAbs(LFS.Path) {
+ LFS.Path = filepath.Join(AppWorkPath, LFS.Path)
+ }
+
+ case MinioStorageType:
+ LFS.Minio.Endpoint = lfsSec.Key("MINIO_ENDPOINT").MustString(LFS.Minio.Endpoint)
+ LFS.Minio.AccessKeyID = lfsSec.Key("MINIO_ACCESS_KEY_ID").MustString(LFS.Minio.AccessKeyID)
+ LFS.Minio.SecretAccessKey = lfsSec.Key("MINIO_SECRET_ACCESS_KEY").MustString(LFS.Minio.SecretAccessKey)
+ LFS.Minio.Bucket = lfsSec.Key("MINIO_BUCKET").MustString(LFS.Minio.Bucket)
+ LFS.Minio.Location = lfsSec.Key("MINIO_LOCATION").MustString(LFS.Minio.Location)
+ LFS.Minio.UseSSL = lfsSec.Key("MINIO_USE_SSL").MustBool(LFS.Minio.UseSSL)
+ LFS.Minio.BasePath = lfsSec.Key("MINIO_BASE_PATH").MustString("lfs/")
+ }
+
if LFS.LocksPagingNum == 0 {
LFS.LocksPagingNum = 50
}
@@ -92,14 +110,6 @@ func newLFSService() {
}
}
-func ensureLFSDirectory() {
- if LFS.StartServer {
- if err := os.MkdirAll(LFS.ContentPath, 0700); err != nil {
- log.Fatal("Failed to create '%s': %v", LFS.ContentPath, err)
- }
- }
-}
-
// CheckLFSVersion will check lfs version, if not satisfied, then disable it.
func CheckLFSVersion() {
if LFS.StartServer {