Skip to content

Commit 882c98c

Browse files
docs: update installation guide for React–backend integration
1 parent 22c20cc commit 882c98c

File tree

1 file changed

+115
-77
lines changed

1 file changed

+115
-77
lines changed

docs/Installation.md

Lines changed: 115 additions & 77 deletions
Original file line numberDiff line numberDiff line change
@@ -8,67 +8,77 @@ _**NOTE:**_
88
* make sure you are logged in as user with sudo permissions
99

1010
### Step 1: Install prerequisite
11-
12-
sudo apt-get update
13-
sudo apt-get install -y python3 python3-pip gcc git python3-dev libssl-dev libffi-dev cron python3-lxml apache2 libapache2-mod-wsgi-py3
14-
sudo pip3 install cffi cryptography Flask launchpadlib simplejson requests pytest
11+
```bash
12+
sudo apt-get update
13+
sudo apt-get install -y python3 python3-pip gcc git python3-dev libssl-dev libffi-dev cron python3-lxml apache2 libapache2-mod-wsgi-py3
14+
sudo pip3 install cffi cryptography Flask launchpadlib simplejson requests pytest
15+
```
1516

1617
* if "/usr/local/bin" is not part of $PATH add it to the path:
17-
18-
echo $PATH
19-
export PATH=/usr/local/bin:$PATH
20-
sudo sh -c "echo 'export PATH=/usr/local/bin:$PATH' > /etc/profile.d/alternate_install_path.sh"
18+
```bash
19+
echo $PATH
20+
export PATH=/usr/local/bin:$PATH
21+
sudo sh -c "echo 'export PATH=/usr/local/bin:$PATH' > /etc/profile.d/alternate_install_path.sh"
22+
```
2123

2224
### Step 2: Checkout the source code, into /opt/ folder
23-
24-
cd /opt/
25-
sudo git clone https://github.com/openmainframeproject/software-discovery-tool.git
26-
cd software-discovery-tool
27-
25+
```bash
26+
cd /opt/
27+
sudo git clone https://github.com/openmainframeproject/software-discovery-tool.git
28+
cd software-discovery-tool
29+
```
30+
2831
Note: In case software-discovery-tool code is already checked out, do the following for latest updates
29-
30-
cd /opt/software-discovery-tool
31-
sudo git pull origin master
32+
```bash
33+
cd /opt/software-discovery-tool
34+
sudo git pull origin master
35+
```
3236

3337
### Step 3: Set Environment variables
34-
35-
sudo sh -c "echo 'export PYTHONPATH=/opt/software-discovery-tool/src/classes:/opt/software-discovery-tool/src/config:$PYTHONPATH' > /etc/profile.d/software-discovery-tool.sh"
36-
38+
```bash
39+
sudo sh -c "echo 'export PYTHONPATH=/opt/software-discovery-tool/src/classes:/opt/software-discovery-tool/src/config:$PYTHONPATH' > /etc/profile.d/software-discovery-tool.sh"
40+
```
41+
3742
### Step 4: Install and configure software-discovery-tool
3843

3944
#### Copy the apache configuration file from `/opt/software-discovery-tool/src/config/sdt.conf` into respective apache configuration folder as below
40-
41-
sudo cp -f /opt/software-discovery-tool/src/config/sdt.conf /etc/apache2/sites-available/sdt.conf
42-
sudo mv /etc/apache2/sites-available/000-default.conf /etc/apache2/sites-available/z-000-default.conf
45+
```bash
46+
sudo cp -f /opt/software-discovery-tool/src/config/sdt.conf /etc/apache2/sites-available/sdt.conf
47+
sudo mv /etc/apache2/sites-available/000-default.conf /etc/apache2/sites-available/z-000-default.conf
48+
```
49+
4350

4451
#### Create new user and group for apache
45-
46-
sudo useradd apache
47-
sudo groupadd apache
48-
52+
```bash
53+
sudo useradd apache
54+
sudo groupadd apache
55+
```
56+
4957
#### Set appropriate folder and file permission on /opt/software-discovery-tool/ folder for apache
50-
51-
sudo chown -R apache:apache /opt/software-discovery-tool/
58+
```bash
59+
sudo chown -R apache:apache /opt/software-discovery-tool/
60+
```
5261

5362
#### Start/Restart Apache service
54-
55-
sudo apachectl restart
63+
```bash
64+
sudo apachectl restart
65+
```
5666

