Skip to content

Commit 939c13a

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

File tree

6 files changed

+304
-98
lines changed

6 files changed

+304
-98
lines changed

README.md

Lines changed: 34 additions & 72 deletions
Original file line numberDiff line numberDiff line change
@@ -57,111 +57,71 @@ 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-
6160
## Prerequisite
6261

63-
Before proceeding, make sure you have the following installed on your system:
64-
65-
62+
Before setting up the project, ensure the following tools are installed on your system:
6663

64+
### 1. Golang (Go)
6765

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

70-
Follow the official instructions to install Golang:
71-
👉 [https://go.dev/doc/install](https://go.dev/doc/install)
69+
### 2. PostgreSQL (v14 or later)
7270

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

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?
80+
#### Option B: Official Installer
8381

84-
- Clone this Project and Navigate to the folder.
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/)
8584

86-
``` bash
87-
git clone https://github.com/fossology/LicenseDb.git
88-
cd LicenseDb
89-
```
90-
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.
93-
94-
```bash
95-
cp external_ref_fields.example.yaml external_ref_fields.yaml
96-
vim external_ref_fields.yaml
97-
```
85+
### 3. Install golang-migrate CLI
9886

99-
- Generate Go struct for the extra fields listed in the external_ref_fields.yaml.
100-
101-
```bash
102-
go generate ./...
103-
```
104-
105-
- Build the project using following command.
106-
107-
```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-
```
87+
#### For Linux & macOS
11888

119-
- Run the migration files.
12089
```bash
121-
migrate -path pkg/db/migrations -database "postgres://fossy:fossy@localhost:5432/licensedb?sslmode=disable" up
90+
curl -L https://github.com/golang-migrate/migrate/releases/latest/download/migrate.linux-amd64.tar.gz | tar xvz
91+
sudo mv migrate /usr/local/bin/
12292
```
12393

124-
- Run the executable.
94+
For other platforms and installation methods, check the official docs:
95+
👉 [https://github.com/golang-migrate/migrate](https://github.com/golang-migrate/migrate)
12596

126-
```bash
127-
./laas
128-
```
97+
## How to run this project?
12998

130-
- You can directly run it by the following command.
99+
👉 Please follow the [Setup Guide](./SETUP.md) for step-by-step instructions on how to run the project.
131100

132-
```bash
133-
go run ./cmd/laas
134-
```
101+
## Generating Swagger Documentation
135102

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-
```
103+
- Install [swag](https://github.com/swaggo/swag) using the following command.
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-
```
146-
147-
### Generating Swagger Documentation
148-
1. Install [swag](https://github.com/swaggo/swag) using the following command.
149105
```bash
150106
go install github.com/swaggo/swag/cmd/swag@latest
151107
```
152-
2. Run the following command to generate swagger documentation.
108+
109+
- Run the following command to generate swagger documentation.
153110
<!-- https://github.com/swaggo/swag/issues/817#issuecomment-730895033 -->
154111
```bash
155112
swag init --parseDependency --generalInfo api.go --dir ./pkg/api,./pkg/auth,./pkg/db,./pkg/models,./pkg/utils --output ./cmd/laas/docs
156113
```
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.
114+
115+
- Swagger documentation will be generated in `./cmd/laas/docs` folder.
116+
- Run the project and navigate to `http://localhost:8080/swagger/index.html` to view the documentation.
117+
- After changing any documentation comments, format them with following command.
118+
160119
```bash
161120
swag fmt --generalInfo ./pkg/api/api.go --dir ./pkg/api,./pkg/auth,./pkg/db,./pkg/models,./pkg/utils
162121
```
163122

164123
### Testing (local)
124+
165125
The PostgreSQL user `fossy` must have the `CREATEDB` privilege in order to:
166126

167127
- Programmatically create and drop a test database.
@@ -172,7 +132,9 @@ sudo -u postgres psql; // log into psql with postgres super user
172132
ALTER USER fossy CREATEDB; // alter the role for fossy
173133
\du ; // verify role
174134
```
135+
175136
Create the `.env.test` file file in the `configs` directory of the project.
176-
```
137+
138+
```bash
177139
cp configs/.env.test.example .env.test
178-
```
140+
```

SETUP.md

Lines changed: 137 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,137 @@
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+
51+
52+
## 3. Bare metal Installation
53+
54+
### 1. Setting up the project
55+
56+
- 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.
57+
58+
```bash
59+
cp external_ref_fields.example.yaml external_ref_fields.yaml
60+
vim external_ref_fields.yaml
61+
```
62+
63+
- Generate Go struct for the extra fields listed in the external_ref_fields.yaml.
64+
65+
```bash
66+
go generate ./...
67+
```
68+
69+
- Create the `.env` file in the root directory of the project and change the
70+
values of the environment variables as per your requirement.
71+
72+
```bash
73+
cp configs/.env.dev.example .env
74+
vim .env
75+
```
76+
77+
- Build the project using following command.
78+
79+
```bash
80+
go build ./cmd/laas
81+
```
82+
83+
### 2. Setting up the database
84+
85+
- Create database licensedb and provide user fossy all priviliges to it.
86+
87+
```sql
88+
CREATE DATABASE licensedb;
89+
90+
CREATE USER fossy WITH PASSWORD 'fossy';
91+
92+
GRANT ALL PRIVILEGES ON DATABASE licensedb TO fossy;
93+
```
94+
95+
- Run the migration files.
96+
97+
```bash
98+
migrate -path pkg/db/migrations -database "postgres://fossy:fossy@localhost:5432/licensedb?sslmode=disable" up
99+
```
100+
101+
- Create first user
102+
103+
Connect to the database using `psql` with the following command.
104+
105+
```bash
106+
psql -h localhost -p 5432 -U fossy -d licensedb
107+
```
108+
109+
Run the following query to create the first user.
110+
111+
```sql
112+
INSERT INTO users (user_name, user_password, user_level, display_name, user_email) VALUES ('<username>', '<password>', 'SUPER_ADMIN', '<display_name>', '<user_email>');
113+
```
114+
115+
### 3. Run the executable
116+
117+
```bash
118+
./laas
119+
```
120+
121+
Use the command below for more startup options.
122+
123+
```bash
124+
./laas --help
125+
```
126+
127+
- You can directly run it by the following command.
128+
129+
```bash
130+
go run ./cmd/laas
131+
```
132+
133+
## Post Install
134+
135+
The super admin user can only create new app users and import licenses and obligations.
136+
137+
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)