Skip to content

Commit 47a515a

Browse files
committed
docs(setup): Add setup docs and easy install script
Signed-off-by: deo002 <[email protected]>
1 parent 3169bfa commit 47a515a

File tree

6 files changed

+326
-107
lines changed

6 files changed

+326
-107
lines changed

README.md

Lines changed: 29 additions & 81 deletions
Original file line numberDiff line numberDiff line change
@@ -57,111 +57,57 @@ As the response of the request, a JWT will be returned. Use this JWT with the
5757
`Authorization` header (as `-H "Authorization: <JWT>"`) to access endpoints
5858
requiring authentication.
5959

60+
## Prerequisites
6061

61-
## Prerequisite
62+
Before setting up the project, ensure the following tools are installed on your system:
6263

63-
Before proceeding, make sure you have the following installed on your system:
64+
### 1. Golang (Go)
6465

66+
You’ll need Go installed to build and run the project.
67+
👉 [Official installation guide](https://go.dev/doc/install)
6568

69+
### 2. PostgreSQL (v14 or later)
6670

71+
The project uses PostgreSQL as its database. You can install it via:
6772

68-
- Install Golang
69-
70-
Follow the official instructions to install Golang:
71-
👉 [https://go.dev/doc/install](https://go.dev/doc/install)
72-
73-
---
74-
75-
- Install golang-migrate CLI (For Linux & MacOs)
73+
#### Option A: Package Manager (Linux example)
7674

7775
```bash
78-
curl -L https://github.com/golang-migrate/migrate/releases/latest/download/migrate.linux-amd64.tar.gz | tar xvz
79-
sudo mv migrate /usr/local/bin/
76+
sudo apt update
77+
sudo apt install postgresql
8078
```
8179

82-
## How to run this project?
83-
84-
- Clone this Project and Navigate to the folder.
80+
#### Option B: Official Installer
8581

86-
``` bash
87-
git clone https://github.com/fossology/LicenseDb.git
88-
cd LicenseDb
89-
```
82+
Download and run the official installer for your operating system from the PostgreSQL website.
83+
👉 [https://www.postgresql.org/download/](https://www.postgresql.org/download/)
9084

91-
- Create the `external_ref_fields.yaml` file in the root directory of the project and change the
92-
values of the extra license json keys as per your requirement.
85+
### 3. Install golang-migrate CLI
9386

94-
```bash
95-
cp external_ref_fields.example.yaml external_ref_fields.yaml
96-
vim external_ref_fields.yaml
97-
```
87+
### 4. Install swagger document generator
9888

99-
- Generate Go struct for the extra fields listed in the external_ref_fields.yaml.
89+
You'll need```swag``` installed to build swagger docs.
10090

10191
```bash
102-
go generate ./...
92+
go install github.com/swaggo/swag/cmd/swag@latest
10393
```
10494

105-
- Build the project using following command.
95+
#### For Linux & macOS
10696

10797
```bash
108-
go build ./cmd/laas
109-
```
110-
111-
- Create the `.env` file in the root directory of the project and change the
112-
values of the environment variables as per your requirement.
113-
114-
```bash
115-
cp configs/.env.dev.example .env
116-
vim .env
117-
```
118-
119-
- Run the migration files.
120-
```bash
121-
migrate -path pkg/db/migrations -database "postgres://fossy:fossy@localhost:5432/licensedb?sslmode=disable" up
122-
```
123-
124-
- Run the executable.
125-
126-
```bash
127-
./laas
128-
```
129-
130-
- You can directly run it by the following command.
131-
132-
```bash
133-
go run ./cmd/laas
98+
curl -L https://github.com/golang-migrate/migrate/releases/latest/download/migrate.linux-amd64.tar.gz | tar xvz
99+
sudo mv migrate /usr/local/bin/
134100
```
135101

136-
### Create first user
137-
Connect to the database using `psql` with the following command.
138-
```bash
139-
psql -h localhost -p 5432 -U fossy -d licensedb
140-
```
102+
For other platforms and installation methods, check the official docs:
103+
👉 [https://github.com/golang-migrate/migrate](https://github.com/golang-migrate/migrate)
141104

142-
Run the following query to create the first user.
143-
```sql
144-
INSERT INTO users (user_name, user_password, user_level, display_name, user_email) VALUES ('<username>', '<password>', 'SUPER_ADMIN', '<display_name>', '<user_email>');
145-
```
105+
## How to run this project?
146106

147-
### Generating Swagger Documentation
148-
1. Install [swag](https://github.com/swaggo/swag) using the following command.
149-
```bash
150-
go install github.com/swaggo/swag/cmd/swag@latest
151-
```
152-
2. Run the following command to generate swagger documentation.
153-
<!-- https://github.com/swaggo/swag/issues/817#issuecomment-730895033 -->
154-
```bash
155-
swag init --parseDependency --generalInfo api.go --dir ./pkg/api,./pkg/auth,./pkg/db,./pkg/models,./pkg/utils --output ./cmd/laas/docs
156-
```
157-
3. Swagger documentation will be generated in `./cmd/laas/docs` folder.
158-
4. Run the project and navigate to `http://localhost:8080/swagger/index.html` to view the documentation.
159-
5. Optionally, after changing any documentation comments, format them with following command.
160-
```bash
161-
swag fmt --generalInfo ./pkg/api/api.go --dir ./pkg/api,./pkg/auth,./pkg/db,./pkg/models,./pkg/utils
162-
```
107+
👉 Please follow the [Setup Guide](./SETUP.md) for step-by-step instructions on how to run the project.
163108

164109
### Testing (local)
110+
165111
The PostgreSQL user `fossy` must have the `CREATEDB` privilege in order to:
166112

167113
- Programmatically create and drop a test database.
@@ -172,7 +118,9 @@ sudo -u postgres psql; // log into psql with postgres super user
172118
ALTER USER fossy CREATEDB; // alter the role for fossy
173119
\du ; // verify role
174120
```
121+
175122
Create the `.env.test` file file in the `configs` directory of the project.
176-
```
123+
124+
```bash
177125
cp configs/.env.test.example .env.test
178-
```
126+
```

SETUP.md

Lines changed: 158 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,158 @@
1+
<!-- SPDX-FileCopyrightText: 2025 Dearsh Oberoi <[email protected]>
2+
3+
SPDX-License-Identifier: GPL-2.0-only
4+
-->
5+
6+
# Project Setup
7+
8+
There are 3 ways to run LicenseDb.
9+
10+
## 1. Easy Install Script
11+
12+
The easiest of them all is via the easy install script.
13+
14+
- (Optional) Edit the ```configs/.env.dev.example``` to set the environment variables. If not done, default values will be taken.
15+
16+
- (Optional) Edit the ```external_ref_fields.example.yaml``` to extend the schema of licenses and obligations with custom fields. If not done, default values will be taken.
17+
18+
- Run the easy install script to generate the app binary.
19+
20+
```bash
21+
./easy_install.sh
22+
```
23+
24+
- Run the executable
25+
26+
```bash
27+
./laas
28+
```
29+
30+
Use the command below for more startup options.
31+
32+
```bash
33+
./laas --help
34+
```
35+
36+
## 2. Docker Installation
37+
38+
- Build the app image
39+
40+
```bash
41+
docker build -t licensedb/latest
42+
```
43+
44+
- Run the container
45+
46+
```bash
47+
docker compose up
48+
```
49+
50+
## 3. Bare metal Installation
51+
52+
### 1. Setting up the project
53+
54+
- Create the `external_ref_fields.yaml` file in the root directory of the project to extend the schema of licenses and obligations with custom fields.
55+
56+
```bash
57+
cp external_ref_fields.example.yaml external_ref_fields.yaml
58+
vim external_ref_fields.yaml
59+
```
60+
61+
- Generate Go struct for the extra fields listed in the external_ref_fields.yaml.
62+
63+
```bash
64+
go generate ./...
65+
```
66+
67+
- Create the `.env` file in the root directory of the project and change the
68+
values of the environment variables as per your requirement.
69+
70+
```bash
71+
cp configs/.env.dev.example .env
72+
vim .env
73+
```
74+
75+
- Build the project using following command.
76+
77+
```bash
78+
go build ./cmd/laas
79+
```
80+
81+
### 2. Setting up the database
82+
83+
- Create database licensedb and provide user fossy all priviliges to it.
84+
85+
```sql
86+
CREATE DATABASE licensedb;
87+
88+
CREATE USER fossy WITH PASSWORD 'fossy';
89+
90+
GRANT ALL PRIVILEGES ON DATABASE licensedb TO fossy;
91+
```
92+
93+
- Run the migration files.
94+
95+
```bash
96+
migrate -path pkg/db/migrations -database "postgres://fossy:fossy@localhost:5432/licensedb?sslmode=disable" up
97+
```
98+
99+
- Create first user
100+
101+
Connect to the database using `psql` with the following command.
102+
103+
```bash
104+
psql -h localhost -p 5432 -U fossy -d licensedb
105+
```
106+
107+
Run the following query to create the first user.
108+
109+
```sql
110+
INSERT INTO users (user_name, user_password, user_level, display_name, user_email) VALUES ('<username>', '<password>', 'SUPER_ADMIN', '<display_name>', '<user_email>');
111+
```
112+
113+
### 3. Run the executable
114+
115+
```bash
116+
./laas
117+
```
118+
119+
Use the command below for more startup options.
120+
121+
```bash
122+
./laas --help
123+
```
124+
125+
- You can directly run it by the following command.
126+
127+
```bash
128+
go run ./cmd/laas
129+
```
130+
131+
## Post Install
132+
133+
- ### Generating Swagger Documentation
134+
135+
- This step can be skipped if installation is done via the ```easy_install``` script.
136+
- Install [swag](https://github.com/swaggo/swag) using the following command.
137+
138+
```bash
139+
go install github.com/swaggo/swag/cmd/swag@latest
140+
```
141+
142+
- Run the following command to generate swagger documentation.
143+
<!-- https://github.com/swaggo/swag/issues/817#issuecomment-730895033 -->
144+
```bash
145+
swag init --parseDependency --generalInfo api.go --dir ./pkg/api,./pkg/auth,./pkg/db,./pkg/models,./pkg/utils --output ./cmd/laas/docs
146+
```
147+
148+
- Swagger documentation will be generated in `./cmd/laas/docs` folder.
149+
- Run the project and navigate to `http://localhost:8080/swagger/index.html` to view the documentation.
150+
- After changing any documentation comments, format them with following command.
151+
152+
```bash
153+
swag fmt --generalInfo ./pkg/api/api.go --dir ./pkg/api,./pkg/auth,./pkg/db,./pkg/models,./pkg/utils
154+
```
155+
156+
- The super admin user can only create new app users and import licenses and obligations.
157+
158+
To gain further capabilities, create a new admin user via the swagger docs or via the [LicenseDb UI](https://github.com/fossology/LicenseDb-UI).

cmd/laas/main.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,9 +28,9 @@ import (
2828

2929
// declare flags to input the basic requirement of database connection and the path of the data file
3030
var (
31-
datafile = flag.String("datafile", "licenseRef.json", "datafile path")
31+
datafile = flag.String("datafile", "licenseRef.json", "(optional) path of the file from which licenses are to be imported")
3232
// auto-update the database
33-
populatedb = flag.Bool("populatedb", false, "boolean variable to update database")
33+
populatedb = flag.Bool("populatedb", false, "(optional) boolean variable to populate database with licences, obligation types and classifications on start up")
3434
)
3535

3636
func main() {

configs/.env.dev.example

Lines changed: 12 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -9,34 +9,35 @@ READ_API_AUTHENTICATION_ENABLED=false
99

1010
PORT=8080
1111

12-
# OIDC Provider (To be set if OIDC Authentication support required)
12+
# Email Password JWT Token Configuration
13+
DEFAULT_ISSUER=http://localhost:5000
14+
15+
# OIDC Provider (Optional, to be set if OIDC Authentication support required)
1316
# The URL for retrieving keys for Token Parsing
14-
JWKS_URI=https://provider/keys
17+
# JWKS_URI=https://provider/keys
1518

1619
# The field in ID Token that is to be used as username
17-
OIDC_USERNAME_KEY=employee_id
20+
# OIDC_USERNAME_KEY=employee_id
1821

1922
# The field in ID Token that is to be used as email
20-
OIDC_EMAIL_KEY=mail
23+
# OIDC_EMAIL_KEY=mail
2124

2225
# The issuer url
23-
OIDC_ISSUER=https://provider
26+
# OIDC_ISSUER=https://provider
2427

2528
# The field in ID Token that is used as display name
26-
OIDC_DISPLAYNAME_KEY=display_name
29+
# OIDC_DISPLAYNAME_KEY=display_name
2730

2831
# Some OIDC providers do not provide the "alg" header in their key set(ex. AzureAD)
2932
# This env variable, if set, will be used for signing while verifying the JWT signature
3033
# (Make sure it's same as the signing algorithm used by the provider)
3134
#
3235
# For OIDC providers that provide the "alg" header in their key set, there is no need for this to be set
33-
OIDC_SIGNING_ALG=RS256
36+
# OIDC_SIGNING_ALG=RS256
3437

3538
# LicenseDB M2M Configuration (To be set if M2M communication support required)
3639
# This field's should be equal to the oidc instance's client id
37-
OIDC_CLIENT_TO_USER_MAPPER_CLAIM=azp
38-
39-
40+
# OIDC_CLIENT_TO_USER_MAPPER_CLAIM=azp
4041

4142
# Database info
4243
DB_NAME=licensedb
@@ -49,4 +50,4 @@ DB_HOST=localhost
4950
# This value can be adjusted based on the requirements of the similarity search
5051
# A lower value will result in more matches, while a higher value will be more strict
5152
# Default is set to 0.7, but can be changed to a higher value like 0.8 or 0.9 for stricter matching
52-
SIMILARITY_THRESHOLD = 0.8
53+
SIMILARITY_THRESHOLD = 0.9

0 commit comments

Comments
 (0)