go.chromium.org/luci@v0.0.0-20240309015107-7cdc2e660f33/config_service/cmd/config_server/main.go (about) 1 // Copyright 2023 The LUCI Authors. 2 // 3 // Licensed under the Apache License, Version 2.0 (the "License"); 4 // you may not use this file except in compliance with the License. 5 // You may obtain a copy of the License at 6 // 7 // http://www.apache.org/licenses/LICENSE-2.0 8 // 9 // Unless required by applicable law or agreed to in writing, software 10 // distributed under the License is distributed on an "AS IS" BASIS, 11 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 // See the License for the specific language governing permissions and 13 // limitations under the License. 14 15 package main 16 17 import ( 18 "flag" 19 "fmt" 20 21 // Enable gRPC server side gzip compression. 22 _ "google.golang.org/grpc/encoding/gzip" 23 24 "go.chromium.org/luci/common/errors" 25 cfgValidation "go.chromium.org/luci/config/validation" 26 "go.chromium.org/luci/gae/service/info" 27 "go.chromium.org/luci/server" 28 "go.chromium.org/luci/server/cron" 29 "go.chromium.org/luci/server/encryptedcookies" 30 "go.chromium.org/luci/server/gaeemulation" 31 "go.chromium.org/luci/server/module" 32 "go.chromium.org/luci/server/redisconn" 33 "go.chromium.org/luci/server/secrets" 34 "go.chromium.org/luci/server/tq" 35 36 // Register validation rules for LUCI Config itself. 37 _ "go.chromium.org/luci/config_service/internal/rules" 38 // Store auth sessions in the datastore. 39 _ "go.chromium.org/luci/server/encryptedcookies/session/datastore" 40 41 "go.chromium.org/luci/config_service/internal/clients" 42 "go.chromium.org/luci/config_service/internal/importer" 43 "go.chromium.org/luci/config_service/internal/retention" 44 "go.chromium.org/luci/config_service/internal/schema" 45 "go.chromium.org/luci/config_service/internal/service" 46 "go.chromium.org/luci/config_service/internal/settings" 47 "go.chromium.org/luci/config_service/internal/ui" 48 "go.chromium.org/luci/config_service/internal/validation" 49 configpb "go.chromium.org/luci/config_service/proto" 50 "go.chromium.org/luci/config_service/rpc" 51 ) 52 53 func main() { 54 mods := []module.Module{ 55 cron.NewModuleFromFlags(), 56 encryptedcookies.NewModuleFromFlags(), 57 gaeemulation.NewModuleFromFlags(), 58 redisconn.NewModuleFromFlags(), 59 secrets.NewModuleFromFlags(), 60 tq.NewModuleFromFlags(), 61 } 62 63 loc := settings.GlobalConfigLoc{} 64 loc.RegisterFlags(flag.CommandLine) 65 66 server.Main(nil, mods, func(srv *server.Server) error { 67 if err := loc.Validate(); err != nil { 68 return errors.Annotate(err, "Wrong global config location flag value").Err() 69 } 70 srv.Context = settings.WithGlobalConfigLoc(srv.Context, loc.GitilesLocation) 71 72 // Install a global Cloud Storage client. 73 gsClient, err := clients.NewGsProdClient(srv.Context) 74 if err != nil { 75 return errors.Annotate(err, "failed to initiate the global GCS client").Err() 76 } 77 srv.Context = clients.WithGsClient(srv.Context, gsClient) 78 gsBucket := fmt.Sprintf("storage-%s", info.AppID(srv.Context)) 79 80 serviceFinder, err := service.NewFinder(srv.Context) 81 if err != nil { 82 return errors.Annotate(err, "failed to create service finder").Err() 83 } 84 srv.RunInBackground("refresh-service-finder", serviceFinder.RefreshPeriodically) 85 validator := &validation.Validator{ 86 GsClient: gsClient, 87 Finder: serviceFinder, 88 SelfRuleSet: &cfgValidation.Rules, 89 } 90 importer := importer.Importer{ 91 Validator: validator, 92 GSBucket: gsBucket, 93 } 94 95 configsServer := &rpc.Configs{ 96 Validator: validator, 97 GSValidationBucket: gsBucket, 98 } 99 configpb.RegisterConfigsServer(srv, configsServer) 100 cron.RegisterHandler("update-services", service.Update) 101 cron.RegisterHandler("delete-configs", retention.DeleteStaleConfigs) 102 importer.RegisterImportConfigsCron(&tq.Default) 103 ui.InstallHandlers(srv, configsServer, importer) 104 schema.InstallHandler(srv.Routes) 105 return nil 106 }) 107 }