mirror of
https://github.com/goharbor/harbor.git
synced 2024-11-25 03:35:21 +01:00
Merge pull request #5310 from reasonerjt/adminserver-update-schema
Let adminserver initialise the DB schema.
This commit is contained in:
commit
8a92019e8e
@ -7,7 +7,7 @@ RUN tdnf erase vim -y \
|
||||
&& groupadd -r -g 10000 harbor && useradd --no-log-init -r -g 10000 -u 10000 harbor \
|
||||
&& mkdir /harbor/
|
||||
COPY ./make/dev/adminserver/harbor_adminserver ./make/photon/adminserver/start.sh /harbor/
|
||||
#There is a race condition that both ui and adminserver may initialize schema
|
||||
#As UI will be blocked until adminserver is ready, let adminserver do the initialise work for DB
|
||||
COPY ./make/migrations /harbor/migrations
|
||||
|
||||
HEALTHCHECK CMD curl --fail -s http://127.0.0.1:8080/api/ping || exit 1
|
||||
|
@ -11,8 +11,6 @@ HEALTHCHECK CMD curl --fail -s http://127.0.0.1:8080/api/ping || exit 1
|
||||
COPY ./make/dev/ui/harbor_ui ./src/favicon.ico ./make/photon/ui/start.sh ./UIVERSION /harbor/
|
||||
COPY ./src/ui/views /harbor/views
|
||||
COPY ./src/ui/static /harbor/static
|
||||
#There is a race condition that both ui and adminserver may initialize schema
|
||||
COPY ./make/migrations /harbor/migrations
|
||||
|
||||
RUN chmod u+x /harbor/start.sh /harbor/harbor_ui
|
||||
WORKDIR /harbor/
|
||||
|
@ -245,9 +245,24 @@ func parseStringToBool(str string) (interface{}, error) {
|
||||
// Init system configurations. If env RESET is set or configurations
|
||||
// read from storage driver is null, load all configurations from env
|
||||
func Init() (err error) {
|
||||
if err = initCfgStore(); err != nil {
|
||||
//init database
|
||||
envCfgs := map[string]interface{}{}
|
||||
if err := LoadFromEnv(envCfgs, true); err != nil {
|
||||
return err
|
||||
}
|
||||
db := GetDatabaseFromCfg(envCfgs)
|
||||
//Initialize the schema, then register the DB.
|
||||
if err := dao.UpgradeSchema(db); err != nil {
|
||||
return err
|
||||
}
|
||||
if err := dao.InitDatabase(db); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
if err := initCfgStore(); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
cfgs := map[string]interface{}{}
|
||||
//Use reload key to avoid reset customed setting after restart
|
||||
curCfgs, err := CfgStore.Read()
|
||||
@ -288,16 +303,6 @@ func initCfgStore() (err error) {
|
||||
log.Infof("the path of json configuration storage: %s", path)
|
||||
|
||||
if drivertype == common.CfgDriverDB {
|
||||
//init database
|
||||
cfgs := map[string]interface{}{}
|
||||
if err = LoadFromEnv(cfgs, true); err != nil {
|
||||
return err
|
||||
}
|
||||
cfgdb := GetDatabaseFromCfg(cfgs)
|
||||
//Initialize the schema.
|
||||
if err = dao.InitDatabase(cfgdb, true); err != nil {
|
||||
return err
|
||||
}
|
||||
CfgStore, err = database.NewCfgStore()
|
||||
if err != nil {
|
||||
return err
|
||||
|
@ -46,7 +46,6 @@ type Database interface {
|
||||
|
||||
// InitClairDB ...
|
||||
func InitClairDB(clairDB *models.PostGreSQL) error {
|
||||
//Except for password other information will not be configurable, so keep it hard coded for 1.2.0.
|
||||
p := &pgsql{
|
||||
host: clairDB.Host,
|
||||
port: strconv.Itoa(clairDB.Port),
|
||||
@ -62,25 +61,26 @@ func InitClairDB(clairDB *models.PostGreSQL) error {
|
||||
return nil
|
||||
}
|
||||
|
||||
// InitDatabase initializes the database, there's an optional parm as a flag
|
||||
// to indicate whether it should initialize the schema.
|
||||
func InitDatabase(database *models.Database, initSchema ...bool) error {
|
||||
// UpgradeSchema will call the internal migrator to upgrade schema based on the setting of database.
|
||||
func UpgradeSchema(database *models.Database) error {
|
||||
db, err := getDatabase(database)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
return db.UpgradeSchema()
|
||||
}
|
||||
|
||||
// InitDatabase registers the database
|
||||
func InitDatabase(database *models.Database) error {
|
||||
db, err := getDatabase(database)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
log.Infof("initializing database: %s", db.String())
|
||||
log.Infof("Registering database: %s", db.String())
|
||||
if err := db.Register(); err != nil {
|
||||
return err
|
||||
}
|
||||
if len(initSchema) > 0 && initSchema[0] {
|
||||
err := db.UpgradeSchema()
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
|
||||
version, err := GetSchemaVersion()
|
||||
if err != nil {
|
||||
return err
|
||||
@ -90,7 +90,7 @@ func InitDatabase(database *models.Database, initSchema ...bool) error {
|
||||
SchemaVersion, version.Version)
|
||||
}
|
||||
|
||||
log.Info("initialize database completed")
|
||||
log.Info("Register database completed")
|
||||
return nil
|
||||
}
|
||||
|
||||
|
@ -92,7 +92,7 @@ func main() {
|
||||
if err != nil {
|
||||
log.Fatalf("failed to get database configuration: %v", err)
|
||||
}
|
||||
if err := dao.InitDatabase(database, true); err != nil {
|
||||
if err := dao.InitDatabase(database); err != nil {
|
||||
log.Fatalf("failed to initialize database: %v", err)
|
||||
}
|
||||
if config.WithClair() {
|
||||
@ -151,16 +151,16 @@ func main() {
|
||||
|
||||
syncRegistry := os.Getenv("SYNC_REGISTRY")
|
||||
sync, err := strconv.ParseBool(syncRegistry)
|
||||
if err != nil{
|
||||
if err != nil {
|
||||
log.Errorf("Failed to parse SYNC_REGISTRY: %v", err)
|
||||
//if err set it default to false
|
||||
sync = false;
|
||||
sync = false
|
||||
}
|
||||
if sync{
|
||||
if sync {
|
||||
if err := api.SyncRegistry(config.GlobalProjectMgr); err != nil {
|
||||
log.Error(err)
|
||||
}
|
||||
}else {
|
||||
} else {
|
||||
log.Infof("Because SYNC_REGISTRY set false , no need to sync registry \n")
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user