...

Source file src/github.com/chaos-mesh/chaos-mesh/cmd/chaos-dashboard/main.go

Documentation: github.com/chaos-mesh/chaos-mesh/cmd/chaos-dashboard

     1  // Copyright 2020 Chaos Mesh 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  // See the License for the specific language governing permissions and
    12  // limitations under the License.
    13  
    14  package main
    15  
    16  import (
    17  	"flag"
    18  	"os"
    19  
    20  	"go.uber.org/fx"
    21  
    22  	_ "github.com/jinzhu/gorm/dialects/mssql"
    23  	_ "github.com/jinzhu/gorm/dialects/mysql"
    24  	_ "github.com/jinzhu/gorm/dialects/postgres"
    25  	_ "github.com/jinzhu/gorm/dialects/sqlite"
    26  
    27  	_ "k8s.io/client-go/plugin/pkg/client/auth/gcp"
    28  	ctrl "sigs.k8s.io/controller-runtime"
    29  	"sigs.k8s.io/controller-runtime/pkg/log/zap"
    30  
    31  	"github.com/chaos-mesh/chaos-mesh/pkg/apiserver"
    32  	"github.com/chaos-mesh/chaos-mesh/pkg/collector"
    33  	config "github.com/chaos-mesh/chaos-mesh/pkg/config/dashboard"
    34  	"github.com/chaos-mesh/chaos-mesh/pkg/store"
    35  	"github.com/chaos-mesh/chaos-mesh/pkg/store/dbstore"
    36  	"github.com/chaos-mesh/chaos-mesh/pkg/ttlcontroller"
    37  	"github.com/chaos-mesh/chaos-mesh/pkg/version"
    38  )
    39  
    40  var (
    41  	log = ctrl.Log.WithName("dashboard")
    42  )
    43  
    44  var (
    45  	printVersion bool
    46  )
    47  
    48  // @title Chaos Mesh Dashboard API
    49  // @version 2.0
    50  // @description Swagger docs for Chaos Mesh Dashboard. If you encounter any problems with API, please click on the issues link below to report bugs or questions.
    51  
    52  // @contact.name Issues
    53  // @contact.url https://github.com/chaos-mesh/chaos-mesh/issues
    54  
    55  // @license.name Apache 2.0
    56  // @license.url http://www.apache.org/licenses/LICENSE-2.0.html
    57  
    58  // @BasePath /api
    59  func main() {
    60  	flag.BoolVar(&printVersion, "version", false, "print version information and exit")
    61  	flag.Parse()
    62  
    63  	version.PrintVersionInfo("Chaos Dashboard")
    64  	if printVersion {
    65  		os.Exit(0)
    66  	}
    67  
    68  	ctrl.SetLogger(zap.New(zap.UseDevMode(true)))
    69  	mainLog := log.WithName("main")
    70  
    71  	dashboardConfig, err := config.GetChaosDashboardEnv()
    72  	if err != nil {
    73  		mainLog.Error(err, "invalid ChaosDashboardConfig")
    74  		os.Exit(1)
    75  	}
    76  	dashboardConfig.Version = version.Get().GitVersion
    77  
    78  	persistTTLConfigParsed, err := config.ParsePersistTTLConfig(dashboardConfig.PersistTTL)
    79  	if err != nil {
    80  		mainLog.Error(err, "invalid PersistTTLConfig")
    81  		os.Exit(1)
    82  	}
    83  
    84  	ctrlRuntimeStopCh := ctrl.SetupSignalHandler()
    85  	app := fx.New(
    86  		fx.Provide(
    87  			func() (<-chan struct{}, *config.ChaosDashboardConfig, *ttlcontroller.TTLconfig) {
    88  				return ctrlRuntimeStopCh, dashboardConfig, persistTTLConfigParsed
    89  			},
    90  			dbstore.NewDBStore,
    91  			collector.NewServer,
    92  			ttlcontroller.NewController,
    93  		),
    94  		store.Module,
    95  		apiserver.Module,
    96  		fx.Invoke(collector.Register),
    97  		fx.Invoke(ttlcontroller.Register),
    98  	)
    99  
   100  	app.Run()
   101  }
   102