Skill Tree Backend
Steps to Run the Service Locally
Required Tools
- Maven version 3.9.6 or higher
Installing Maven on macOS using Homebrew:
-
Open your terminal.
-
Type the following command and press Enter to install Homebrew (if not installed): /bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)"
-
Once Homebrew is installed, run the following command to install Maven: brew install maven
-
Wait for the installation process to complete.
-
Verify the Maven installation by typing: mvn -version
This should display information about the installed Maven version.
Installing Maven on Windows:
-
To install Maven on Windows, we head over to the Apache Maven site to download the latest version and select the Maven zip file, for example, apache-maven-3.9.6-bin.zip.
-
Adding Maven to the Environment Path We add both M2_HOME and MAVEN_HOME variables to the Windows environment using system properties and point them to our Maven folder.
-
Verify the Maven installation by typing: mvn -version
Then, we update the PATH variable by appending the Maven bin folder — %M2_HOME%\bin — so that we can run the Maven command everywhere.
Then, we unzip it to the folder where we want Maven to live.
- Java (version 17 or higher) Link
- Any text editor of your choice (Preferred - IntelliJ Community or Ultimate Edition).
- Docker Desktop: Installation steps
- MySQL Docker Image: Installation steps
Steps to Login to MySQL
-
Go to Docker Desktop
-
You'll see skill-tree-backed (If the process is running)
-
skill-tree-backend>skill-tree-backend-db-1>open in terminal
to login to MySQL mysql -u root -p (in terminal) password : rootpassword
Refrence Screenshots:
If the project is started with docker compose up thise can be seen once you open Docker Desktop:
Terminal needs to be opened here:
Steps for Creating the Database
create database skilltree;
(semicolon is important here)show databases;
create user 'testuser' identified by 'testpassword';
(Username: testuser, Password: testpassword)grant all on skilltree.* to testuser;
Steps for Creating the Database
- After creating the database project needs to be compiled.
- Open skill-tree-backend in intellij.
- Java_Home path needs to be added here.
- You can either add the existing path and jdk 17 can be downloaded inside intellij.
(Below steps are not required as of now.)
Steps to Connect the Service to MySQL Running in Docker
Refer to this link for detailed steps.
- Create a database user with full access for table creation, deletion, and modification (for development only in local MySQL).
- After creating the database user, enter the credentials in the Skill Tree Spring Boot application.
- Attempt to connect to the database using the URL "jdbc:mysql://${MYSQL_HOST:localhost}:3306/${DB_NAME}".
- Create a simple API to test the database connection and data retrieval. For example, create a
/test
route inskill-tree/src/main/java/com/RDS/skilltree/User/UserController.java
.package com.RDS.skilltree.User; import org.springframework.web.bind.annotation.GetMapping; import org.springframework.web.bind.annotation.RestController; @RestController public class UserController { @GetMapping("/test") public void test(){ System.out.println("test123"); } }
Website Backend Repo)
Steps to Generate a JWT Token (Similar to- If you've already generated the public and private keys during the website backend setup, you can proceed directly to step 5.
- Ensure the website-backend is running locally.
- Generate Public and Private keys using openssl with the following commands:
openssl genrsa -out ./private.key 4096
openssl rsa -in private.key -pubout -outform PEM -out public.key
- Obtain a user token (private and public key stored in
local.js
file). - After calling
localhost:3000/auth/github/login
, the backend will generate the JWT token. - Validate the token using jwt.io by entering the public and private keys stored in the website backend.
- Use the public key in the Skill Tree repo to decrypt the JWT token passed for authentication.
Steps for connecting mysql workbench to run mysql inside docker
docker exec -it rds-db-1 bin/bash
- bash-4.4#
mysql -u root -p -A
By default after deployment MySQL has following connection restrictions:
mysql> select host, user from mysql.user;
+-----------+---------------+
| host | user |
+-----------+---------------+
| localhost | healthchecker |
| localhost | mysql.session |
| localhost | mysql.sys |
| localhost | root |
+-----------+---------------+
4 rows in set (0.00 sec)
Apparently, for security purposes, you will not be able to connect to it from outside of the docker container. If you need to change that to allow root to connect from any host (say, for development purposes), do the following:
- update mysql.user set host='%' where user='root';
- Quit the mysql client.
- Restart the docker container
Now you can connect to the mysql running in the docker container, also to connect to it on the terminal type mysql -utestuser -p -P3306 -h127.0.0.1
Additional Configuration Steps
- Download the EnvFile plugin from the marketplace.
- Create a new Env file with the provided content and fill in the RDS public key value.
Note : Publickey in both backend and skilltree backend should be the same.
DB_NAME=${DB_NAME} MYSQL_USERNAME=testuser MYSQL_PASSWORD=testpassword DB_DDL_POLICY=update RDS_PUBLIC_KEY="-----BEGIN PUBLIC KEY----- xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx -----END PUBLIC KEY-----"
- Click "Edit Configurations" -> Create a new application.
- Give it a name instead of "Unnamed".
- In "Build and Run", select Java 17.
- In the class , check "Enable Env file" and "Substitute env var" checkboxes.
- Click "Apply" and "OK".
- Click "Build and Run".
- Retrieve the Bearer token by accessing
http://localhost:3000/auth/github/login
and locating the keyrds-session-development
in the application. The value associated with this key is theBearer token
. - Click the green "Run" button or "Shift + F10" to start the application
- After starting the Tomcat server on port
8080
, attempt to access the dummy routehttp://localhost:8080/test
using theGET
method in Postman or ThunderClient while providing thebearer token
. If the terminal displaystest123
, it indicates that the setup has been successful.
Known Issues Faced by Other Developers
- Port 8080 Conflict: Make sure there is no other process running on the 8080 port where we are going to run our server check this with lsof -p PID (PID - port id)
- Local MySQL Conflict: Make sure there is no local Mysql running on the local machine