Skip to content
Open
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
20 changes: 17 additions & 3 deletions docs/Installation.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,19 +2,33 @@

## Steps for setting up software-discovery-tool application on server

The instructions provided below specify the steps for Ubuntu 20.04/22.04/24.04:
The instructions provided below specify the steps for Ubuntu 24.04:

_**NOTE:**_
* make sure you are logged in as user with sudo permissions

### Step 1: Install prerequisites

System prerequisites
#### Install Node.js 22 via NodeSource

Ubuntu 24.04's default apt package provides Node.js 18, which is too old for Vite 8 (requires Node 20.19+ or 22). Install Node.js 22 LTS from NodeSource:

```bash
curl -fsSL https://deb.nodesource.com/setup_22.x | sudo -E bash -
sudo apt-get install -y nodejs
```

Verify:
```bash
node --version # Should print v22.x.x
```

#### Install remaining system dependencies

```bash
sudo apt update
sudo apt dist-upgrade
sudo apt install nodejs npm git mariadb-server
sudo apt install git mariadb-server
# Python is only required if you plan to use bin/package_build.py
sudo apt install python3 python3-requests
```
Expand Down
307 changes: 307 additions & 0 deletions docs/Production_Installation.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,307 @@
# Production Installation

This guide covers deploying the Software Discovery Tool as a production service on Ubuntu 24.04 using Apache2 as the web server. For a developer setup, see [Installation.md](Installation.md).

## Overview

The production deployment has two components:
- **Node.js backend** — runs as a systemd service on port 5000
- **React frontend** — compiled to static files and served by Apache2

## Prerequisites

- Ubuntu 24.04 server with sudo access
- Domain name or IP address for the server

---

## Step 1: Install Node.js 22 (via NodeSource)

Ubuntu 24.04's apt ships Node.js 18 which is too old for Vite 8 (requires Node 20.19+ or 22). Install Node.js 22 LTS from NodeSource:

```bash
curl -fsSL https://deb.nodesource.com/setup_22.x | sudo -E bash -
sudo apt-get install -y nodejs
```

Verify the installation:

```bash
node --version # Should print v22.x.x
npm --version
```

---

## Step 2: Install system dependencies

```bash
sudo apt update
sudo apt dist-upgrade
sudo apt install git apache2 mariadb-server python3 python3-requests
```

---

## Step 3: Clone the repository

```bash
git clone https://github.com/openmainframeproject/software-discovery-tool.git
cd software-discovery-tool
git submodule update --init --recursive
```

---

## Step 4: Set up MariaDB

### Secure the installation

```bash
sudo mariadb-secure-installation
```

### Create the database and read-only user

```bash
mariadb -u root -p
```

```sql
CREATE DATABASE sdtDB;
CREATE USER 'sdtreaduser'@'localhost' IDENTIFIED BY 'REPLACE_WITH_STRONG_PASSWORD';
GRANT SELECT ON sdtDB.* TO 'sdtreaduser'@'localhost';
FLUSH PRIVILEGES;
QUIT;
```

---

## Step 5: Populate the database

### Configure the backend environment

```bash
cp backend/.env.example backend/.env
```

Edit `backend/.env` and set your database credentials:

```
DB_HOST=localhost
DB_USER=sdtreaduser
DB_PASSWORD=REPLACE_WITH_STRONG_PASSWORD
DB_NAME=sdtDB
PORT=5000
ALLOWED_ORIGINS=http://YOUR_SERVER_IP_OR_DOMAIN
```

### Run the database build script

From the repo root:

```bash
npm install
node bin/database_build.js
```

When prompted, enter a privileged MariaDB account (e.g. root) to create the tables.

### Load package data

Use `bin/package_build.py` to import distro data from the `distro_data/` submodule:

```bash
python3 bin/package_build.py RHEL_9_Package_List.json
python3 bin/package_build.py Ubuntu_2404_Package_List.json
# Repeat for each distro you want to include
```

After adding data files, regenerate the distro config:

```bash
python3 bin/config_build.py
```

---

## Step 6: Build the React frontend

