From 27c03dac06ae183b29d225a695b9c568534f8d89 Mon Sep 17 00:00:00 2001 From: nxtcoder17 Date: Tue, 24 Sep 2024 16:23:28 +0530 Subject: [PATCH 1/4] refactor: migrating grpc logger to `log/slog` --- apps/accounts/internal/framework/framework.go | 6 +- apps/comms/Taskfile.yml | 2 +- apps/comms/internal/framework/framework.go | 5 +- apps/comms/main.go | 42 ++++++------- apps/console/internal/framework/framework.go | 6 +- apps/iam/internal/framework/main.go | 11 ++-- apps/iam/main.go | 22 ++++--- .../domain/global-vpn-cluster-connection.go | 3 +- .../internal/domain/global-vpn-devices.go | 20 ++++--- .../field-constants/generated_constants.go | 59 ++++++++++--------- apps/infra/internal/framework/framework.go | 6 +- .../internal/framework/framework.go | 4 +- apps/tenant-agent/main.go | 2 +- common/banner.go | 30 ++++------ pkg/grpc/server.go | 29 +++++---- 15 files changed, 129 insertions(+), 118 deletions(-) diff --git a/apps/accounts/internal/framework/framework.go b/apps/accounts/internal/framework/framework.go index 624dfc2cb..d33f0e96a 100644 --- a/apps/accounts/internal/framework/framework.go +++ b/apps/accounts/internal/framework/framework.go @@ -102,10 +102,8 @@ var Module = fx.Module("framework", }) }), - fx.Provide(func(logger logging.Logger) (app.AccountsGrpcServer, error) { - return grpc.NewGrpcServer(grpc.ServerOpts{ - Logger: logger.WithKV("component", "grpc-server"), - }) + fx.Provide(func(logger *slog.Logger) (app.AccountsGrpcServer, error) { + return grpc.NewGrpcServer(grpc.ServerOpts{Logger: logger}) }), fx.Invoke(func(lf fx.Lifecycle, server app.AccountsGrpcServer, ev *env.Env, logger logging.Logger) { diff --git a/apps/comms/Taskfile.yml b/apps/comms/Taskfile.yml index bcc3ccb18..192245092 100644 --- a/apps/comms/Taskfile.yml +++ b/apps/comms/Taskfile.yml @@ -39,7 +39,7 @@ tasks: run: dotenv: [".secrets/env"] cmds: - - nodemon -e go --signal SIGKILL --exec 'go run -tags dynamic main.go --dev || exit 1' + - go run ./main.go --dev build: cmds: diff --git a/apps/comms/internal/framework/framework.go b/apps/comms/internal/framework/framework.go index 2058bcc86..f06cc27a3 100644 --- a/apps/comms/internal/framework/framework.go +++ b/apps/comms/internal/framework/framework.go @@ -11,7 +11,6 @@ import ( "github.com/kloudlite/api/common" "github.com/kloudlite/api/pkg/errors" "github.com/kloudlite/api/pkg/grpc" - rpc "github.com/kloudlite/api/pkg/grpc" httpServer "github.com/kloudlite/api/pkg/http-server" "github.com/kloudlite/api/pkg/kv" "github.com/kloudlite/api/pkg/logging" @@ -51,7 +50,7 @@ var Module = fx.Module( return mail.NewSendgridMailer(ev.SendgridApiKey) }), - fx.Provide(func(logger logging.Logger) (app.CommsGrpcServer, error) { + fx.Provide(func(logger *slog.Logger) (app.CommsGrpcServer, error) { return grpc.NewGrpcServer(grpc.ServerOpts{Logger: logger}) }), @@ -81,7 +80,7 @@ var Module = fx.Module( ), fx.Provide(func(ev *env.Env) (app.IAMGrpcClient, error) { - return rpc.NewGrpcClient(ev.IAMGrpcAddr) + return grpc.NewGrpcClient(ev.IAMGrpcAddr) }), mongoDb.NewMongoClientFx[*fm](), diff --git a/apps/comms/main.go b/apps/comms/main.go index 4927f97f3..fd4b8b270 100644 --- a/apps/comms/main.go +++ b/apps/comms/main.go @@ -4,8 +4,9 @@ import ( "context" "embed" "flag" - "log/slog" "os" + "os/signal" + "syscall" "time" "github.com/kloudlite/api/apps/comms/internal/domain" @@ -20,28 +21,22 @@ import ( var EmailTemplatesDir embed.FS func main() { + start := time.Now() + common.PrintBuildInfo() + var isDev bool flag.BoolVar(&isDev, "dev", false, "--dev") flag.Parse() - logger, err := logging.New(&logging.Options{Name: "comms", Dev: isDev}) - if err != nil { - panic(err) - } + logger := logging.NewSlogLogger(logging.SlogOptions{ShowCaller: true, ShowDebugLogs: isDev, SetAsDefaultLogger: true}) - webApp := fx.New( + app := fx.New( fx.NopLogger, - fx.Provide(func() logging.Logger { - return logger + fx.Provide(func() (logging.Logger, error) { + return logging.New(&logging.Options{Name: "comms", Dev: isDev}) }), - fx.Provide(func() *slog.Logger { - return logging.NewSlogLogger(logging.SlogOptions{ - ShowCaller: true, - ShowDebugLogs: isDev, - SetAsDefaultLogger: true, - }) - }), + fx.Supply(logger), fx.Provide(func() (*env.Env, error) { return env.LoadEnv() @@ -54,15 +49,22 @@ func main() { framework.Module, ) + ch := make(chan os.Signal, 1) + signal.Notify(ch, syscall.SIGINT, syscall.SIGTERM) + go func() { + <-ch + logger.Info("shutting down...") + app.Stop(context.Background()) + }() + ctx, cf := context.WithTimeout(context.Background(), 5*time.Second) defer cf() - if err := webApp.Start(ctx); err != nil { - logger.Errorf(err, "comms-api startup errors") - logger.Infof("EXITING as errors encountered during startup") + if err := app.Start(ctx); err != nil { + logger.Error("failed to start comms api, got", "err", err) os.Exit(1) } - common.PrintReadyBanner() - <-webApp.Done() + common.PrintReadyBanner2(time.Since(start)) + <-app.Done() } diff --git a/apps/console/internal/framework/framework.go b/apps/console/internal/framework/framework.go index 03cda93a8..cae0d8771 100644 --- a/apps/console/internal/framework/framework.go +++ b/apps/console/internal/framework/framework.go @@ -101,10 +101,8 @@ var Module = fx.Module("framework", app.Module, - fx.Provide(func(logr logging.Logger) (app.ConsoleGrpcServer, error) { - return grpc.NewGrpcServer(grpc.ServerOpts{ - Logger: logr, - }) + fx.Provide(func(logger *slog.Logger) (app.ConsoleGrpcServer, error) { + return grpc.NewGrpcServer(grpc.ServerOpts{Logger: logger}) }), fx.Invoke(func(ev *env.Env, server app.ConsoleGrpcServer, lf fx.Lifecycle, logger logging.Logger) { diff --git a/apps/iam/internal/framework/main.go b/apps/iam/internal/framework/main.go index e4fa73135..cb60565e3 100644 --- a/apps/iam/internal/framework/main.go +++ b/apps/iam/internal/framework/main.go @@ -3,14 +3,15 @@ package framework import ( "context" "fmt" + "log/slog" + "time" + "github.com/kloudlite/api/apps/iam/internal/app" "github.com/kloudlite/api/apps/iam/internal/env" "github.com/kloudlite/api/pkg/errors" "github.com/kloudlite/api/pkg/grpc" - "github.com/kloudlite/api/pkg/logging" "github.com/kloudlite/api/pkg/repos" "go.uber.org/fx" - "time" ) type fm struct { @@ -32,10 +33,8 @@ var Module fx.Option = fx.Module( }), repos.NewMongoClientFx[*fm](), - fx.Provide(func(logger logging.Logger) (app.IAMGrpcServer, error) { - return grpc.NewGrpcServer(grpc.ServerOpts{ - Logger: logger, - }) + fx.Provide(func(logger *slog.Logger) (app.IAMGrpcServer, error) { + return grpc.NewGrpcServer(grpc.ServerOpts{Logger: logger}) }), app.Module, diff --git a/apps/iam/main.go b/apps/iam/main.go index 2e356368a..564607137 100644 --- a/apps/iam/main.go +++ b/apps/iam/main.go @@ -14,19 +14,26 @@ import ( ) func main() { + start := time.Now() + var isDev bool flag.BoolVar(&isDev, "dev", false, "--dev") + + var debug bool + flag.BoolVar(&debug, "debug", false, "--debug") flag.Parse() - logger, err := logging.New(&logging.Options{Name: "iam", Dev: isDev}) - if err != nil { - panic(err) + if isDev { + debug = true } + logger := logging.NewSlogLogger(logging.SlogOptions{ShowCaller: true, SetAsDefaultLogger: true, ShowDebugLogs: debug}) + app := fx.New( fx.NopLogger, - fx.Provide(func() logging.Logger { - return logger + fx.Supply(logger), + fx.Provide(func() (logging.Logger, error) { + return logging.New(&logging.Options{Name: "iam", Dev: isDev}) }), fx.Provide(func() (*env.Env, error) { @@ -39,11 +46,10 @@ func main() { ctx, cancelFunc := context.WithTimeout(context.Background(), 5*time.Second) defer cancelFunc() if err := app.Start(ctx); err != nil { - logger.Errorf(err, "IAM api startup errors") - logger.Infof("EXITING as errors encountered during startup") + logger.Error("failed to start iam api, got", "err", err) os.Exit(1) } - common.PrintReadyBanner() + common.PrintReadyBanner2(time.Since(start)) <-app.Done() } diff --git a/apps/infra/internal/domain/global-vpn-cluster-connection.go b/apps/infra/internal/domain/global-vpn-cluster-connection.go index a4c7871d6..78ee7b644 100644 --- a/apps/infra/internal/domain/global-vpn-cluster-connection.go +++ b/apps/infra/internal/domain/global-vpn-cluster-connection.go @@ -60,7 +60,7 @@ func (d *domain) getGlobalVPNConnectionPeers(args getGlobalVPNConnectionPeersArg Comments: fmt.Sprintf("gateway/%s/%s", c.GlobalVPNName, c.ClusterName), PublicKey: c.ParsedWgParams.PublicKey, AllowedIPs: []string{c.ClusterCIDR, fmt.Sprintf("%s/32", c.DeviceRef.IPAddr)}, - IP: c.Spec.GlobalIP, + IP: &c.Spec.GlobalIP, DNSSuffix: &c.Spec.DNSSuffix, } @@ -480,7 +480,6 @@ func (d *domain) OnGlobalVPNConnectionDeleteMessage(ctx InfraContext, clusterNam func (d *domain) OnGlobalVPNConnectionUpdateMessage(ctx InfraContext, dispatchAddr entities.DispatchAddr, gvpn entities.GlobalVPNConnection, status types.ResourceStatus, opts UpdateAndDeleteOpts) error { // FIXME: need a way to find global vpn connection, receiving it from other clusters - xconn, err := d.gvpnConnRepo.FindOne(ctx, repos.Filter{ fields.AccountName: ctx.AccountName, fc.GlobalVPNConnectionDispatchAddrAccountName: dispatchAddr.AccountName, diff --git a/apps/infra/internal/domain/global-vpn-devices.go b/apps/infra/internal/domain/global-vpn-devices.go index 003ae7463..8719c8b74 100644 --- a/apps/infra/internal/domain/global-vpn-devices.go +++ b/apps/infra/internal/domain/global-vpn-devices.go @@ -217,7 +217,7 @@ func (d *domain) createGlobalVPNDevice(ctx InfraContext, gvpnDevice entities.Glo return gv, nil } -func (d *domain) buildPeerFromGlobalVPNDevice(ctx InfraContext, gvpn *entities.GlobalVPN, device *entities.GlobalVPNDevice) *networkingv1.Peer { +func (d *domain) buildPeerFromGlobalVPNDevice(_ InfraContext, gvpn *entities.GlobalVPN, device *entities.GlobalVPNDevice) *networkingv1.Peer { allowedIPs := []string{fmt.Sprintf("%s/32", device.IPAddr)} // privateConns, err := d.gvpnConnRepo.Find(ctx, repos.Query{ @@ -246,7 +246,7 @@ func (d *domain) buildPeerFromGlobalVPNDevice(ctx InfraContext, gvpn *entities.G DNSHostname: fmt.Sprintf("%s.device.local", device.Name), PublicKey: device.PublicKey, PublicEndpoint: device.PublicEndpoint, - IP: device.IPAddr, + IP: &device.IPAddr, DNSSuffix: nil, AllowedIPs: allowedIPs, } @@ -287,7 +287,7 @@ func (d *domain) buildPeersFromGlobalVPNDevices(ctx InfraContext, gvpn string) ( DNSHostname: fmt.Sprintf("%s.device.local", devices[i].Name), PublicKey: devices[i].PublicKey, PublicEndpoint: devices[i].PublicEndpoint, - IP: devices[i].IPAddr, + IP: &devices[i].IPAddr, DNSSuffix: nil, AllowedIPs: allowedIPs, }) @@ -298,7 +298,7 @@ func (d *domain) buildPeersFromGlobalVPNDevices(ctx InfraContext, gvpn string) ( Comments: fmt.Sprintf("device/%s/%s", devices[i].GlobalVPNName, devices[i].Name), DNSHostname: fmt.Sprintf("%s.device.local", devices[i].Name), PublicKey: devices[i].PublicKey, - IP: devices[i].IPAddr, + IP: &devices[i].IPAddr, DNSSuffix: nil, AllowedIPs: allowedIPs, }) @@ -334,7 +334,9 @@ func (d *domain) buildGlobalVPNDeviceWgBaseParams(ctx InfraContext, gvpnConns [] publicPeers := make([]wgutils.PublicPeer, 0, len(pubPeers)+len(gvpnConnPeers)) for _, peer := range gvpnConnPeers { - deviceHosts[peer.DNSHostname] = peer.IP + if peer.IP != nil { + deviceHosts[peer.DNSHostname] = *peer.IP + } if peer.DNSHostname == fmt.Sprintf("%s.device.local", gvpnDevice.Name) { continue } @@ -352,7 +354,9 @@ func (d *domain) buildGlobalVPNDeviceWgBaseParams(ctx InfraContext, gvpnConns [] } for _, peer := range pubPeers { - deviceHosts[peer.DNSHostname] = peer.IP + if peer.IP != nil { + deviceHosts[peer.DNSHostname] = *peer.IP + } if peer.DNSHostname == fmt.Sprintf("%s.device.local", gvpnDevice.Name) { continue } @@ -372,7 +376,9 @@ func (d *domain) buildGlobalVPNDeviceWgBaseParams(ctx InfraContext, gvpnConns [] privatePeers := make([]wgutils.PrivatePeer, 0, len(privPeers)) for _, peer := range privPeers { - deviceHosts[peer.DNSHostname] = peer.IP + if peer.IP != nil { + deviceHosts[peer.DNSHostname] = *peer.IP + } if peer.DNSHostname == fmt.Sprintf("%s.device.local", gvpnDevice.Name) { continue } diff --git a/apps/infra/internal/entities/field-constants/generated_constants.go b/apps/infra/internal/entities/field-constants/generated_constants.go index eccdabad3..bb2281349 100644 --- a/apps/infra/internal/entities/field-constants/generated_constants.go +++ b/apps/infra/internal/entities/field-constants/generated_constants.go @@ -207,34 +207,37 @@ const ( // constant vars generated for struct GlobalVPNConnection const ( - GlobalVPNConnectionClusterSvcCIDR = "clusterSvcCIDR" - GlobalVPNConnectionDeviceRef = "deviceRef" - GlobalVPNConnectionDeviceRefIpAddr = "deviceRef.ipAddr" - GlobalVPNConnectionDeviceRefName = "deviceRef.name" - GlobalVPNConnectionDispatchAddr = "dispatchAddr" - GlobalVPNConnectionDispatchAddrAccountName = "dispatchAddr.accountName" - GlobalVPNConnectionDispatchAddrClusterName = "dispatchAddr.clusterName" - GlobalVPNConnectionGlobalVPNName = "globalVPNName" - GlobalVPNConnectionParsedWgParams = "parsedWgParams" - GlobalVPNConnectionParsedWgParamsPrivateKey = "parsedWgParams.private_key" - GlobalVPNConnectionParsedWgParamsPublicKey = "parsedWgParams.public_key" - GlobalVPNConnectionSpec = "spec" - GlobalVPNConnectionSpecClusterCIDR = "spec.clusterCIDR" - GlobalVPNConnectionSpecDnsSuffix = "spec.dnsSuffix" - GlobalVPNConnectionSpecGlobalIP = "spec.globalIP" - GlobalVPNConnectionSpecLoadBalancer = "spec.loadBalancer" - GlobalVPNConnectionSpecLoadBalancerHosts = "spec.loadBalancer.hosts" - GlobalVPNConnectionSpecLoadBalancerPort = "spec.loadBalancer.port" - GlobalVPNConnectionSpecNodePort = "spec.nodePort" - GlobalVPNConnectionSpecPeers = "spec.peers" - GlobalVPNConnectionSpecServiceType = "spec.serviceType" - GlobalVPNConnectionSpecSvcCIDR = "spec.svcCIDR" - GlobalVPNConnectionSpecTargetNamespace = "spec.targetNamespace" - GlobalVPNConnectionSpecWireguardKeysRef = "spec.wireguardKeysRef" - GlobalVPNConnectionSpecWireguardKeysRefName = "spec.wireguardKeysRef.name" - GlobalVPNConnectionVisibility = "visibility" - GlobalVPNConnectionVisibilityMode = "visibility.mode" - GlobalVPNConnectionVisibilityPublicEndpoint = "visibility.publicEndpoint" + GlobalVPNConnectionClusterSvcCIDR = "clusterSvcCIDR" + GlobalVPNConnectionDeviceRef = "deviceRef" + GlobalVPNConnectionDeviceRefIpAddr = "deviceRef.ipAddr" + GlobalVPNConnectionDeviceRefName = "deviceRef.name" + GlobalVPNConnectionDispatchAddr = "dispatchAddr" + GlobalVPNConnectionDispatchAddrAccountName = "dispatchAddr.accountName" + GlobalVPNConnectionDispatchAddrClusterName = "dispatchAddr.clusterName" + GlobalVPNConnectionGlobalVPNName = "globalVPNName" + GlobalVPNConnectionParsedWgParams = "parsedWgParams" + GlobalVPNConnectionParsedWgParamsPrivateKey = "parsedWgParams.private_key" + GlobalVPNConnectionParsedWgParamsPublicKey = "parsedWgParams.public_key" + GlobalVPNConnectionSpec = "spec" + GlobalVPNConnectionSpecClusterCIDR = "spec.clusterCIDR" + GlobalVPNConnectionSpecDnsSuffix = "spec.dnsSuffix" + GlobalVPNConnectionSpecGlobalIP = "spec.globalIP" + GlobalVPNConnectionSpecLoadBalancer = "spec.loadBalancer" + GlobalVPNConnectionSpecLoadBalancerHosts = "spec.loadBalancer.hosts" + GlobalVPNConnectionSpecLoadBalancerPort = "spec.loadBalancer.port" + GlobalVPNConnectionSpecLocalOverrides = "spec.localOverrides" + GlobalVPNConnectionSpecLocalOverridesName = "spec.localOverrides.name" + GlobalVPNConnectionSpecLocalOverridesNamespace = "spec.localOverrides.namespace" + GlobalVPNConnectionSpecNodePort = "spec.nodePort" + GlobalVPNConnectionSpecPeers = "spec.peers" + GlobalVPNConnectionSpecServiceType = "spec.serviceType" + GlobalVPNConnectionSpecSvcCIDR = "spec.svcCIDR" + GlobalVPNConnectionSpecTargetNamespace = "spec.targetNamespace" + GlobalVPNConnectionSpecWireguardKeysRef = "spec.wireguardKeysRef" + GlobalVPNConnectionSpecWireguardKeysRefName = "spec.wireguardKeysRef.name" + GlobalVPNConnectionVisibility = "visibility" + GlobalVPNConnectionVisibilityMode = "visibility.mode" + GlobalVPNConnectionVisibilityPublicEndpoint = "visibility.publicEndpoint" ) // constant vars generated for struct GlobalVPNDevice diff --git a/apps/infra/internal/framework/framework.go b/apps/infra/internal/framework/framework.go index 75c091eaa..adee446e2 100644 --- a/apps/infra/internal/framework/framework.go +++ b/apps/infra/internal/framework/framework.go @@ -90,10 +90,8 @@ var Module = fx.Module("framework", app.Module, - fx.Provide(func(logr logging.Logger) (app.InfraGrpcServer, error) { - return grpc.NewGrpcServer(grpc.ServerOpts{ - Logger: logr, - }) + fx.Provide(func(logger *slog.Logger) (app.InfraGrpcServer, error) { + return grpc.NewGrpcServer(grpc.ServerOpts{Logger: logger}) }), fx.Invoke(func(ev *env.Env, server app.InfraGrpcServer, lf fx.Lifecycle, logger logging.Logger) { diff --git a/apps/message-office/internal/framework/framework.go b/apps/message-office/internal/framework/framework.go index 9806e6d6a..7dd3a5bc5 100644 --- a/apps/message-office/internal/framework/framework.go +++ b/apps/message-office/internal/framework/framework.go @@ -55,7 +55,7 @@ var Module = fx.Module("framework", app.Module, fx.Provide(func(logger *slog.Logger) (app.InternalGrpcServer, error) { - return grpc.NewGrpcServer(grpc.ServerOpts{Slogger: logger.With(slog.String("component", "internal-grpc"))}) + return grpc.NewGrpcServer(grpc.ServerOpts{Logger: logger.With(slog.String("component", "internal-grpc"))}) }), fx.Invoke(func(lf fx.Lifecycle, logr logging.Logger, server app.InternalGrpcServer, ev *env.Env) { @@ -80,7 +80,7 @@ var Module = fx.Module("framework", }), fx.Provide(func(logger *slog.Logger) (app.ExternalGrpcServer, error) { - return grpc.NewGrpcServer(grpc.ServerOpts{Slogger: logger.With(slog.String("component", "external-grpc"))}) + return grpc.NewGrpcServer(grpc.ServerOpts{Logger: logger.With(slog.String("component", "external-grpc"))}) }), fx.Invoke(func(lf fx.Lifecycle, logr logging.Logger, server app.ExternalGrpcServer, ev *env.Env) { diff --git a/apps/tenant-agent/main.go b/apps/tenant-agent/main.go index b75e08463..b080df346 100644 --- a/apps/tenant-agent/main.go +++ b/apps/tenant-agent/main.go @@ -321,7 +321,7 @@ func main() { accessToken: ev.AccessToken, } - gs, err := libGrpc.NewGrpcServer(libGrpc.ServerOpts{Slogger: logger.With("component", "vector-grpc-proxy")}) + gs, err := libGrpc.NewGrpcServer(libGrpc.ServerOpts{Logger: logger.With("component", "vector-grpc-proxy")}) if err != nil { logger.Error("failed to create grpc server, got", "err", err) } diff --git a/common/banner.go b/common/banner.go index b747e5a0d..839623f4b 100644 --- a/common/banner.go +++ b/common/banner.go @@ -59,24 +59,18 @@ func PrintKloudliteBanner() { func PrintReadyBanner2(readyIn time.Duration) { fmt.Printf(` - , - ##### - ######## - ######## - ######## ##### - ######## *######### ██╗ ██╗██╗ ██████╗ ██╗ ██╗██████╗ ██╗ ██╗████████╗███████╗ - ######## ############### ██║ ██╔╝██║ ██╔═══██╗██║ ██║██╔══██╗██║ ██║╚══██╔══╝██╔════╝ - ######## *################### █████╔╝ ██║ ██║ ██║██║ ██║██║ ██║██║ ██║ ██║ █████╗ - #######/ ######################## ██╔═██╗ ██║ ██║ ██║██║ ██║██║ ██║██║ ██║ ██║ ██╔══╝ - #######( ################### ██║ ██╗███████╗╚██████╔╝╚██████╔╝██████╔╝███████╗██║ ██║ ███████╗ - (#######. ##############* ╚═╝ ╚═╝╚══════╝ ╚═════╝ ╚═════╝ ╚═════╝ ╚══════╝╚═╝ ╚═╝ ╚══════╝ - ######## #(####### - (#######. ####* - ######## 🚀 running in %.2fs - /######(. - ##### - , - + ** + **** + **** * + **** ***** ▗▖ ▗▖▗▖ ▗▄▖ ▗▖ ▗▖▗▄▄▄ ▗▖ ▗▄▄▄▖▗▄▄▄▖▗▄▄▄▖ + **** ********* ▐▌▗▞▘▐▌ ▐▌ ▐▌▐▌ ▐▌▐▌ █▐▌ █ █ ▐▌ + **** ************ ▐▛▚▖ ▐▌ ▐▌ ▐▌▐▌ ▐▌▐▌ █▐▌ █ █ ▐▛▀▀▘ + **** ********* ▐▌ ▐▌▐▙▄▄▖▝▚▄▞▘▝▚▄▞▘▐▙▄▄▀▐▙▄▄▖▗▄█▄▖ █ ▐▙▄▄▖ + **** ***** + **** * 🚀 running in %.2fs + **** + ** + `, readyIn.Seconds()) } diff --git a/pkg/grpc/server.go b/pkg/grpc/server.go index 97c190914..9ef309a84 100644 --- a/pkg/grpc/server.go +++ b/pkg/grpc/server.go @@ -1,11 +1,12 @@ package grpc import ( + "context" "log/slog" "net" + "github.com/grpc-ecosystem/go-grpc-middleware/v2/interceptors/logging" "github.com/kloudlite/api/pkg/errors" - "github.com/kloudlite/api/pkg/logging" "google.golang.org/grpc" "google.golang.org/grpc/peer" ) @@ -17,15 +18,12 @@ type Server interface { } type ServerOpts struct { - Logger logging.Logger - Slogger *slog.Logger + Logger *slog.Logger } type grpcServer struct { *grpc.Server - // Deprecated: use slogger - logger logging.Logger - slogger *slog.Logger + logger *slog.Logger } func (g *grpcServer) Listen(addr string) error { @@ -33,7 +31,7 @@ func (g *grpcServer) Listen(addr string) error { if err != nil { return errors.NewEf(err, "could not listen to net/tcp server") } - g.slogger.Info("grpc server listening", "at", addr) + g.logger.Info("grpc server listening", "at", addr) return g.Serve(listen) } @@ -42,11 +40,22 @@ func (g *grpcServer) Stop() { } func NewGrpcServer(opts ServerOpts) (Server, error) { - if opts.Slogger == nil { - opts.Slogger = slog.Default() + if opts.Logger == nil { + opts.Logger = slog.Default() + } + + grpcLogger := logging.LoggerFunc(func(ctx context.Context, lvl logging.Level, msg string, fields ...any) { + opts.Logger.Log(ctx, slog.Level(lvl), msg, fields...) + }) + + grpcLoggingOpts := []logging.Option{ + logging.WithLogOnEvents(logging.StartCall, logging.FinishCall), } server := grpc.NewServer( + grpc.ChainUnaryInterceptor(logging.UnaryServerInterceptor(grpcLogger, grpcLoggingOpts...)), + grpc.ChainStreamInterceptor(logging.StreamServerInterceptor(grpcLogger, grpcLoggingOpts...)), + grpc.StreamInterceptor(func(srv interface{}, stream grpc.ServerStream, info *grpc.StreamServerInfo, handler grpc.StreamHandler) error { p, ok := peer.FromContext(stream.Context()) if ok { @@ -61,7 +70,7 @@ func NewGrpcServer(opts ServerOpts) (Server, error) { }), ) - return &grpcServer{Server: server, logger: opts.Logger, slogger: opts.Slogger}, nil + return &grpcServer{Server: server, logger: opts.Logger}, nil } // Type guard to ensure grpcServer implements Server interface, at compile time From e183316a28d03159adb642a6e404719d1be2584f Mon Sep 17 00:00:00 2001 From: nxtcoder17 Date: Tue, 24 Sep 2024 16:41:55 +0530 Subject: [PATCH 2/4] feat: control edge gateway service type via Env --- apps/infra/internal/app/process-resource-updates.go | 9 ++++----- apps/infra/internal/domain/clusters.go | 2 ++ .../domain/templates/kloudlite-gateway-svc.yml.tpl | 3 +-- apps/infra/internal/domain/templates/types.go | 1 + apps/infra/internal/env/env.go | 2 ++ 5 files changed, 10 insertions(+), 7 deletions(-) diff --git a/apps/infra/internal/app/process-resource-updates.go b/apps/infra/internal/app/process-resource-updates.go index 01631df1d..210717027 100644 --- a/apps/infra/internal/app/process-resource-updates.go +++ b/apps/infra/internal/app/process-resource-updates.go @@ -9,7 +9,6 @@ import ( "sync" "time" - "github.com/kloudlite/api/constants" "github.com/kloudlite/api/pkg/errors" "github.com/kloudlite/api/apps/infra/internal/domain" @@ -111,10 +110,10 @@ func processResourceUpdates(consumer ReceiveResourceUpdatesConsumer, d domain.Do dctx := domain.InfraContext{Context: context.TODO(), UserId: "sys-user-process-infra-updates", AccountName: ru.AccountName} - if strings.HasPrefix(ru.AccountName, "kl-") { - // FIXME: this is a kloudlite account, so we should handle it differently, as it is definitely not a tenant account - dctx.AccountName = obj.GetLabels()[constants.AccountNameKey] - } + // if strings.HasPrefix(ru.AccountName, "kl-") { + // // FIXME: this is a kloudlite account, so we should handle it differently, as it is definitely not a tenant account + // dctx.AccountName = obj.GetLabels()[constants.AccountNameKey] + // } mlogger.Debug("validated message") defer func() { diff --git a/apps/infra/internal/domain/clusters.go b/apps/infra/internal/domain/clusters.go index 04ef02c6c..898f55b40 100644 --- a/apps/infra/internal/domain/clusters.go +++ b/apps/infra/internal/domain/clusters.go @@ -498,6 +498,7 @@ func (d *domain) syncKloudliteGatewayDevice(ctx InfraContext, gvpnName string) e Namespace: resourceNamespace, WireguardPort: wgParams.ListenPort, Selector: selector, + ServiceType: d.env.KloudliteEdgeGatewayServiceType, }) if err != nil { return errors.NewE(err) @@ -682,6 +683,7 @@ func (d *domain) syncKloudliteDeviceOnPlatform(ctx InfraContext, gvpnName string Namespace: resourceNamespace, WireguardPort: wgParams.ListenPort, Selector: selector, + ServiceType: d.env.KloudliteEdgeGatewayServiceType, }) if err != nil { return errors.NewE(err) diff --git a/apps/infra/internal/domain/templates/kloudlite-gateway-svc.yml.tpl b/apps/infra/internal/domain/templates/kloudlite-gateway-svc.yml.tpl index 704264dc8..512b4fe5d 100644 --- a/apps/infra/internal/domain/templates/kloudlite-gateway-svc.yml.tpl +++ b/apps/infra/internal/domain/templates/kloudlite-gateway-svc.yml.tpl @@ -13,8 +13,7 @@ metadata: labels: app: {{.Name}} spec: - {{- /* type: NodePort */}} - type: LoadBalancer + type: {{ .ServiceType }} ports: - name: wireguard protocol: UDP diff --git a/apps/infra/internal/domain/templates/types.go b/apps/infra/internal/domain/templates/types.go index 49dc16fa5..458d4c8df 100644 --- a/apps/infra/internal/domain/templates/types.go +++ b/apps/infra/internal/domain/templates/types.go @@ -21,4 +21,5 @@ type GatewayServiceTemplateVars struct { Namespace string WireguardPort uint16 Selector map[string]string + ServiceType string } diff --git a/apps/infra/internal/env/env.go b/apps/infra/internal/env/env.go index 110be4c41..6f643cdc8 100644 --- a/apps/infra/internal/env/env.go +++ b/apps/infra/internal/env/env.go @@ -59,6 +59,8 @@ type infraEnv struct { AvailableKloudliteRegionsConfig string `env:"AVAILABLE_KLOUDLITE_REGIONS_CONFIG" required:"false"` AvailableKloudliteRegions map[string]AvailableKloudliteRegion + KloudliteEdgeGatewayServiceType string `env:"KLOUDLITE_EDGE_GATEWAY_SERVICE_TYPE" default:"LoadBalancer"` + EnableClusterCreation bool `env:"ENABLE_CLUSTER_CREATION" default:"false"` } From badb8a97d3f8dbab9179082c6b96275e929b1daf Mon Sep 17 00:00:00 2001 From: nxtcoder17 Date: Tue, 24 Sep 2024 16:46:20 +0530 Subject: [PATCH 3/4] chore: go mod tidy --- go.mod | 7 ++++--- go.sum | 14 ++++++++------ 2 files changed, 12 insertions(+), 9 deletions(-) diff --git a/go.mod b/go.mod index 8c2e56cb3..b529b379d 100644 --- a/go.mod +++ b/go.mod @@ -29,7 +29,7 @@ require ( go.uber.org/zap v1.26.0 golang.org/x/oauth2 v0.16.0 golang.org/x/sync v0.7.0 - google.golang.org/grpc v1.61.0 + google.golang.org/grpc v1.61.1 google.golang.org/protobuf v1.34.1 gopkg.in/yaml.v2 v2.4.0 // indirect k8s.io/api v0.29.0 @@ -45,6 +45,7 @@ require ( github.com/charmbracelet/lipgloss v0.10.0 github.com/charmbracelet/log v0.4.0 github.com/go-chi/chi/v5 v5.0.10 + github.com/grpc-ecosystem/go-grpc-middleware/v2 v2.1.0 github.com/kloudlite/container-registry-authorizer v0.0.0-20231021122509-161dc30fde55 github.com/miekg/dns v1.1.55 github.com/nats-io/nats.go v1.31.0 @@ -82,12 +83,12 @@ require ( github.com/seancfoley/bintree v1.2.1 // indirect github.com/sosodev/duration v1.3.1 // indirect github.com/stretchr/objx v0.5.2 // indirect - google.golang.org/genproto/googleapis/rpc v0.0.0-20240116215550-a9fa1716bcac // indirect + google.golang.org/genproto/googleapis/rpc v0.0.0-20240213162025-012b6fc9bca9 // indirect gopkg.in/yaml.v3 v3.0.1 // indirect ) require ( - cloud.google.com/go/compute v1.23.3 // indirect + cloud.google.com/go/compute v1.23.4 // indirect cloud.google.com/go/compute/metadata v0.2.3 // indirect github.com/Masterminds/goutils v1.1.1 // indirect github.com/Masterminds/semver/v3 v3.2.1 // indirect diff --git a/go.sum b/go.sum index 440a7dcd0..90ed2d814 100644 --- a/go.sum +++ b/go.sum @@ -1,5 +1,5 @@ -cloud.google.com/go/compute v1.23.3 h1:6sVlXXBmbd7jNX0Ipq0trII3e4n1/MsADLK6a+aiVlk= -cloud.google.com/go/compute v1.23.3/go.mod h1:VCgBUoMnIVIR0CscqQiPJLAG25E3ZRZMzcFZeQ+h8CI= +cloud.google.com/go/compute v1.23.4 h1:EBT9Nw4q3zyE7G45Wvv3MzolIrCJEuHys5muLY0wvAw= +cloud.google.com/go/compute v1.23.4/go.mod h1:/EJMj55asU6kAFnuZET8zqgwgJ9FvXWXOkkfQZa4ioI= cloud.google.com/go/compute/metadata v0.2.3 h1:mg4jlk7mCAj6xXp9UJ4fjI9VUI5rubuGBW5aJ7UnBMY= cloud.google.com/go/compute/metadata v0.2.3/go.mod h1:VAV5nSsACxMJvgaAuX6Pk2AawlZn8kiOGuCv6gTkwuA= github.com/99designs/gqlgen v0.17.49 h1:b3hNGexHd33fBSAd4NDT/c3NCcQzcAVkknhN9ym36YQ= @@ -146,6 +146,8 @@ github.com/google/uuid v1.6.0 h1:NIvaJDMOsjHA8n1jAhLSgzrAzy1Hgr+hNrb57e+94F0= github.com/google/uuid v1.6.0/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+yHo= github.com/gorilla/websocket v1.5.0 h1:PPwGk2jz7EePpoHN/+ClbZu8SPxiqlu12wZP/3sWmnc= github.com/gorilla/websocket v1.5.0/go.mod h1:YR8l580nyteQvAITg2hZ9XVh4b55+EU/adAjf1fMHhE= +github.com/grpc-ecosystem/go-grpc-middleware/v2 v2.1.0 h1:pRhl55Yx1eC7BZ1N+BBWwnKaMyD8uC+34TLdndZMAKk= +github.com/grpc-ecosystem/go-grpc-middleware/v2 v2.1.0/go.mod h1:XKMd7iuf/RGPSMJ/U4HP0zS2Z9Fh8Ps9a+6X26m/tmI= github.com/hashicorp/go-cleanhttp v0.5.2 h1:035FKYIWjmULyFRBKPs8TBQoi0x6d9G4xc9neXJWAZQ= github.com/hashicorp/go-cleanhttp v0.5.2/go.mod h1:kO/YDlP8L1346E6Sodw+PrpBSV4/SoxCXGY6BqNFT48= github.com/hashicorp/go-hclog v1.6.3 h1:Qr2kF+eVWjTiYmU7Y31tYlP1h0q/X3Nl3tPGdaB11/k= @@ -448,10 +450,10 @@ gomodules.xyz/jsonpatch/v2 v2.4.0/go.mod h1:AH3dM2RI6uoBZxn3LVrfvJ3E0/9dG4cSrbuB google.golang.org/appengine v1.6.7/go.mod h1:8WjMMxjGQR8xUklV/ARdw2HLXBOI7O7uCIDZVag1xfc= google.golang.org/appengine v1.6.8 h1:IhEN5q69dyKagZPYMSdIjS2HqprW324FRQZJcGqPAsM= google.golang.org/appengine v1.6.8/go.mod h1:1jJ3jBArFh5pcgW8gCtRJnepW8FzD1V44FJffLiz/Ds= -google.golang.org/genproto/googleapis/rpc v0.0.0-20240116215550-a9fa1716bcac h1:nUQEQmH/csSvFECKYRv6HWEyypysidKl2I6Qpsglq/0= -google.golang.org/genproto/googleapis/rpc v0.0.0-20240116215550-a9fa1716bcac/go.mod h1:daQN87bsDqDoe316QbbvX60nMoJQa4r6Ds0ZuoAe5yA= -google.golang.org/grpc v1.61.0 h1:TOvOcuXn30kRao+gfcvsebNEa5iZIiLkisYEkf7R7o0= -google.golang.org/grpc v1.61.0/go.mod h1:VUbo7IFqmF1QtCAstipjG0GIoq49KvMe9+h1jFLBNJs= +google.golang.org/genproto/googleapis/rpc v0.0.0-20240213162025-012b6fc9bca9 h1:hZB7eLIaYlW9qXRfCq/qDaPdbeY3757uARz5Vvfv+cY= +google.golang.org/genproto/googleapis/rpc v0.0.0-20240213162025-012b6fc9bca9/go.mod h1:YUWgXUFRPfoYK1IHMuxH5K6nPEXSCzIMljnQ59lLRCk= +google.golang.org/grpc v1.61.1 h1:kLAiWrZs7YeDM6MumDe7m3y4aM6wacLzM1Y/wiLP9XY= +google.golang.org/grpc v1.61.1/go.mod h1:VUbo7IFqmF1QtCAstipjG0GIoq49KvMe9+h1jFLBNJs= google.golang.org/protobuf v1.26.0-rc.1/go.mod h1:jlhhOSvTdKEhbULTjvd4ARK9grFBp09yW+WbY/TyQbw= google.golang.org/protobuf v1.26.0/go.mod h1:9q0QmTI4eRPtz6boOQmLYwt+qCgq0jsYwAQnmE0givc= google.golang.org/protobuf v1.34.1 h1:9ddQBjfCyZPOHPUiPxpYESBLc+T8P3E+Vo4IbKZgFWg= From fd9a7c488d50b790efea503988c65447a77285e6 Mon Sep 17 00:00:00 2001 From: nxtcoder17 Date: Tue, 24 Sep 2024 16:46:58 +0530 Subject: [PATCH 4/4] ci: migrating from local actions to kloudlite/actions --- .github/actions/build-api-images/action.yml | 418 ++++++++++-------- .github/workflows/building-with-nix.yml | 4 +- README.md | 67 +-- .../internal/framework/framework.go | 6 +- apps/container-registry/main.go | 36 +- go.mod | 2 +- go.sum | 4 +- 7 files changed, 277 insertions(+), 260 deletions(-) diff --git a/.github/actions/build-api-images/action.yml b/.github/actions/build-api-images/action.yml index 4e9eec6db..0fedc12fe 100644 --- a/.github/actions/build-api-images/action.yml +++ b/.github/actions/build-api-images/action.yml @@ -7,13 +7,9 @@ inputs: required: true image_tag: - description: 'image tag, if empty, will be generated from branch or tag' + description: 'image tag, when empty, will be generated from branch/tag' default: '' - cachix_enabled: - description: "cachix enabled" - default: "false" - cachix_cache_name: description: "cachix cache name" default: "kloudlite" @@ -95,18 +91,18 @@ runs: steps: - name: setup ENV Variables shell: bash - id: env-vars + # id: env-vars working-directory: ${{ inputs.git_directory }} run: |+ - GOMODCACHE=${{github.workspace}}/actions/go-mod-cache - GOCACHE=${{github.workspace}}/actions/go-cache - echo "GOMODCACHE=$GOMODCACHE" >> $GITHUB_OUTPUT - echo "GOCACHE=$GOCACHE" >> $GITHUB_OUTPUT - - echo "GOMODCACHE=$GOMODCACHE" >> $GITHUB_ENV - echo "GOCACHE=$GOCACHE" >> $GITHUB_ENV - echo "FILES_HASH=${{ hashFiles('**/*.go', '**/go.mod', '**/go.sum')}}" >> $GITHUB_OUTPUT - echo "PUSH_IMAGE=false" >> $GITHUB_ENV + # GOMODCACHE=${{github.workspace}}/actions/go-mod-cache + # GOCACHE=${{github.workspace}}/actions/go-cache + # echo "GOMODCACHE=$GOMODCACHE" >> $GITHUB_OUTPUT + # echo "GOCACHE=$GOCACHE" >> $GITHUB_OUTPUT + # + # echo "GOMODCACHE=$GOMODCACHE" >> $GITHUB_ENV + # echo "GOCACHE=$GOCACHE" >> $GITHUB_ENV + # echo "FILES_HASH=${{ hashFiles('**/*.go', '**/go.mod', '**/go.sum')}}" >> $GITHUB_OUTPUT + # echo "PUSH_IMAGE=false" >> $GITHUB_ENV if [ "$(basename ${{ inputs.git_directory }})" != "." ]; then echo "IMAGE_REPOSITORY_PREFIX=ghcr.io/${{ github.repository }}/$(basename ${{inputs.git_directory}})" >> $GITHUB_ENV else @@ -119,8 +115,8 @@ runs: ln -sf ${{ inputs.git_directory }}/.github/actions ./github-actions - name: setup nix (with cachix) - if: ${{ inputs.cachix_enabled == 'true' }} - uses: ./github-actions/setup-nix-cachix/ + uses: kloudlite/actions/setup-nix-cachix@v1 + # uses: ./github-actions/setup-nix-cachix/ with: flake_lock: ${{ inputs.git_directory }}/flake.lock nix_develop_arguments: "${{ inputs.git_directory }}#default" @@ -128,16 +124,10 @@ runs: cachix_cache_name: ${{ inputs.cachix_cache_name }} cachix_auth_token: ${{ inputs.cachix_auth_token }} - - name: setup nix cache (with github cache) - if: ${{ inputs.cachix_enabled == 'false' }} - uses: ./github-actions/setup-nix-github/ - with: - flake_lock: ${{ inputs.git_directory }}/flake.lock - nix_develop_arguments: "${{ inputs.git_directory }}#default" - - name: setup docker if: ${{ inputs.docker_enabled == 'true' }} - uses: ./github-actions/setup-docker + uses: kloudlite/actions/setup-docker@v1 + # uses: ./github-actions/setup-docker with: docker_username: ${{ github.actor }} docker_password: ${{ inputs.github_token }} @@ -155,26 +145,9 @@ runs: run: |+ echo "IMAGE_TAG=${{ inputs.image_tag }}" >> $GITHUB_ENV - - name: Create Image Tag from branch name - if: ${{ inputs.image_tag == '' && startsWith(github.ref, 'refs/heads/release-') }} - shell: bash - run: | - set +e - IMAGE_TAG=$(echo ${GITHUB_REF#refs/heads/} | sed 's/release-//g') - echo "$IMAGE_TAG" | grep -i '\-nightly$' - if [ $? -ne 0 ]; then - IMAGE_TAG="$IMAGE_TAG-nightly" - fi - set -e - - echo "IMAGE_TAG=$IMAGE_TAG" >> $GITHUB_ENV - - - name: Create Image Tag from tag - if: ${{ inputs.image_tag == '' && startsWith(github.ref, 'refs/tags/') }} - shell: bash - run: | - IMAGE_TAG=$(echo ${GITHUB_REF#refs/tags/}) - echo "IMAGE_TAG=$IMAGE_TAG" >> $GITHUB_ENV + - name: generate image tag + if: inputs.image_tag == '' + uses: kloudlite/actions/generate-image-tag@v1 - name: override image if image_tag is nightly if: "${{ endsWith(env.IMAGE_TAG, '-nightly') }}" @@ -182,272 +155,371 @@ runs: run: |+ echo "OVERRIDE_PUSHED_IMAGE=true" >> $GITHUB_ENV - - name: accounts api go build cache - if: ${{ inputs.accounts-api == 'true' }} - uses: actions/cache@v4 + # - name: accounts api go build cache + # if: ${{ inputs.accounts-api == 'true' }} + # uses: actions/cache@v4 + # with: + # path: |+ + # ${{ env.GOMODCACHE }} + # ${{ env.GOCACHE }} + # key: go-${{ runner.os }}-accounts-api-${{ steps.env-vars.outputs.FILES_HASH }} + # save-always: true + # restore-keys: go-${{ runner.os }}-accounts-api- + + - name: setup accounts api go cache + uses: kloudlite/actions/setup-cache-go@v1 + if: inputs.accounts-api == 'true' with: - path: |+ - ${{ env.GOMODCACHE }} - ${{ env.GOCACHE }} - key: go-${{ runner.os }}-accounts-api-${{ steps.env-vars.outputs.FILES_HASH }} - save-always: true - restore-keys: go-${{ runner.os }}-accounts-api- + cache_key: accounts-api + working_directory: ${{ inputs.git_directory }} - name: accounts api - if: ${{ inputs.accounts-api == 'true' }} + if: inputs.accounts-api == 'true' working-directory: ${{ inputs.git_directory }}/apps/accounts shell: bash run: | - task container:build-and-push image=${IMAGE_REPOSITORY_PREFIX}/accounts:${IMAGE_TAG:-latest} upx=true override=$OVERRIDE_PUSHED_IMAGE push_image=${PUSH_IMAGE} + task container:build-and-push image=${IMAGE_REPOSITORY_PREFIX}/accounts:${IMAGE_TAG} upx=true override=$OVERRIDE_PUSHED_IMAGE push_image=${PUSH_IMAGE} + + # - name: auth api go build cache + # if: ${{ inputs.auth-api == 'true' }} + # uses: actions/cache@v4 + # with: + # path: |+ + # ${{ env.GOMODCACHE }} + # ${{ env.GOCACHE }} + # key: go-${{ runner.os }}-auth-api-${{ steps.env-vars.outputs.FILES_HASH }} + # save-always: true + # restore-keys: go-${{ runner.os }}-auth-api- - name: auth api go build cache if: ${{ inputs.auth-api == 'true' }} - uses: actions/cache@v4 + uses: kloudlite/actions/setup-cache-go@v1 with: - path: |+ - ${{ env.GOMODCACHE }} - ${{ env.GOCACHE }} - key: go-${{ runner.os }}-auth-api-${{ steps.env-vars.outputs.FILES_HASH }} - save-always: true - restore-keys: go-${{ runner.os }}-auth-api- + cache_key: auth-api + working_directory: ${{ inputs.git_directory }} - name: auth api if: ${{ inputs.auth-api == 'true' }} working-directory: ${{ inputs.git_directory }}/apps/auth shell: bash run: | - task container:build-and-push image=${IMAGE_REPOSITORY_PREFIX}/auth:${IMAGE_TAG:-latest} upx=true override=$OVERRIDE_PUSHED_IMAGE push_image=${PUSH_IMAGE} + task container:build-and-push image=${IMAGE_REPOSITORY_PREFIX}/auth:${IMAGE_TAG} upx=true override=$OVERRIDE_PUSHED_IMAGE push_image=${PUSH_IMAGE} + + # - name: comms api go build cache + # if: ${{ inputs.comms-api == 'true' }} + # uses: actions/cache@v4 + # with: + # path: |+ + # ${{ env.GOMODCACHE }} + # ${{ env.GOCACHE }} + # key: go-${{ runner.os }}-comms-api-${{ steps.env-vars.outputs.FILES_HASH }} + # save-always: true + # restore-keys: go-${{ runner.os }}-comms-api- - name: comms api go build cache if: ${{ inputs.comms-api == 'true' }} - uses: actions/cache@v4 + uses: kloudlite/actions/setup-cache-go@v1 with: - path: |+ - ${{ env.GOMODCACHE }} - ${{ env.GOCACHE }} - key: go-${{ runner.os }}-comms-api-${{ steps.env-vars.outputs.FILES_HASH }} - save-always: true - restore-keys: go-${{ runner.os }}-comms-api- + cache_key: comms-api + working_directory: ${{ inputs.git_directory }} - name: comms api if: ${{ inputs.comms-api == 'true' }} working-directory: ${{ inputs.git_directory }}/apps/comms shell: bash run: | - task container:build-and-push image=${IMAGE_REPOSITORY_PREFIX}/comms:${IMAGE_TAG:-latest} upx=true override=$OVERRIDE_PUSHED_IMAGE push_image=${PUSH_IMAGE} + task container:build-and-push image=${IMAGE_REPOSITORY_PREFIX}/comms:${IMAGE_TAG} upx=true override=$OVERRIDE_PUSHED_IMAGE push_image=${PUSH_IMAGE} + + # - name: console api go build cache + # if: ${{ inputs.console-api == 'true' }} + # uses: actions/cache@v4 + # with: + # path: |+ + # ${{ env.GOMODCACHE }} + # ${{ env.GOCACHE }} + # key: go-${{ runner.os }}-console-api-${{ steps.env-vars.outputs.FILES_HASH }} + # save-always: true + # restore-keys: go-${{ runner.os }}-console-api- - name: console api go build cache if: ${{ inputs.console-api == 'true' }} - uses: actions/cache@v4 + uses: kloudlite/actions/setup-cache-go@v1 with: - path: |+ - ${{ env.GOMODCACHE }} - ${{ env.GOCACHE }} - key: go-${{ runner.os }}-console-api-${{ steps.env-vars.outputs.FILES_HASH }} - save-always: true - restore-keys: go-${{ runner.os }}-console-api- + cache_key: console-api + working_directory: ${{ inputs.git_directory }} - name: console api if: ${{ inputs.console-api == 'true' }} working-directory: ${{ inputs.git_directory }}/apps/console shell: bash run: | - task container:build-and-push image=${IMAGE_REPOSITORY_PREFIX}/console:${IMAGE_TAG:-latest} upx=true override=$OVERRIDE_PUSHED_IMAGE push_image=${PUSH_IMAGE} - + task container:build-and-push image=${IMAGE_REPOSITORY_PREFIX}/console:${IMAGE_TAG} upx=true override=$OVERRIDE_PUSHED_IMAGE push_image=${PUSH_IMAGE} + + # - name: container-registry api go build cache + # if: ${{ inputs.container-registry-api == 'true' }} + # uses: actions/cache@v4 + # with: + # path: |+ + # ${{ env.GOMODCACHE }} + # ${{ env.GOCACHE }} + # key: go-${{ runner.os }}-container-registry-api-${{ steps.env-vars.outputs.FILES_HASH }} + # save-always: true + # restore-keys: go-${{ runner.os }}-container-registry-api- + # - name: container-registry api go build cache if: ${{ inputs.container-registry-api == 'true' }} - uses: actions/cache@v4 + uses: kloudlite/actions/setup-cache-go@v1 with: - path: |+ - ${{ env.GOMODCACHE }} - ${{ env.GOCACHE }} - key: go-${{ runner.os }}-container-registry-api-${{ steps.env-vars.outputs.FILES_HASH }} - save-always: true - restore-keys: go-${{ runner.os }}-container-registry-api- + cache_key: "container-registry-api" + working_directory: ${{ inputs.git_directory }} - name: container-registry api if: ${{ inputs.container-registry-api == 'true' }} working-directory: ${{ inputs.git_directory }}/apps/container-registry shell: bash run: | - task container:build-and-push image=${IMAGE_REPOSITORY_PREFIX}/container-registry:${IMAGE_TAG:-latest} upx=true override=$OVERRIDE_PUSHED_IMAGE push_image=${PUSH_IMAGE} - - - name: gateway api go build cache - if: ${{ inputs.gateway-api == 'true' }} - uses: actions/cache@v4 - with: - path: |+ - ${{ env.GOMODCACHE }} - ${{ env.GOCACHE }} - key: go-${{ runner.os }}-gateway-api-${{ steps.env-vars.outputs.FILES_HASH }} - save-always: true - restore-keys: go-${{ runner.os }}-gateway-api- + task container:build-and-push image=${IMAGE_REPOSITORY_PREFIX}/container-registry:${IMAGE_TAG} upx=true override=$OVERRIDE_PUSHED_IMAGE push_image=${PUSH_IMAGE} + + # - name: gateway api go build cache + # if: ${{ inputs.gateway-api == 'true' }} + # uses: actions/cache@v4 + # with: + # path: |+ + # ${{ env.GOMODCACHE }} + # ${{ env.GOCACHE }} + # key: go-${{ runner.os }}-gateway-api-${{ steps.env-vars.outputs.FILES_HASH }} + # save-always: true + # restore-keys: go-${{ runner.os }}-gateway-api- - name: gateway api if: ${{ inputs.gateway-api == 'true' }} working-directory: ${{ inputs.git_directory }}/apps/gateway shell: bash run: | - task container:build-and-push image=${IMAGE_REPOSITORY_PREFIX}/gateway:${IMAGE_TAG:-latest} upx=true override=$OVERRIDE_PUSHED_IMAGE push_image=${PUSH_IMAGE} + task container:build-and-push image=${IMAGE_REPOSITORY_PREFIX}/gateway:${IMAGE_TAG} upx=true override=$OVERRIDE_PUSHED_IMAGE push_image=${PUSH_IMAGE} + + # - name: iam api go build cache + # if: ${{ inputs.iam-api == 'true' }} + # uses: actions/cache@v4 + # with: + # path: |+ + # ${{ env.GOMODCACHE }} + # ${{ env.GOCACHE }} + # key: go-${{ runner.os }}-iam-api-${{ steps.env-vars.outputs.FILES_HASH }} + # save-always: true + # restore-keys: go-${{ runner.os }}-iam-api- - name: iam api go build cache if: ${{ inputs.iam-api == 'true' }} - uses: actions/cache@v4 + uses: kloudlite/actions/setup-cache-go@v1 with: - path: |+ - ${{ env.GOMODCACHE }} - ${{ env.GOCACHE }} - key: go-${{ runner.os }}-iam-api-${{ steps.env-vars.outputs.FILES_HASH }} - save-always: true - restore-keys: go-${{ runner.os }}-iam-api- + cache_key: "iam-api" + working_directory: ${{ inputs.git_directory }} - name: iam api if: ${{ inputs.iam-api == 'true' }} working-directory: ${{ inputs.git_directory }}/apps/iam shell: bash run: | - task container:build-and-push image=${IMAGE_REPOSITORY_PREFIX}/iam:${IMAGE_TAG:-latest} upx=true override=$OVERRIDE_PUSHED_IMAGE push_image=${PUSH_IMAGE} + task container:build-and-push image=${IMAGE_REPOSITORY_PREFIX}/iam:${IMAGE_TAG} upx=true override=$OVERRIDE_PUSHED_IMAGE push_image=${PUSH_IMAGE} + + # - name: infra api go build cache + # if: ${{ inputs.infra-api == 'true' }} + # uses: actions/cache@v4 + # with: + # path: |+ + # ${{ env.GOMODCACHE }} + # ${{ env.GOCACHE }} + # key: go-${{ runner.os }}-infra-api-${{ steps.env-vars.outputs.FILES_HASH }} + # save-always: true + # restore-keys: go-${{ runner.os }}-infra-api- - name: infra api go build cache if: ${{ inputs.infra-api == 'true' }} - uses: actions/cache@v4 + uses: kloudlite/actions/setup-cache-go@v1 with: - path: |+ - ${{ env.GOMODCACHE }} - ${{ env.GOCACHE }} - key: go-${{ runner.os }}-infra-api-${{ steps.env-vars.outputs.FILES_HASH }} - save-always: true - restore-keys: go-${{ runner.os }}-infra-api- + cache_key: "infra-api" + working_directory: ${{ inputs.git_directory }} - name: infra api if: ${{ inputs.infra-api == 'true' }} working-directory: ${{ inputs.git_directory }}/apps/infra shell: bash run: | - task container:build-and-push image=${IMAGE_REPOSITORY_PREFIX}/infra:${IMAGE_TAG:-latest} upx=true override=$OVERRIDE_PUSHED_IMAGE push_image=${PUSH_IMAGE} + task container:build-and-push image=${IMAGE_REPOSITORY_PREFIX}/infra:${IMAGE_TAG} upx=true override=$OVERRIDE_PUSHED_IMAGE push_image=${PUSH_IMAGE} + + # - name: iot-console api go build cache + # if: ${{ inputs.iot-console-api == 'true' }} + # uses: actions/cache@v4 + # with: + # path: |+ + # ${{ env.GOMODCACHE }} + # ${{ env.GOCACHE }} + # key: go-${{ runner.os }}-iot-console-api-${{ steps.env-vars.outputs.FILES_HASH }} + # save-always: true + # restore-keys: go-${{ runner.os }}-iot-console-api- - name: iot-console api go build cache if: ${{ inputs.iot-console-api == 'true' }} - uses: actions/cache@v4 + uses: kloudlite/actions/setup-cache-go@v1 with: - path: |+ - ${{ env.GOMODCACHE }} - ${{ env.GOCACHE }} - key: go-${{ runner.os }}-iot-console-api-${{ steps.env-vars.outputs.FILES_HASH }} - save-always: true - restore-keys: go-${{ runner.os }}-iot-console-api- + cache_key: "iot-console-api" + working_directory: ${{ inputs.git_directory }} - name: iot-console api if: ${{ inputs.iot-console-api == 'true' }} working-directory: ${{ inputs.git_directory }}/apps/iot-console shell: bash run: | - task container:build-and-push image=${IMAGE_REPOSITORY_PREFIX}/iot-console:${IMAGE_TAG:-latest} upx=true override=$OVERRIDE_PUSHED_IMAGE push_image=${PUSH_IMAGE} + task container:build-and-push image=${IMAGE_REPOSITORY_PREFIX}/iot-console:${IMAGE_TAG} upx=true override=$OVERRIDE_PUSHED_IMAGE push_image=${PUSH_IMAGE} + + # - name: message-office api go build cache + # if: ${{ inputs.message-office-api == 'true' }} + # uses: actions/cache@v4 + # with: + # path: |+ + # ${{ env.GOMODCACHE }} + # ${{ env.GOCACHE }} + # key: go-${{ runner.os }}-message-office-api-${{ steps.env-vars.outputs.FILES_HASH }} + # save-always: true + # restore-keys: go-${{ runner.os }}-message-office-api- - name: message-office api go build cache if: ${{ inputs.message-office-api == 'true' }} - uses: actions/cache@v4 + uses: kloudlite/actions/setup-cache-go@v1 with: - path: |+ - ${{ env.GOMODCACHE }} - ${{ env.GOCACHE }} - key: go-${{ runner.os }}-message-office-api-${{ steps.env-vars.outputs.FILES_HASH }} - save-always: true - restore-keys: go-${{ runner.os }}-message-office-api- + cache_key: "message-office-api" + working_directory: ${{ inputs.git_directory }} - name: message-office api if: ${{ inputs.message-office-api == 'true' }} working-directory: ${{ inputs.git_directory }}/apps/message-office shell: bash run: | - task container:build-and-push image=${IMAGE_REPOSITORY_PREFIX}/message-office:${IMAGE_TAG:-latest} upx=true override=$OVERRIDE_PUSHED_IMAGE push_image=${PUSH_IMAGE} + task container:build-and-push image=${IMAGE_REPOSITORY_PREFIX}/message-office:${IMAGE_TAG} upx=true override=$OVERRIDE_PUSHED_IMAGE push_image=${PUSH_IMAGE} + + # - name: observability api go build cache + # if: ${{ inputs.observability-api == 'true' }} + # uses: actions/cache@v4 + # with: + # path: |+ + # ${{ env.GOMODCACHE }} + # ${{ env.GOCACHE }} + # key: go-${{ runner.os }}-observability-api-${{ steps.env-vars.outputs.FILES_HASH }} + # save-always: true + # restore-keys: go-${{ runner.os }}-observability-api- - name: observability api go build cache if: ${{ inputs.observability-api == 'true' }} - uses: actions/cache@v4 + uses: kloudlite/actions/setup-cache-go@v1 with: - path: |+ - ${{ env.GOMODCACHE }} - ${{ env.GOCACHE }} - key: go-${{ runner.os }}-observability-api-${{ steps.env-vars.outputs.FILES_HASH }} - save-always: true - restore-keys: go-${{ runner.os }}-observability-api- + cache_key: "observability-api" + working_directory: ${{ inputs.git_directory }} + - name: observability api if: ${{ inputs.observability-api == 'true' }} working-directory: ${{ inputs.git_directory }}/apps/observability shell: bash run: | - task container:build-and-push image=${IMAGE_REPOSITORY_PREFIX}/observability:${IMAGE_TAG:-latest} upx=true override=$OVERRIDE_PUSHED_IMAGE push_image=${PUSH_IMAGE} + task container:build-and-push image=${IMAGE_REPOSITORY_PREFIX}/observability:${IMAGE_TAG} upx=true override=$OVERRIDE_PUSHED_IMAGE push_image=${PUSH_IMAGE} + + # - name: tenant-agent go build cache + # if: ${{ inputs.tenant-agent == 'true' }} + # uses: actions/cache@v4 + # with: + # path: |+ + # ${{ env.GOMODCACHE }} + # ${{ env.GOCACHE }} + # key: go-${{ runner.os }}-tenant-agent-${{ steps.env-vars.outputs.FILES_HASH }} + # save-always: true + # restore-keys: go-${{ runner.os }}-tenant-agent- - name: tenant-agent go build cache if: ${{ inputs.tenant-agent == 'true' }} - uses: actions/cache@v4 + uses: kloudlite/actions/setup-cache-go@v1 with: - path: |+ - ${{ env.GOMODCACHE }} - ${{ env.GOCACHE }} - key: go-${{ runner.os }}-tenant-agent-${{ steps.env-vars.outputs.FILES_HASH }} - save-always: true - restore-keys: go-${{ runner.os }}-tenant-agent- + cache_key: "tenant-agent" + working_directory: ${{ inputs.git_directory }} - name: tenant-agent if: ${{ inputs.tenant-agent == 'true' }} working-directory: ${{ inputs.git_directory }}/apps/tenant-agent shell: bash run: | - task container:build-and-push image=${IMAGE_REPOSITORY_PREFIX}/tenant-agent:${IMAGE_TAG:-latest} upx=true override=$OVERRIDE_PUSHED_IMAGE push_image=${PUSH_IMAGE} + task container:build-and-push image=${IMAGE_REPOSITORY_PREFIX}/tenant-agent:${IMAGE_TAG} upx=true override=$OVERRIDE_PUSHED_IMAGE push_image=${PUSH_IMAGE} + + # - name: webhook api go build cache + # if: ${{ inputs.webhook-api == 'true' }} + # uses: actions/cache@v4 + # with: + # path: |+ + # ${{ env.GOMODCACHE }} + # ${{ env.GOCACHE }} + # key: go-${{ runner.os }}-webhook-api-${{ steps.env-vars.outputs.FILES_HASH }} + # save-always: true + # restore-keys: go-${{ runner.os }}-webhook-api- - name: webhook api go build cache if: ${{ inputs.webhook-api == 'true' }} - uses: actions/cache@v4 + uses: kloudlite/actions/setup-cache-go@v1 with: - path: |+ - ${{ env.GOMODCACHE }} - ${{ env.GOCACHE }} - key: go-${{ runner.os }}-webhook-api-${{ steps.env-vars.outputs.FILES_HASH }} - save-always: true - restore-keys: go-${{ runner.os }}-webhook-api- + cache_key: "webhook-api" + working_directory: ${{ inputs.git_directory }} - name: webhook api if: ${{ inputs.webhook-api == 'true' }} working-directory: ${{ inputs.git_directory }}/apps/webhook shell: bash run: | - task container:build-and-push image=${IMAGE_REPOSITORY_PREFIX}/webhook:${IMAGE_TAG:-latest} upx=true override=$OVERRIDE_PUSHED_IMAGE push_image=${PUSH_IMAGE} + task container:build-and-push image=${IMAGE_REPOSITORY_PREFIX}/webhook:${IMAGE_TAG} upx=true override=$OVERRIDE_PUSHED_IMAGE push_image=${PUSH_IMAGE} + + # - name: websocket-server api go build cache + # if: ${{ inputs.websocket-server-api == 'true' }} + # uses: actions/cache@v4 + # with: + # path: |+ + # ${{ env.GOMODCACHE }} + # ${{ env.GOCACHE }} + # key: go-${{ runner.os }}-websocket-server-api-${{ steps.env-vars.outputs.FILES_HASH }} + # save-always: true + # restore-keys: go-${{ runner.os }}-websocket-server-api- - name: websocket-server api go build cache if: ${{ inputs.websocket-server-api == 'true' }} - uses: actions/cache@v4 + uses: kloudlite/actions/setup-cache-go@v1 with: - path: |+ - ${{ env.GOMODCACHE }} - ${{ env.GOCACHE }} - key: go-${{ runner.os }}-websocket-server-api-${{ steps.env-vars.outputs.FILES_HASH }} - save-always: true - restore-keys: go-${{ runner.os }}-websocket-server-api- + cache_key: "websocket-server-api" + working_directory: ${{ inputs.git_directory }} - name: websocket-server api if: ${{ inputs.websocket-server-api == 'true' }} working-directory: ${{ inputs.git_directory }}/apps/websocket-server shell: bash run: | - task container:build-and-push image=${IMAGE_REPOSITORY_PREFIX}/websocket-server:${IMAGE_TAG:-latest} upx=true override=$OVERRIDE_PUSHED_IMAGE push_image=${PUSH_IMAGE} + task container:build-and-push image=${IMAGE_REPOSITORY_PREFIX}/websocket-server:${IMAGE_TAG} upx=true override=$OVERRIDE_PUSHED_IMAGE push_image=${PUSH_IMAGE} + + # - name: gateway kube proxy api build cache + # if: ${{ inputs.gateway-kube-proxy == 'true' }} + # uses: actions/cache@v4 + # with: + # path: |+ + # ${{ env.GOMODCACHE }} + # ${{ env.GOCACHE }} + # key: go-${{ runner.os }}-gateway-kube-proxy-${{ steps.env-vars.outputs.FILES_HASH }} + # save-always: true + # restore-keys: go-${{ runner.os }}-gateway-kube-proxy- - name: gateway kube proxy api build cache if: ${{ inputs.gateway-kube-proxy == 'true' }} - uses: actions/cache@v4 + uses: kloudlite/actions/setup-cache-go@v1 with: - path: |+ - ${{ env.GOMODCACHE }} - ${{ env.GOCACHE }} - key: go-${{ runner.os }}-gateway-kube-proxy-${{ steps.env-vars.outputs.FILES_HASH }} - save-always: true - restore-keys: go-${{ runner.os }}-gateway-kube-proxy- + cache_key: "gateway-kube-proxy" + working_directory: ${{ inputs.git_directory }} - name: gateway logs proxy if: ${{ inputs.gateway-kube-proxy == 'true' }} working-directory: ${{ inputs.git_directory }}/cmd/gateway-kube-proxy shell: bash run: | - task container:build-and-push image=${IMAGE_REPOSITORY_PREFIX}/cmd/gateway-kube-proxy:${IMAGE_TAG:-latest} upx=true override=$OVERRIDE_PUSHED_IMAGE push_image=${PUSH_IMAGE} + task container:build-and-push image=${IMAGE_REPOSITORY_PREFIX}/cmd/gateway-kube-proxy:${IMAGE_TAG} upx=true override=$OVERRIDE_PUSHED_IMAGE push_image=${PUSH_IMAGE} diff --git a/.github/workflows/building-with-nix.yml b/.github/workflows/building-with-nix.yml index 5462b6bc2..ecc5cdda3 100644 --- a/.github/workflows/building-with-nix.yml +++ b/.github/workflows/building-with-nix.yml @@ -30,7 +30,7 @@ permissions: jobs: build-images: strategy: - fail-fast: false + fail-fast: true matrix: images: - name: accounts-api @@ -59,7 +59,7 @@ jobs: with: image_tag: ${{ inputs.image_tag }} - cachix_enabled: true + # cachix_enabled: true cachix_auth_token: ${{ secrets.CACHIX_AUTH_TOKEN }} docker_enabled: true diff --git a/README.md b/README.md index ab678b409..2e5a38c4c 100644 --- a/README.md +++ b/README.md @@ -1,6 +1,6 @@ # Kloudlite Platform Backend -[![FOSSA Status](https://app.fossa.com/api/projects/custom%2B37304%2Fgit%40github.com%3Akloudlite%2Fapi-go.svg?type=shield)](https://app.fossa.com/projects/custom%2B37304%2Fgit%40github.com%3Akloudlite%2Fapi-go?ref=badge_shield) +![GitHub License](https://img.shields.io/github/license/kloudlite/api) ![Nightly CI](https://github.com/k3s-io/k3s/actions/workflows/nightly-install.yaml/badge.svg) [![Build Status](https://drone-publish.k3s.io/api/badges/k3s-io/k3s/status.svg)](https://drone-publish.k3s.io/k3s-io/k3s) [![Integration Test Coverage](https://github.com/k3s-io/k3s/actions/workflows/integration.yaml/badge.svg)](https://github.com/k3s-io/k3s/actions/workflows/integration.yaml) @@ -18,68 +18,5 @@ to effectively manage complex multi-cloud and hybrid infrastructures without req expertise. -## Table of Contents - -1. [Installation](#installation) -2. [Uninstallation](#uninstallation) -3. [Usage](#usage) -4. [Contributing](docs/code-contribution-guidelines.md) -5. [License](LICENSE) - ## Installation - -This section provides instructions for installing our application using Helm, a popular package manager for Kubernetes. Before proceeding, make sure you have the following prerequisites: - -- Kubernetes cluster up and running -- kubectl configured to connect to your cluster -- Helm v3.x installed - -### Step 1: Add the Helm Repository -First, add the Helm repository containing the chart for our application: - -``` -helm repo add kloudlite https://github.com/kloudlite/helm -helm repo update -``` - -### Step 2: Configure the Application -Create a values.yaml file to customize the application's configuration according to your needs. -Use the values.yaml file provided in the Helm chart as a reference. - -``` -# values.yaml -someFeature: - enabled: true - replicas: 2 - -anotherFeature: - size: "large" -``` - -### Step 3: Install the Application - -Install the application using the helm install command, specifying your custom values.yaml file: - -``` -helm install / -f values.yaml -``` - -### Step 4: Verify the Installation - -After the installation is complete, check that the application's resources have been created in your Kubernetes cluster: - -``` -kubectl get all -l app.kubernetes.io/instance= -``` - -### Step 5: Access the Application - -Depending on your application's configuration, you may need to expose its services to access it. Follow the specific instructions provided by your application's documentation. - -## Uninstalling the Application - -To uninstall the application, use the helm uninstall command: - -``` -helm uninstall -``` +[Follow installation docs](https://github.com/kloudlite/helm-charts) diff --git a/apps/container-registry/internal/framework/framework.go b/apps/container-registry/internal/framework/framework.go index b602c0b45..1cf21b39e 100644 --- a/apps/container-registry/internal/framework/framework.go +++ b/apps/container-registry/internal/framework/framework.go @@ -107,10 +107,8 @@ var Module = fx.Module("framework", }), // creates New GRPC server - fx.Provide(func(logger logging.Logger) (app.ContainerRegistryGRPCServer, error) { - return grpc.NewGrpcServer(grpc.ServerOpts{ - Logger: logger.WithName("GRPC server"), - }) + fx.Provide(func(logger *slog.Logger) (app.ContainerRegistryGRPCServer, error) { + return grpc.NewGrpcServer(grpc.ServerOpts{Logger: logger}) }), // handles GRPC server lifecycle diff --git a/apps/container-registry/main.go b/apps/container-registry/main.go index e9bb338c0..1eb7e10b6 100644 --- a/apps/container-registry/main.go +++ b/apps/container-registry/main.go @@ -3,8 +3,9 @@ package main import ( "context" "flag" - "log/slog" - "runtime/trace" + "os" + "os/signal" + "time" "github.com/kloudlite/api/apps/container-registry/internal/env" "github.com/kloudlite/api/pkg/errors" @@ -17,10 +18,22 @@ import ( ) func main() { + start := time.Now() + var isDev bool flag.BoolVar(&isDev, "dev", false, "--dev") + + var debug bool + flag.BoolVar(&debug, "debug", false, "--debug") + flag.Parse() + if isDev { + debug = true + } + + logger := logging.NewSlogLogger(logging.SlogOptions{ShowCaller: true, ShowDebugLogs: debug, SetAsDefaultLogger: true}) + app := fx.New( fx.Provide(func() (*env.Env, error) { if e, err := env.LoadEnv(); err != nil { @@ -37,23 +50,20 @@ func main() { }, ), - fx.Provide(func() *slog.Logger { - return logging.NewSlogLogger(logging.SlogOptions{ - ShowCaller: true, - ShowDebugLogs: isDev, - SetAsDefaultLogger: true, - }) - }), + fx.Supply(logger), fn.FxErrorHandler(), framework.Module, ) - if err := app.Start(context.TODO()); err != nil { - trace.Log(context.TODO(), "app.Start", err.Error()) - panic(err) + ctx, cf := signal.NotifyContext(context.TODO(), os.Interrupt) + defer cf() + + if err := app.Start(ctx); err != nil { + logger.Error("failed to start container registry api, got", "err", err) + os.Exit(1) } - common.PrintReadyBanner() + common.PrintReadyBanner2(time.Since(start)) <-app.Done() } diff --git a/go.mod b/go.mod index b529b379d..953d3f2c9 100644 --- a/go.mod +++ b/go.mod @@ -16,7 +16,7 @@ require ( github.com/google/go-github/v43 v43.0.0 github.com/google/go-github/v45 v45.2.0 github.com/gorilla/websocket v1.5.0 - github.com/kloudlite/operator v0.0.0-20240917124613-0418df6214cf + github.com/kloudlite/operator v0.0.0-20240924122932-030f95a15613 github.com/matoous/go-nanoid/v2 v2.0.0 github.com/pkg/errors v0.9.1 github.com/sendgrid/sendgrid-go v3.11.1+incompatible diff --git a/go.sum b/go.sum index 90ed2d814..8bf458a03 100644 --- a/go.sum +++ b/go.sum @@ -179,8 +179,8 @@ github.com/klauspost/compress v1.17.9 h1:6KIumPrER1LHsvBVuDa0r5xaG0Es51mhhB9BQB2 github.com/klauspost/compress v1.17.9/go.mod h1:Di0epgTjJY877eYKx5yC51cX2A2Vl2ibi7bDH9ttBbw= github.com/kloudlite/container-registry-authorizer v0.0.0-20231021122509-161dc30fde55 h1:YnZh3TL6AG4EfoInx1/L5zcPHd2QxgLKseJB1KtHjdQ= github.com/kloudlite/container-registry-authorizer v0.0.0-20231021122509-161dc30fde55/go.mod h1:GZj3wZmIw/qCciclRhgQTgmGiqe8wxoVzMXQjbOfnbc= -github.com/kloudlite/operator v0.0.0-20240917124613-0418df6214cf h1:GPPzhVCddW5Ba+gxaumhdX3cq5HB6qs99v47v2aKbkc= -github.com/kloudlite/operator v0.0.0-20240917124613-0418df6214cf/go.mod h1:VkreINDW43qeTsDv9gfGH5M9c5OG/jPGYOGxj8otsGY= +github.com/kloudlite/operator v0.0.0-20240924122932-030f95a15613 h1:2vmIyEscCnsRpZ0zaXov1jglR+UcRnCwa4va7DbwcYc= +github.com/kloudlite/operator v0.0.0-20240924122932-030f95a15613/go.mod h1:VkreINDW43qeTsDv9gfGH5M9c5OG/jPGYOGxj8otsGY= github.com/kr/pretty v0.2.1/go.mod h1:ipq/a2n7PKx3OHsz4KJII5eveXtPO4qwEXGdVfWzfnI= github.com/kr/pretty v0.3.1 h1:flRD4NNwYAUpkphVc1HcthR4KEIFJ65n8Mw5qdRn3LE= github.com/kr/pretty v0.3.1/go.mod h1:hoEshYVHaxMs3cyo3Yncou5ZscifuDolrwPKZanG3xk=