2016-05-13 15:43:17 +02:00
|
|
|
package config
|
|
|
|
|
|
|
|
import (
|
2016-05-23 13:39:13 +02:00
|
|
|
"fmt"
|
2016-05-13 15:43:17 +02:00
|
|
|
"os"
|
|
|
|
"strconv"
|
2016-05-16 07:57:30 +02:00
|
|
|
|
|
|
|
"github.com/vmware/harbor/utils/log"
|
2016-05-13 15:43:17 +02:00
|
|
|
)
|
|
|
|
|
|
|
|
const defaultMaxWorkers int = 10
|
|
|
|
|
|
|
|
var maxJobWorkers int
|
2016-05-25 09:24:44 +02:00
|
|
|
var localURL string
|
2016-05-23 13:39:13 +02:00
|
|
|
var logDir string
|
2016-05-25 09:24:44 +02:00
|
|
|
var uiSecret string
|
2016-05-13 15:43:17 +02:00
|
|
|
|
|
|
|
func init() {
|
|
|
|
maxWorkersEnv := os.Getenv("MAX_JOB_WORKERS")
|
|
|
|
maxWorkers64, err := strconv.ParseInt(maxWorkersEnv, 10, 32)
|
|
|
|
maxJobWorkers = int(maxWorkers64)
|
|
|
|
if err != nil {
|
|
|
|
log.Warningf("Failed to parse max works setting, error: %v, the default value: %d will be used", err, defaultMaxWorkers)
|
|
|
|
maxJobWorkers = defaultMaxWorkers
|
|
|
|
}
|
|
|
|
|
2016-05-27 10:21:32 +02:00
|
|
|
localURL = os.Getenv("HARBOR_URL")
|
2016-05-25 09:24:44 +02:00
|
|
|
if len(localURL) == 0 {
|
2016-05-27 10:21:32 +02:00
|
|
|
localURL = "http://registry:5000/"
|
2016-05-13 15:43:17 +02:00
|
|
|
}
|
|
|
|
|
2016-05-23 13:39:13 +02:00
|
|
|
logDir = os.Getenv("LOG_DIR")
|
|
|
|
if len(logDir) == 0 {
|
|
|
|
logDir = "/var/log"
|
|
|
|
}
|
|
|
|
|
|
|
|
f, err := os.Open(logDir)
|
|
|
|
defer f.Close()
|
|
|
|
if err != nil {
|
|
|
|
panic(err)
|
|
|
|
}
|
|
|
|
finfo, err := f.Stat()
|
|
|
|
if err != nil {
|
|
|
|
panic(err)
|
|
|
|
}
|
|
|
|
if !finfo.IsDir() {
|
|
|
|
panic(fmt.Sprintf("%s is not a direcotry", logDir))
|
|
|
|
}
|
|
|
|
|
2016-05-25 09:24:44 +02:00
|
|
|
uiSecret = os.Getenv("UI_SECRET")
|
|
|
|
if len(uiSecret) == 0 {
|
|
|
|
panic("UI Secret is not set")
|
|
|
|
}
|
|
|
|
|
2016-05-13 15:43:17 +02:00
|
|
|
log.Debugf("config: maxJobWorkers: %d", maxJobWorkers)
|
2016-05-25 09:24:44 +02:00
|
|
|
log.Debugf("config: localHarborURL: %s", localURL)
|
2016-05-23 13:39:13 +02:00
|
|
|
log.Debugf("config: logDir: %s", logDir)
|
2016-05-25 09:24:44 +02:00
|
|
|
log.Debugf("config: uiSecret: ******")
|
2016-05-13 15:43:17 +02:00
|
|
|
}
|
|
|
|
|
2016-05-30 08:44:03 +02:00
|
|
|
// MaxJobWorkers ...
|
2016-05-13 15:43:17 +02:00
|
|
|
func MaxJobWorkers() int {
|
|
|
|
return maxJobWorkers
|
|
|
|
}
|
|
|
|
|
2016-05-30 08:44:03 +02:00
|
|
|
// LocalHarborURL returns the local registry url, job service will use this URL to pull manifest and repository.
|
2016-05-25 09:24:44 +02:00
|
|
|
func LocalHarborURL() string {
|
|
|
|
return localURL
|
2016-05-13 15:43:17 +02:00
|
|
|
}
|
2016-05-23 13:39:13 +02:00
|
|
|
|
2016-05-30 08:44:03 +02:00
|
|
|
// LogDir returns the absolute path to which the log file will be written
|
2016-05-23 13:39:13 +02:00
|
|
|
func LogDir() string {
|
|
|
|
return logDir
|
|
|
|
}
|
2016-05-25 09:24:44 +02:00
|
|
|
|
2016-05-30 08:44:03 +02:00
|
|
|
// UISecret will return the value of secret cookie for jobsevice to call UI API.
|
2016-05-25 09:24:44 +02:00
|
|
|
func UISecret() string {
|
|
|
|
return uiSecret
|
|
|
|
}
|