Skip to content

Commit 1d09920

Browse files
Merge pull request #156 from Real-Dev-Squad/develop
Dev to main merge
2 parents 6264763 + a7c39ec commit 1d09920

File tree

114 files changed

+1472
-3564
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

114 files changed

+1472
-3564
lines changed

.env.sample

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
DB_NAME=skilltree
2+
MYSQL_DB_USERNAME=testuser
3+
MYSQL_DB_PASSWORD=testpassword
4+
MYSQL_ROOT_PASSWORD=password
5+
DB_DDL_POLICY=update
6+
RDS_BACKEND_BASE_URL=http://localhost:3000
7+
SKILL_TREE_FRONTEND_BASE_URL=https://localhost
8+
SKILL_TREE_BACKEND_BASE_URL=http://localhost:8080
9+
RDS_PUBLIC_KEY="-----BEGIN PUBLIC KEY-----
10+
MIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEAg5HrGgKFmH485DXLG4fG
11+
1mKNXceWthXgAozsUGHxLIM3Fa5wU+tLi7tLDZ6LRKo4ZZV2gJJdDqFSNsvn1Uvr
12+
XygvkCCRD/DYjxpG/qNiq9kgv7G8gjVI394oJWgx9uWTmDp4DmEVi7rIviyqVimE
13+
V1nzdlKfGeLckagsetPS28rqULVGXaIAOL52vzrk3O74MnvCSVkjH/+cxEHE7XGg
14+
ryy1fcH9CXvgrXxOLG2xrIdHrV39WBaMC4KOt5piCXgz2tAfhy47x6tIaEj5URx/
15+
jxQoSPZJ5TAf27pjPvUkGVs726RlO0tBLteNzTAWCVZ0QeMoMzBwtdloouC+Rzj2
16+
8QIDAQAB
17+
-----END PUBLIC KEY-----"

.github/workflows/deploy-to-ec2.yml

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@ on:
55
branches:
66
- main
77
- develop
8-
- feat/aws-deploy # Remove before merting this PR to dev
98

109
jobs:
1110
build-and-push:
@@ -53,5 +52,14 @@ jobs:
5352
--name ${{ github.event.repository.name }}-${{ vars.ENV }} \
5453
--network=${{ vars.DOCKER_NETWORK }} \
5554
-e RDS_PUBLIC_KEY="${{ secrets.RDS_PUBLIC_KEY }}" \
55+
-e MYSQL_HOST="${{ secrets.MYSQL_HOST }}" \
56+
-e MYSQL_PORT="${{ secrets.MYSQL_PORT }}" \
57+
-e DB_NAME="${{ vars.DB_NAME }}" \
58+
-e MYSQL_DB_USERNAME="${{ secrets.MYSQL_DB_USERNAME }}" \
59+
-e MYSQL_DB_PASSWORD="${{ secrets.MYSQL_DB_PASSWORD }}" \
60+
-e RDS_BACKEND_BASE_URL="${{ vars.RDS_BACKEND_BASE_URL }}" \
61+
-e SKILL_TREE_BACKEND_BASE_URL="${{ vars.SKILL_TREE_BACKEND_BASE_URL }}" \
62+
-e SKILL_TREE_FRONTEND_BASE_URL="${{ vars.SKILL_TREE_FRONTEND_BASE_URL }}" \
63+
-e SPRING_PROFILES_ACTIVE="${{ vars.SPRING_PROFILES_ACTIVE }}" \
5664
-e API_V1_PREFIX=/api/v1 \
5765
${{ secrets.DOCKERHUB_USERNAME }}/${{ github.event.repository.name }}

Makefile

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,6 @@
1+
copy-env:
2+
cp .env.sample .env
3+
14
# Setup MySql Database
25
docker-run:
36
@if command -v docker > /dev/null; then \
@@ -21,5 +24,8 @@ setup:
2124
@echo "--- Setting up docker ---"
2225
@make docker-run
2326

27+
@echo "--- Copying env ---"
28+
@make copy-env
29+
2430
@echo "\n"
2531
@echo "Setup complete!"

README.md

Lines changed: 64 additions & 190 deletions
Original file line numberDiff line numberDiff line change
@@ -1,197 +1,78 @@
11
# Skill Tree Backend
22