5767
### Step 5: Cloning Data Directory (Only First Time)
5868
openmainframeproject/software-discovery-tool-data contains all OMP created json files. To add the data files, we will use `git submodule`
5969
- map the submodule directory with the directory path and update the directory:
60-
```
70+
```bash
6171
sudo -u apache git submodule update --init --recursive --remote
6272
```
6373

6474
#### Updating Data Directory
6575
Everytime there's an upstream change in the submodule:
6676
- To update the data directory with the main repo with the remote changes:
67-
```
77+
```bash
6878
sudo -u apache git pull <upstream remote> <default branch> --recurse-submodules
6979
```
7080
- To update ONLY the data directory keeping the main repo as it is:
71-
```
81+
```bash
7282
sudo -u apache git submodule update --recursive --remote
7383
```
7484

@@ -78,7 +88,7 @@ The data directory we cloned above only brings in sources maintained by this pro
7888

7989
For example, taking RHEL_8_Package_List.json
8090
- Usage help will be displayed:
81-
```
91+
```bash
8292
cd /opt/software-discovery-tool/bin
8393
./package_build.py
8494
Usage:
@@ -92,7 +102,7 @@ Example:
92102
./package_build.py RHEL_8_Package_List.json
93103
```
94104
Example of extracting the RHEL_8_Package_List.json from PDS repo:
95-
```
105+
```bash
96106
sudo -u apache ./bin/package_build.py RHEL_8_Package_List.json
97107
Extracting RHEL_8_Package_List.json from PDS data ...
98108
Thanks for using SDT!
@@ -101,7 +111,7 @@ Thanks for using SDT!
101111
- Make sure the json file exists in the PDS data directory.
102112
- Please keep in mind that the directory belongs to user `apache`, so in case of permission error,
103113
run the chown cmd or directly use `package_build.py` as `apache` user like:
104-
```
114+
```bash
105115
sudo -u apache ./bin/package_build.py RHEL_8_Package_List.json
106116
```
107117

@@ -113,24 +123,37 @@ The `src/config/supported_distros.py` must now be updated to reflect the new jso
113123
### Step 6: Install and populate the SQL database
114124

115125
#### Install dependencies and complete the secure installation. Remember the root password you set, you will need this in the future.
126+
```bash
127+
sudo apt install mariadb-server python3-pymysql
128+
sudo mysql_secure_installation
129+
```
116130

117-
sudo apt install mariadb-server python3-pymysql
118-
sudo mysql_secure_installation
131+
***NOTE:***
132+
- If you encounter the following error when running `sudo mysql_secure_installation`:
133+
```bash
134+
Enter current password for root (enter for none):
135+
ERROR 2002 (HY000): Can't connect to local server through socket '/run/mysqld/mysqld.sock' (2)
136+
```
137+
It means the MariaDB service is not running. Start it with:
138+
```bash
139+
sudo service mariadb start
140+
```
119141
120142
#### Log in to MariaDB with the root account you set and create the read-only user (with a password, changed below) and database.
143+
```bash
144+
# Log in to MariaDB with the root account you set.
145+
mariadb -u root -p
121146
122-
# Log in to MariaDB with the root account you set.
123-
mariadb -u root -p
124-
125-
# Create the read-only user
126-
MariaDB> CREATE USER 'sdtreaduser'@'localhost' IDENTIFIED BY 'SDTUSERPWD'; # Replace 'SDTUSERPWD' with the desired password.
147+
# Create the read-only user
148+
MariaDB> CREATE USER 'sdtreaduser'@'localhost' IDENTIFIED BY 'SDTUSERPWD'; # Replace 'SDTUSERPWD' with the desired password.
127149
128-
# Grant permissions.
129-
MariaDB> GRANT SELECT ON sdtDB.* TO 'sdtreaduser'@'localhost';
150+
# Grant permissions.
151+
MariaDB> GRANT SELECT ON sdtDB.* TO 'sdtreaduser'@'localhost';
130152
131-
# Apply changes and exit.
132-
MariaDB> flush privileges;
133-
MariaDB> quit
153+
# Apply changes and exit.
154+
MariaDB> flush privileges;
155+
MariaDB> quit
156+
```
134157
135158
***NOTE:***
136159
- For enhanced security, it's recommended to grant the software-discovery-tool user (sdtreaduser) only read (SELECT) permissions on the required database. This adheres to the principle of least privilege and minimizes the impact if the user credentials are compromised.
@@ -144,19 +167,29 @@ The `src/config/supported_distros.py` must now be updated to reflect the new jso
144167
See `.env.example` and create a `.env` file in `/opt/software-discovery-tool/`, replacing the value of `DB_PASSWORD` with your own.
145168

146169
#### Run the script to populate the database, when prompted by the script for a user and password, use the root account and password you set above.
147-
148-
cd /opt/software-discovery-tool/bin/
149-
./database_build.py
150-
170+
```bash
171+
cd /opt/software-discovery-tool/bin/
172+
./database_build.py
173+
```
174+
***NOTE:***
175+
- If you encounter the following error:
176+
```bash
177+
pymysql.err.OperationalError: (1698, "Access denied for user 'root'@'localhost'")
178+
```
179+
Then give access to root user using:
180+
```bash
181+
mariadb -u root -p
182+
MariaDB> ALTER USER 'root'@'localhost' IDENTIFIED VIA mysql_native_password USING PASSWORD('password'); # Replace the 'password' with the root password you set while installing mariadb.
183+
```
151184
### Step 7: Verify that the software-discovery-tool server is up and running
152185
We now run the following commands to properly enable the config files of the software-discovery-tool server and then restart the apache server.
153-
154-
sudo a2ensite z-000-default.conf
155-
systemctl reload apache2
156-
sudo a2ensite sdt.conf
157-
systemctl reload apache2
158-
sudo apachectl restart
159-
186+
```bash
187+
sudo a2ensite z-000-default.conf
188+
systemctl reload apache2
189+
sudo a2ensite sdt.conf
190+
systemctl reload apache2
191+
sudo apachectl restart
192+
```
160193
We can check if the server is up and running by going to following URL :
161194

162195
```http://server_ip_or_fully_qualified_domain_name:port_number/sdt``` <br />
@@ -165,9 +198,9 @@ We can check if the server is up and running by going to following URL :
165198
```cd software-discovery-tool/src/tests``` <br />
166199

