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"
|
2018-11-09 03:19:14 +01:00
|
|
|
"errors"
|
2018-03-29 17:30:03 +02:00
|
|
|
"flag"
|
2018-11-05 11:23:31 +01:00
|
|
|
"fmt"
|
2018-03-29 17:30:03 +02:00
|
|
|
|
2019-01-09 10:40:27 +01:00
|
|
|
"github.com/goharbor/harbor/src/common"
|
|
|
|
comcfg "github.com/goharbor/harbor/src/common/config"
|
2018-08-23 09:02:20 +02:00
|
|
|
"github.com/goharbor/harbor/src/jobservice/config"
|
2018-11-09 03:19:14 +01:00
|
|
|
"github.com/goharbor/harbor/src/jobservice/env"
|
|
|
|
"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"
|
|
|
|
"github.com/goharbor/harbor/src/jobservice/utils"
|
2019-01-09 10:40:27 +01:00
|
|
|
"os"
|
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))
|
|
|
|
}
|
|
|
|
|
|
|
|
// Create the root context
|
|
|
|
ctx, cancel := context.WithCancel(context.Background())
|
|
|
|
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
|
2018-11-09 03:19:14 +01:00
|
|
|
runtime.JobService.SetJobContextInitializer(func(ctx *env.Context) (env.JobContext, 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-01-09 10:40:27 +01:00
|
|
|
coreURL := os.Getenv("CORE_URL")
|
|
|
|
configURL := coreURL + common.CoreConfigPath
|
|
|
|
cfgMgr := comcfg.NewRESTCfgManager(configURL, secret)
|
|
|
|
jobCtx := impl.NewContext(ctx.SystemContext, 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
|
2018-11-09 03:19:14 +01:00
|
|
|
})
|
2018-03-29 17:30:03 +02:00
|
|
|
|
2018-09-05 10:16:31 +02:00
|
|
|
// Start
|
2018-11-05 11:23:31 +01:00
|
|
|
runtime.JobService.LoadAndRun(ctx, cancel)
|
2016-12-30 11:04:01 +01:00
|
|
|
}
|