2018-10-18 06:00:18 +02:00
|
|
|
// Copyright Project Harbor Authors
|
|
|
|
//
|
|
|
|
// Licensed under the Apache License, Version 2.0 (the "License");
|
|
|
|
// you may not use this file except in compliance with the License.
|
|
|
|
// You may obtain a copy of the License at
|
|
|
|
//
|
|
|
|
// http://www.apache.org/licenses/LICENSE-2.0
|
|
|
|
//
|
|
|
|
// Unless required by applicable law or agreed to in writing, software
|
|
|
|
// distributed under the License is distributed on an "AS IS" BASIS,
|
|
|
|
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
|
|
// See the License for the specific language governing permissions and
|
|
|
|
// limitations under the License.
|
|
|
|
|
2016-04-20 08:24:17 +02:00
|
|
|
package main
|
|
|
|
|
|
|
|
import (
|
2018-11-05 11:23:31 +01:00
|
|
|
"context"
|
2019-04-29 12:47:29 +02:00
|
|
|
"errors"
|
2018-03-29 17:30:03 +02:00
|
|
|
"flag"
|
2018-11-05 11:23:31 +01:00
|
|
|
"fmt"
|
2019-04-29 12:47:29 +02:00
|
|
|
|
|
|
|
"github.com/goharbor/harbor/src/common"
|
|
|
|
comcfg "github.com/goharbor/harbor/src/common/config"
|
2019-04-18 10:02:49 +02:00
|
|
|
"github.com/goharbor/harbor/src/jobservice/common/utils"
|
2018-08-23 09:02:20 +02:00
|
|
|
"github.com/goharbor/harbor/src/jobservice/config"
|
2019-04-29 12:47:29 +02:00
|
|
|
"github.com/goharbor/harbor/src/jobservice/job"
|
|
|
|
"github.com/goharbor/harbor/src/jobservice/job/impl"
|
2018-08-23 09:02:20 +02:00
|
|
|
"github.com/goharbor/harbor/src/jobservice/logger"
|
|
|
|
"github.com/goharbor/harbor/src/jobservice/runtime"
|
2016-04-20 08:24:17 +02:00
|
|
|
)
|
|
|
|
|
|
|
|
func main() {
|
2018-09-05 10:16:31 +02:00
|
|
|
// Get parameters
|
2018-03-29 17:30:03 +02:00
|
|
|
configPath := flag.String("c", "", "Specify the yaml config file path")
|
|
|
|
flag.Parse()
|
2016-12-30 11:04:01 +01:00
|
|
|
|
2018-09-05 10:16:31 +02:00
|
|
|
// Missing config file
|
2018-03-29 17:30:03 +02:00
|
|
|
if configPath == nil || utils.IsEmptyStr(*configPath) {
|
|
|
|
flag.Usage()
|
2018-11-05 11:23:31 +01:00
|
|
|
panic("no config file is specified")
|
2016-12-30 11:04:01 +01:00
|
|
|
}
|
|
|
|
|
2018-09-05 10:16:31 +02:00
|
|
|
// Load configurations
|
2018-03-29 17:30:03 +02:00
|
|
|
if err := config.DefaultConfig.Load(*configPath, true); err != nil {
|
2018-11-05 11:23:31 +01:00
|
|
|
panic(fmt.Sprintf("load configurations error: %s\n", err))
|
|
|
|
}
|
|
|
|
|
2019-04-19 07:54:23 +02:00
|
|
|
// Append node ID
|
|
|
|
vCtx := context.WithValue(context.Background(), utils.NodeID, utils.GenerateNodeID())
|
2018-11-05 11:23:31 +01:00
|
|
|
// Create the root context
|
2019-04-19 07:54:23 +02:00
|
|
|
ctx, cancel := context.WithCancel(vCtx)
|
2018-11-05 11:23:31 +01:00
|
|
|
defer cancel()
|
|
|
|
|
|
|
|
// Initialize logger
|
|
|
|
if err := logger.Init(ctx); err != nil {
|
|
|
|
panic(err)
|
2017-07-25 15:12:03 +02:00
|
|
|
}
|
2016-06-17 12:54:29 +02:00
|
|
|
|
2018-09-05 10:16:31 +02:00
|
|
|
// Set job context initializer
|
2019-04-29 12:47:29 +02:00
|
|
|
runtime.JobService.SetJobContextInitializer(func(ctx context.Context) (job.Context, error) {
|
2018-03-29 17:30:03 +02:00
|
|
|
secret := config.GetAuthSecret()
|
|
|
|
if utils.IsEmptyStr(secret) {
|
|
|
|
return nil, errors.New("empty auth secret")
|
2017-08-16 10:02:36 +02:00
|
|
|
}
|
2019-07-24 07:10:10 +02:00
|
|
|
coreURL := config.GetCoreURL()
|
2019-01-09 10:40:27 +01:00
|
|
|
configURL := coreURL + common.CoreConfigPath
|
|
|
|
cfgMgr := comcfg.NewRESTCfgManager(configURL, secret)
|
2019-04-22 17:29:19 +02:00
|
|
|
jobCtx := impl.NewContext(ctx, cfgMgr)
|
2018-03-29 17:30:03 +02:00
|
|
|
|
|
|
|
if err := jobCtx.Init(); err != nil {
|
|
|
|
return nil, err
|
2017-07-25 15:12:03 +02:00
|
|
|
}
|
2018-03-29 17:30:03 +02:00
|
|
|
|
|
|
|
return jobCtx, nil
|
2019-04-29 12:47:29 +02:00
|
|
|
})
|
2018-03-29 17:30:03 +02:00
|
|
|
|
2018-09-05 10:16:31 +02:00
|
|
|
// Start
|
2019-04-20 09:00:32 +02:00
|
|
|
if err := runtime.JobService.LoadAndRun(ctx, cancel); err != nil {
|
|
|
|
logger.Fatal(err)
|
|
|
|
}
|
2016-12-30 11:04:01 +01:00
|
|
|
}
|