167200
If you run `pytest` as your logged user, it may give errors/warnings since you have given user `apache` ownership.
168-
169-
sudo -u apache pytest
170-
201+
```bash
202+
sudo -u apache pytest
203+
```
171204
_**NOTE:**_
172205

173206
* By default the port_number will be 80
@@ -209,24 +242,28 @@ _**NOTE:**_
209242
In case any of the parameters are updated, the server has to be restarted:
210243

211244
#### Start/Restart Apache service
212-
213-
sudo apachectl restart
214-
245+
```bash
246+
sudo apachectl restart
247+
```
215248
### Step 9: Start React (frontend) server
216249

217250
#### Ensure Node.js and npm are installed
218-
219-
sudo apt install npm
220-
251+
```bash
252+
curl -o- https://raw.githubusercontent.com/nvm-sh/nvm/v0.40.3/install.sh | bash
253+
\. "$HOME/.nvm/nvm.sh"
254+
nvm install 22
255+
node -v # Should print "v22.20.0".
256+
npm -v # Should print "10.9.3".
257+
```
221258

222259
#### Change to the react-frontend directory
223-
224-
cd react-frontend
225-
260+
```bash
261+
cd react-frontend
262+
```
226263
#### Install the required npm packages
227-
228-
sudo npm i
229-
264+
```bash
265+
npm install
266+
```
230267
#### Setting up the Environment Variables
231268

232269
To configure the Flask server URL for your React application, follow these steps:
@@ -245,13 +282,14 @@ To configure the Flask server URL for your React application, follow these steps
245282
- Open the newly created `.env` file and ensure it contains the following line:<br><br>
246283

247284
```plaintext
248-
REACT_APP_API_URL='http://localhost:80/sdt'
285+
REACT_APP_API_URL='http://server_ip_or_fully_qualified_domain_name:80/sdt'
249286
```
250287

251288
3. **Use the Environment Variable:**
252289

253290
The `REACT_APP_API_URL` variable is now set and will be used by your React application to communicate with the Flask server running at the specified URL.
254291

255292
#### Start the react frontend application
256-
257-
sudo npm run start
293+
```bash
294+
npm run start
295+
```

0 commit comments

Comments
 (0)