add sync registry env (#5294)

By default Harbor will call catalog API of registry and sync the result to DB, this becomes problematic when registry is configured to custom storage service, there maybe inconsistent result and the whole process may be very time consuming.
So in this commit a env var SYNC_REGISTRY is introduced if user want Harbor to sync the repo when it starts up, by default it's false.
This commit is contained in:
timchenxiaoyu 2018-07-13 11:15:41 +08:00 committed by Daniel Jiang
parent f7a29363ed
commit a912a55ac2
2 changed files with 17 additions and 2 deletions

View File

@ -6,3 +6,4 @@ GODEBUG=netdns=cgo
ADMINSERVER_URL=$adminserver_url
UAA_CA_ROOT=/etc/ui/certificates/uaa_ca.pem
_REDIS_URL=$redis_url
SYNC_REGISTRY=false

View File

@ -18,6 +18,7 @@ import (
"fmt"
"os"
"reflect"
"strconv"
"github.com/vmware/harbor/src/common/utils"
"github.com/vmware/harbor/src/common/utils/log"
@ -147,9 +148,22 @@ func main() {
beego.InsertFilter("/api/*", beego.BeforeRouter, filter.MediaTypeFilter("application/json"))
initRouters()
if err := api.SyncRegistry(config.GlobalProjectMgr); err != nil {
log.Error(err)
syncRegistry := os.Getenv("SYNC_REGISTRY")
sync, err := strconv.ParseBool(syncRegistry)
if err != nil{
log.Errorf("Failed to parse SYNC_REGISTRY: %v", err)
//if err set it default to false
sync = false;
}
if sync{
if err := api.SyncRegistry(config.GlobalProjectMgr); err != nil {
log.Error(err)
}
}else {
log.Infof("Because SYNC_REGISTRY set false , no need to sync registry \n")
}
log.Info("Init proxy")
proxy.Init()
//go proxy.StartProxy()