Skip to content
This repository was archived by the owner on Jun 11, 2025. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
418 changes: 245 additions & 173 deletions .github/actions/build-api-images/action.yml

Large diffs are not rendered by default.

4 changes: 2 additions & 2 deletions .github/workflows/building-with-nix.yml
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ permissions:
jobs:
build-images:
strategy:
fail-fast: false
fail-fast: true
matrix:
images:
- name: accounts-api
Expand Down Expand Up @@ -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
Expand Down
67 changes: 2 additions & 65 deletions README.md
Original file line number Diff line number Diff line change
@@ -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)
Expand All @@ -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 <RELEASE_NAME> <REPO_NAME>/<CHART_NAME> -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=<RELEASE_NAME>
```

### 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 <RELEASE_NAME>
```
[Follow installation docs](https://github.com/kloudlite/helm-charts)
6 changes: 2 additions & 4 deletions apps/accounts/internal/framework/framework.go
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
2 changes: 1 addition & 1 deletion apps/comms/Taskfile.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
5 changes: 2 additions & 3 deletions apps/comms/internal/framework/framework.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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})
}),

Expand Down Expand Up @@ -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](),
Expand Down
42 changes: 22 additions & 20 deletions apps/comms/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,9 @@ import (
"context"
"embed"
"flag"
"log/slog"
"os"
"os/signal"
"syscall"
"time"

"github.com/kloudlite/api/apps/comms/internal/domain"
Expand All @@ -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()
Expand All @@ -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()
}
6 changes: 2 additions & 4 deletions apps/console/internal/framework/framework.go
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
6 changes: 2 additions & 4 deletions apps/container-registry/internal/framework/framework.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
36 changes: 23 additions & 13 deletions apps/container-registry/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand All @@ -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 {
Expand All @@ -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()
}
11 changes: 5 additions & 6 deletions apps/iam/internal/framework/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand All @@ -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,
Expand Down
22 changes: 14 additions & 8 deletions apps/iam/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand All @@ -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()
}
Loading