mirror of
				https://github.com/go-gitea/gitea.git
				synced 2025-10-31 21:28:11 +09:00 
			
		
		
		
	Fix all possible setting error related storages and added some tests (#23911)
Follow up #22405 Fix #20703 This PR rewrites storage configuration read sequences with some breaks and tests. It becomes more strict than before and also fixed some inherit problems. - Move storage's MinioConfig struct into setting, so after the configuration loading, the values will be stored into the struct but not still on some section. - All storages configurations should be stored on one section, configuration items cannot be overrided by multiple sections. The prioioty of configuration is `[attachment]` > `[storage.attachments]` | `[storage.customized]` > `[storage]` > `default` - For extra override configuration items, currently are `SERVE_DIRECT`, `MINIO_BASE_PATH`, `MINIO_BUCKET`, which could be configured in another section. The prioioty of the override configuration is `[attachment]` > `[storage.attachments]` > `default`. - Add more tests for storages configurations. - Update the storage documentations. --------- Co-authored-by: wxiaoguang <wxiaoguang@gmail.com>
This commit is contained in:
		| @@ -4,20 +4,19 @@ | ||||
| package setting | ||||
|  | ||||
| import ( | ||||
| 	"fmt" | ||||
| 	"math" | ||||
| 	"net/url" | ||||
| 	"os" | ||||
| 	"path/filepath" | ||||
|  | ||||
| 	"code.gitea.io/gitea/modules/log" | ||||
|  | ||||
| 	"github.com/dustin/go-humanize" | ||||
| ) | ||||
|  | ||||
| // Package registry settings | ||||
| var ( | ||||
| 	Packages = struct { | ||||
| 		Storage | ||||
| 		Storage           *Storage | ||||
| 		Enabled           bool | ||||
| 		ChunkedUploadPath string | ||||
| 		RegistryHost      string | ||||
| @@ -51,13 +50,21 @@ var ( | ||||
| 	} | ||||
| ) | ||||
|  | ||||
| func loadPackagesFrom(rootCfg ConfigProvider) { | ||||
| 	sec := rootCfg.Section("packages") | ||||
| 	if err := sec.MapTo(&Packages); err != nil { | ||||
| 		log.Fatal("Failed to map Packages settings: %v", err) | ||||
| func loadPackagesFrom(rootCfg ConfigProvider) (err error) { | ||||
| 	sec, _ := rootCfg.GetSection("packages") | ||||
| 	if sec == nil { | ||||
| 		Packages.Storage, err = getStorage(rootCfg, "packages", "", nil) | ||||
| 		return err | ||||
| 	} | ||||
|  | ||||
| 	Packages.Storage = getStorage(rootCfg, "packages", "", nil) | ||||
| 	if err = sec.MapTo(&Packages); err != nil { | ||||
| 		return fmt.Errorf("failed to map Packages settings: %v", err) | ||||
| 	} | ||||
|  | ||||
| 	Packages.Storage, err = getStorage(rootCfg, "packages", "", sec) | ||||
| 	if err != nil { | ||||
| 		return err | ||||
| 	} | ||||
|  | ||||
| 	appURL, _ := url.Parse(AppURL) | ||||
| 	Packages.RegistryHost = appURL.Host | ||||
| @@ -68,7 +75,7 @@ func loadPackagesFrom(rootCfg ConfigProvider) { | ||||
| 	} | ||||
|  | ||||
| 	if err := os.MkdirAll(Packages.ChunkedUploadPath, os.ModePerm); err != nil { | ||||
| 		log.Error("Unable to create chunked upload directory: %s (%v)", Packages.ChunkedUploadPath, err) | ||||
| 		return fmt.Errorf("unable to create chunked upload directory: %s (%v)", Packages.ChunkedUploadPath, err) | ||||
| 	} | ||||
|  | ||||
| 	Packages.LimitTotalOwnerSize = mustBytes(sec, "LIMIT_TOTAL_OWNER_SIZE") | ||||
| @@ -93,6 +100,7 @@ func loadPackagesFrom(rootCfg ConfigProvider) { | ||||
| 	Packages.LimitSizeRubyGems = mustBytes(sec, "LIMIT_SIZE_RUBYGEMS") | ||||
| 	Packages.LimitSizeSwift = mustBytes(sec, "LIMIT_SIZE_SWIFT") | ||||
| 	Packages.LimitSizeVagrant = mustBytes(sec, "LIMIT_SIZE_VAGRANT") | ||||
| 	return nil | ||||
| } | ||||
|  | ||||
| func mustBytes(section ConfigSection, key string) int64 { | ||||
|   | ||||
		Reference in New Issue
	
	Block a user