Guide for Local Development of FedLCM

December 12, 2022 · View on GitHub

Requirements

In this section you can have a glance of the minimum and recommended versions of the tools needed to build/debug FedLCM.

These tools and services needs to be installed:

ToolLinkMinimumRecommended
npmlink>= 6>= 7
NodeJSlink>= 14>= 16
golanglink>= 1.19>= 1.19

Service Dependency

FedLCM depends on a PostgreSQL Database and a StepCA service. Refer to their documents on how to setup one.

Quick Setup and Run

Clone the repository:

git clone $URL

Start Backend Server

Configure necessary environment variables for connecting with PostgreSQL:

NameDescriptionRequired
POSTGRES_HOSTthe address of the postgres dbYes
POSTGRES_PORTthe port of the postgres dbYes
POSTGRES_USERthe username of the postgres connectionYes
POSTGRES_PASSWORDthe password of the postgres connectionYes
POSTGRES_DBthe db name of the postgresYes

Go to ./server directory and run:

go run main.go

If the process goes well, backend server will listen and serving HTTP on port 8080.

Alternatively, you can configure your favorite IDE to start this service.

Start Frontend Server

  1. Run npm install under "frontend" directory.
  2. create "proxy.config.json" file under "frontend" directory, and replace the URL of target with your available backend server.
 {
    "/api/v1": {
      "target": "http://localhost:8080",
      "secure": false,
      "changeOrigin": true,
      "logLevel": "debug",
        "headers": {
            "Connection": "keep-alive"
        }
    }
  }
  1. Run ng serve for a dev server. Navigate to http://localhost:4200/. The app will automatically reload if you change any of the source files.
  2. Run ng build to build the project. The build artifacts will be stored in the dist/ directory.

Default username is Admin with password admin.

Other Useful Commands

# Build both frontend and backend into `./output` directory.
make all

# Run server tests
make server-unittest

# Run frontend tests
cd frontend && npm test

# Build docker image
make docker-build

# Push docker image
make docker-push

Other configurable environment variables

NameDescriptionRequired
POSTGRES_DEBUGwhether or not to enable postgres debug level logsNo, default to false
POSTGRES_SSLMODEwhether or not to enable ssl connection to DBNo, default to false
LIFECYCLEMANAGER_INITIAL_ADMIN_PASSWORDinitial admin user password, only takes effect on first startNo, default to "admin"
LIFECYCLEMANAGER_SECRETKEYa string of secret key for encrypting sensitive data in the DBNo, default to "passphrase123456"
LIFECYCLEMANAGER_DEBUGtrue or false to enable debug logNo, default to false
LIFECYCLEMANAGER_EXPERIMENT_ENABLEDtrue of false to enable OpenFL managementNo, default to false
LIFECYCLEMANAGER_JWT_KEYa string of secret key for generating JWT tokenNo, default to a random one

Development

Frontend

The frontend is based on Clarity and Angular.

Backend

We use Gin framework to handle API requests and GORM to persist data.

The code are organized as below:

pkg
├── kubefate         // KubeFATE management and client code
├── kubernetes       // K8s client code
└── utils            // some basic util functions
server
├── api              // Gin route and API handlinig
├── application      // App services called by the handlers in api level
├── constants        // some constants
├── docs             // swagger docs
├── domain           // domain driven design implementation of the main workflow
├── infrastructure   // client to other system, GORM logics etc. that can be used by other layers
└── main.go          // entry point