3-
## Steps to Run the Service Locally
4-
5-
### Required Tools
6-
7-
- [Maven](https://maven.apache.org/download.cgi) version 3.9.6 or higher
8-
9-
Installing Maven on macOS using Homebrew:
10-
11-
1. Open your terminal.
12-
2. Type the following command and press Enter to install Homebrew (if not installed):
13-
14-
```bash
15-
/bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)"
16-
```
17-
18-
3. Once Homebrew is installed, run the following command to install Maven:
3+
## Required Tools
4+
- [Homebrew](https://brew.sh/) (If you're using macOS)
5+
- [Maven](https://maven.apache.org/download.cgi) (version 3.9.6 or higher)
6+
- [Java](https://www.oracle.com/in/java/technologies/downloads/#java17) (version 17)
7+
- [IntelliJ Community or Ultimate Edition](https://www.jetbrains.com/idea/download/other.html)
8+
- [Docker Desktop](https://www.docker.com/products/docker-desktop/)
9+
10+
## Development Setup
11+
### Install Maven
12+
#### macOS
13+
1. To install maven type the following command in your terminal:
14+
```bash
1915
brew install maven
20-
21-
4. Wait for the installation process to complete.
22-
23-
5. Verify the Maven installation by typing:
16+
```
17+
2. Verify your installation using the following command:
18+
```bash
2419
mvn -version
20+
```
21+
If maven is installed correctly you should see the maven version in the terminal:
22+
```bash
23+
Apache Maven 3.9.7
24+
```
2525

26-
This should display information about the installed Maven version.
27-
28-
Installing Maven on Windows:
29-
26+
#### Windows
3027
1. 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.
31-
3228
2. Adding Maven to the Environment Path
3329
We add both M2_HOME and MAVEN_HOME variables to the Windows environment using system properties and point them to our Maven folder.
34-
3530
3. Verify the Maven installation by typing:
3631
mvn -version
32+
4. Then, we update the PATH variable by appending the Maven bin folder — %M2_HOME%\bin — so that we can run the Maven command everywhere.
33+
34+
### Setup database and configure env
35+
- To setup the database & create a `.env` file run the following command in your terminal:
36+
```bash
37+
make setup
38+
```
39+
- To edit your environment variables edit the `.env` file.
40+
41+
#### NOTE:
42+
- If you do not have `make` installed, run the `docker-run` and `copy-env` commands from the `Makefile` manually.
43+
44+
### Install EnvFile Plugin in IntelliJ
45+
- To read the values from your `.env` you will need install the `EnvFile` plugin.
46+
- To Install the plugin to go `settings` > `Plugins` > `Marketplace` > EnvFile.
47+
![img.png](public/highlight-env-file-plugin.png)
48+
49+
### Create a configuration in IntelliJ
50+
- Press the Edit configurations button on the top right of your screen
51+
![img.png](public/highlight-edit-config.png)
52+
- Create a new application
53+
![img.png](public/create-new-application.png)
54+
- Select `Java version 17`, `Skill tree` and `SkillTreeApplication`
55+
![img.png](public/highlight-java-version-main-class.png)
56+
- Check `EnvFile` and `Substitute Environment Variables`
57+
![img.png](public/highlight-check-env.png)
58+
- Add path to the `.env` file you created above
59+
![img.png](public/highlight-add-new-env-cta.png)
60+
- You should a new entry like so:
61+
![img.png](public/highlight-env-list.png)
62+
- Click on `Apply` and then `Ok`
63+
64+
### Running your application
65+
- Press the `Run` button on the top right of your screen to run the application.
66+
![img.png](public/highlight-run-application.png)
67+
68+
## Steps to authenticate a user during development
69+
- Run RDS backend on your local machine
70+
- Copy the `public key` from `local.js` (if not in `local.js` copy it from `development.js`) and add it in your `.env` file.
71+
- Run skill tree frontend, click on `signin with github` button
72+
- Once authenticated you will be redirected to `localhost:4000` (skill tree frontend homepage) and a `rds-session-v2-development` cookie will be set in the browser which will be used for authentication when making API calls.
73+
- NOTE:
74+
- make sure that `incompleteUserDetails` is false for the user in firestore, else the redirect will not work as intended.
3775

38-
Then, we update the PATH variable by appending the Maven bin folder — %M2_HOME%\bin — so that we can run the Maven command everywhere.
39-
40-
Then, we unzip it to the folder where we want Maven to live.
41-
42-
- Java (version 17 or higher) [Link](https://www.oracle.com/java/technologies/javase/jdk17-archive-downloads.html)
43-
- Any text editor of your choice (Preferred - IntelliJ Community or Ultimate Edition).
44-
- Docker Desktop: [Installation steps](https://docs.docker.com/engine/install/)
45-
- MySQL Docker Image: [Installation steps](https://hub.docker.com/_/mysql)
46-
47-
### Steps to Login to MySQL
48-
49-
1. Go to Docker Desktop
50-
51-
2. You'll see skill-tree-backed (If the process is running)
52-
53-
3. skill-tree-backend > skill-tree-backend-db-1 > open in terminal
54-
55-
To login to MySQL
56-
57-
```
58-
mysql -u root -p
59-
```
60-
61-
(in terminal)
62-
password : password
63-
64-
Reference Screenshots:
65-
66-
If the project is started with `docker compose up`, this can be seen once you open Docker Desktop:
67-
68-
<img width="1680" alt="Screenshot 2023-12-26 at 9 33 17 PM" src="https://github.com/ashifkhn/skill-tree-backend/assets/54736284/57b90473-ae22-45b2-8a19-3377bfbcf1b9">
69-
70-
Terminal needs to be opened here:
71-
72-
![image](https://github.com/ashifkhn/skill-tree-backend/assets/54736284/d66166ae-b931-40ab-914f-f42615323a32)
73-
74-
## Steps for Creating the Database (To be executed in order)
75-
76-
Semicolon is important in the commands
77-
78-
Username: testuser
79-
Password: testpassword
80-
81-
```
82-
CREATE DATABASE skilltree;
83-
SHOW DATABASES;
84-
CREATE USER 'testuser'@'localhost' IDENTIFIED BY 'testpassword';
85-
GRANT ALL ON skilltree.* TO testuser;
86-
```
87-
88-
## Steps for setting up skill-tree in Intellij
89-
90-
1. After creating the database project needs to be compiled.
91-
2. Open skill-tree-backend in intellij.
92-
3. Java_Home path needs to be added here.
93-
4. You can either add the existing path and JDK 17 can be downloaded inside intellij.
94-
5. If adding from the existing path, go to Settings > Project Structure > Choose the earlier installed Java 17 SDK.
95-
6. Install Lombok plug-in, if you see annotation errors
96-
97-
## Creating Run/Debug Configuration
98-
99-
1. Create a .env file inside the skill-tree folder with content mentioned in the Additional Configuration Steps below
100-
2. Click on "Edit Configurations" > Add new "Application" Configuration
101-
3. Choose "Java 17" and "skill-tree" folder in the dropdown
102-
4. Choose com.RDS.skilltree.SkillTreeApplication as the Main class
103-
5. Add the .env file you created in the first step for the environment variables and click "OK"
104-
105-
(Below steps are not required as of now.)
106-
107-
### Steps to Connect the Service to MySQL Running in Docker
108-
109-
Refer to this [link](https://find10archived.medium.com/how-to-connect-a-mysql-docker-container-with-a-local-spring-boot-application-9366707dce0d) for detailed steps.
110-
111-
1. Create a database user with full access for table creation, deletion, and modification (for development only in local MySQL).
112-
2. After creating the database user, enter the credentials in the Skill Tree Spring Boot application.
113-
3. Attempt to connect to the database using the URL "jdbc:mysql://${MYSQL_HOST:localhost}:3306/${DB_NAME}".
114-
4. Create a simple API to test the database connection and data retrieval. For example, create a `/test` route in `skill-tree/src/main/java/com/RDS/skilltree/User/UserController.java`.
115-
116-
```java
117-
package com.RDS.skilltree.User;
118-
119-
import org.springframework.web.bind.annotation.GetMapping;
120-
import org.springframework.web.bind.annotation.RestController;
121-
122-
@RestController
123-
public class UserController {
124-
@GetMapping("/test")
125-
public void test(){
126-
System.out.println("test123");
127-
}
128-
}
129-
```
130-
131-
### Steps to Generate a JWT Token (Similar to [Website Backend Repo](https://github.com/Real-Dev-Squad/website-backend/issues))
132-
133-
1. If you've already generated the public and private keys during the website backend setup, you can proceed directly to step 5.
134-
2. Ensure the website-backend is running locally.
135-
3. Generate Public and Private keys using openssl with the following commands:
136-
- `openssl genrsa -out ./private.key 4096`
137-
- `openssl rsa -in private.key -pubout -outform PEM -out public.key`
138-
4. Obtain a user token (private and public key stored in `local.js` file).
139-
5. After calling `localhost:3000/auth/github/login`, the backend will generate the JWT token.
140-
6. Validate the token using [jwt.io](https://jwt.io/) by entering the public and private keys stored in the website backend.
141-
7. Use the public key in the Skill Tree repo to decrypt the JWT token passed for authentication.
142-
143-
## Steps for connecting mysql workbench to run mysql inside docker
144-
145-
1. `docker exec -it skill-tree-db-1 bin/bash`
146-
2. bash-4.4# `mysql -u root -p -A`
147-
148-
By default after deployment MySQL has following connection restrictions:
149-
150-
```
151-
mysql> select host, user from mysql.user;
152-
+-----------+---------------+
153-
| host | user |
154-
+-----------+---------------+
155-
| localhost | healthchecker |
156-
| localhost | mysql.session |
157-
| localhost | mysql.sys |
158-
| localhost | root |
159-
+-----------+---------------+
160-
4 rows in set (0.00 sec)
161-
```
162-
163-
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:
164-
165-
3. update mysql.user set host='%' where user='root';
166-
4. Quit the mysql client.
167-
5. Restart the docker container
168-
169-
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`
170-
171-
## Additional Configuration Steps
172-
173-
1. Download the EnvFile plugin from the marketplace.
174-
2. Create a new Env file with the provided content and fill in the RDS public key value.
175-
```env
176-
DB_NAME=${DB_NAME}
177-
MYSQL_DB_USERNAME=testuser
178-
MYSQL_DB_PASSWORD=testpassword
179-
MYSQL_ROOT_PASSWORD=password
180-
DB_DDL_POLICY=update
181-
RDS_PUBLIC_KEY="-----BEGIN PUBLIC KEY-----
182-
xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
183-
-----END PUBLIC KEY-----"
184-
```
185-
> Note : Publickey in both [RDS backend](https://github.com/Real-Dev-Squad/website-backend) and skilltree backend should be the same.
186-
3. Click "Edit Configurations" -> Create a new application.
187-
4. Give it a name instead of "Unnamed".
188-
5. In "Build and Run", select Java 17.
189-
6. In the class , check "Enable Env file" and "Substitute env var" checkboxes.
190-
7. Click "Apply" and "OK".
191-
8. Click "Build and Run".
192-
9. Retrieve the Bearer token by accessing `http://localhost:3000/auth/github/login` and locating the key `rds-session-development` in the application. The value associated with this key is the `Bearer token`.
193-
10. Click the green "Run" button or "Shift + F10" to start the application
194-
11. After starting the Tomcat server on port `8080`, attempt to access the dummy route `http://localhost:8080/test` using the `GET` method in Postman or ThunderClient while providing the `bearer token`. If the terminal displays `test123`, it indicates that the setup has been successful.
19576

19677
## To Authenticate Yourself
19778

@@ -212,10 +93,3 @@ Please build using `mvn compile` in local or run `mvn spotless:apply` before pus
21293
To check if the codebase is formatted, you can explicitly use `mvn spotless:check`
21394

21495
The Continuous Integration build for pushed commits may fail when a Pull Request is created if your code doesn't follow project's formatting guideline.
215-
216-
## Known Issues Faced by Other Developers
217-
218-
1. 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)
219-
2. Local MySQL Conflict: Make sure there is no local Mysql running on the local machine
220-
221-
---

public/create-new-application.png

290 KB
Loading
761 KB
Loading

public/highlight-check-env.png

721 KB
Loading

public/highlight-edit-config.png

146 KB
Loading
469 KB
Loading

public/highlight-env-list.png

331 KB
Loading

0 commit comments

Comments
 (0)