On your **development machine** (or the server if Node 22 is available):

```bash
cd react-frontend
npm install
cp .env.example .env
```

Edit `react-frontend/.env`:

```
VITE_REACT_APP_API_URL=/sdt
```

Build the production bundle:

```bash
npm run build
```

This generates compiled static files in `react-frontend/dist/`.

---

## Step 7: Configure Apache2

### Enable required Apache modules

```bash
sudo a2enmod proxy proxy_http rewrite headers
sudo systemctl restart apache2
```

### Create the virtual host configuration

```bash
sudo nano /etc/apache2/sites-available/software-discovery-tool.conf
```

Paste the following (replace `YOUR_DOMAIN_OR_IP`):

```apache
<VirtualHost *:80>
ServerName YOUR_DOMAIN_OR_IP

# Serve React static files
DocumentRoot /opt/software-discovery-tool/react-frontend/dist

<Directory /opt/software-discovery-tool/react-frontend/dist>
Options -Indexes
AllowOverride All
Require all granted

# Support React Router — send all non-file requests to index.html
RewriteEngine On
RewriteBase /
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^ index.html [L]
</Directory>

# Proxy /sdt/* to the Node.js backend
ProxyPass /sdt http://localhost:5000/sdt
ProxyPassReverse /sdt http://localhost:5000/sdt

ErrorLog ${APACHE_LOG_DIR}/sdt-error.log
CustomLog ${APACHE_LOG_DIR}/sdt-access.log combined
</VirtualHost>
```

### Deploy the built files

```bash
sudo mkdir -p /opt/software-discovery-tool/react-frontend
sudo cp -r react-frontend/dist /opt/software-discovery-tool/react-frontend/dist
sudo chown -R www-data:www-data /opt/software-discovery-tool/react-frontend/dist
```

### Enable the site

```bash
sudo a2ensite software-discovery-tool.conf
sudo a2dissite 000-default.conf
sudo systemctl reload apache2
```

---

## Step 8: Run the backend as a systemd service

### Install backend dependencies

```bash
cd /path/to/software-discovery-tool/backend
npm install --omit=dev
```

### Create the systemd service

```bash
sudo nano /etc/systemd/system/sdt-backend.service
```

```ini
[Unit]
Description=Software Discovery Tool Node.js Backend
After=network.target mariadb.service

[Service]
Type=simple
User=www-data
WorkingDirectory=/opt/software-discovery-tool/backend
ExecStart=/usr/bin/node index.js
Restart=on-failure
RestartSec=5
EnvironmentFile=/opt/software-discovery-tool/backend/.env

[Install]
WantedBy=multi-user.target
```

### Copy backend to /opt and start the service

```bash
sudo cp -r backend /opt/software-discovery-tool/backend
sudo cp backend/.env /opt/software-discovery-tool/backend/.env
sudo chown -R www-data:www-data /opt/software-discovery-tool/backend

sudo systemctl daemon-reload
sudo systemctl enable sdt-backend
sudo systemctl start sdt-backend
```

Verify the backend is running:

```bash
sudo systemctl status sdt-backend
curl http://localhost:5000/sdt/getSupportedDistros
```

---

## Step 9: Verify the deployment

Visit `http://YOUR_DOMAIN_OR_IP` in a browser. You should see the Software Discovery Tool frontend and be able to search for packages.

If the frontend loads but searches fail, check:

```bash
sudo tail -f /var/log/apache2/sdt-error.log
sudo journalctl -u sdt-backend -f
```

---

## Updating the deployment

### Update backend

```bash
cd /path/to/software-discovery-tool
git pull
git submodule update --recursive --remote
cd backend && npm install --omit=dev
sudo cp -r backend /opt/software-discovery-tool/
sudo systemctl restart sdt-backend
```

### Update frontend

```bash
cd react-frontend
npm install
npm run build
sudo cp -r dist /opt/software-discovery-tool/react-frontend/dist
sudo chown -R www-data:www-data /opt/software-discovery-tool/react-frontend/dist
sudo systemctl reload apache2
```
Loading