From 8a4edea91837508172da3be3941e24943da5d5f7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?L=C3=AA=20Ti=E1=BA=BFn=20=C4=90=E1=BA=A1t?= <66414511+letiendat1002@users.noreply.github.com> Date: Mon, 11 Mar 2024 14:21:45 +0700 Subject: [PATCH] Update documentation (#191) * Update documentation and fix keep-alive scheduler * Update documentation --- backend/README.md | 15 ++++++--- backend/docs/Deployment.md | 64 ++++++++++++++++++++++++++++++++++++++ 2 files changed, 75 insertions(+), 4 deletions(-) create mode 100644 backend/docs/Deployment.md diff --git a/backend/README.md b/backend/README.md index db510e00..535c280d 100644 --- a/backend/README.md +++ b/backend/README.md @@ -9,6 +9,7 @@ - [Spring Security](https://spring.io/projects/spring-security) - [Spring Web](https://spring.io/projects/spring-web) - [Spring Test](https://spring.io/guides/gs/testing-web/) + - More details please refer to [pom.xml](pom.xml) ## Requirements @@ -20,10 +21,16 @@ 1. [MySQL Scripts](assets/databases/mysql) 2. [Database Design](assets/images/database/database_design.png) 3. [Spring Security Architecture](assets/images/security) -4. [Documentation](docs) ## Documentation -1. [Connect to database](docs/ConnectDatabase.md) -2. [APIs](docs/APIs.md) -3. [Role & Permission](docs/RolePermission.md) +1. [Docs folder](docs) +2. [Connect to database](docs/ConnectDatabase.md) +3. [APIs](docs/APIs.md) +4. [Role & Permission](docs/RolePermission.md) +5. [Deployment](docs/Deployment.md) + +**Notice**: +- To initiate the backend properly, please open this project in the `backend/` folder not the root `e-commerce/` folder. +- To run the project locally, please refer to [Connect to database](docs/ConnectDatabase.md) for more details and remember to change `spring.profiles.active` in [application.yml](src/main/resources/application.yml) from `prod` to `dev` (default value is `prod`). +- To deploy the project, please refer to [Deployment](docs/Deployment.md) for more details and remember to change `spring.profiles.active` in [application.yml](src/main/resources/application.yml) from `dev` to `prod`. diff --git a/backend/docs/Deployment.md b/backend/docs/Deployment.md new file mode 100644 index 00000000..e0a9e6f5 --- /dev/null +++ b/backend/docs/Deployment.md @@ -0,0 +1,64 @@ +# Deployment Guide + +This guide outlines the steps to deploy Linkking project backend web services to a production environment. + +## Table of Contents + +- [Deploy MySQL](#deploy-mysql) +- [Environment Variables](#environment-variables) +- [Deploy Backend](#deploy-backend) + +## Deploy MySQL + +1. **Setup MySQL Server:** + - Install MySQL server on your hosting environment or use a cloud-based MySQL service provider. + - We recommend [aiven.io](https://aiven.io) for cloud-based MySQL hosting. + - Configure the MySQL server to allow remote connections if necessary. + +2. **Database Initialization:** + - Execute the provided SQL script [data_sample.sql](/assets/databases/mysql/data_sample.sql) to initialize the + database schema, necessary tables and sample data. + +## Environment Variables + +1. **Database Configuration:** + - `DB_HOST`: Hostname or IP address of the MySQL server. + - `DB_PORT`: Port number for MySQL server. + - `DB_USERNAME`: Username for accessing the MySQL database. + - `DB_PASSWORD`: Password for accessing the MySQL database. + - `DB_NAME`: Name of the MySQL database (if using sample data, use `myecommerce` as the database name) + - `DB_URL` with format `jdbc:mysql://:@:/?ssl-mode=REQUIRED` + +2. **Other Configurations:** + - `API_URL`: Base URL for the deployed backend service (Assign API url after web service deployment). + - `MAIL_USERNAME`: Email address for sending emails. + - `MAIL_PASSWORD`: Password for the email address (Use + an [app password](https://support.google.com/accounts/answer/185833?hl=en) if using Gmail). + +## Deploy Backend + +This guide will help you deploy the Linkking project backend web services to [Render](https://render.com/). + +1. **Prerequisites:** + - **Docker Desktop:** Ensure you have Docker Desktop installed on your system. + - **Docker Hub Account:** Create an account on [Docker Hub](https://hub.docker.com/) if you don't have one already. + +2. **Build JAR files:** + - Run the following command to build the JAR file: + ```bash + mvn clean -DskipTests package + ``` + - You can also run this command via IntelliJ IDEA by right-clicking on the project and + selecting `Run Maven` -> `New Goal...` -> `clean -DskipTests package`. + +3. **Build Docker Image and Deploy to Render:** + + - For proper instructions, please refer to this blog + post: [How to host a Spring Boot application for free with Render](https://hostingtutorials.dev/blog/free-spring-boot-host-with-render) (You may skip to the **Building your docker image** section). + - Example commands used from above blog post (Assume you already in `backend/` directory): + ```bash + docker build -t linkking . + docker tag linkking letiendat1002/linkking + docker login -u letiendat1002 + docker push letiendat1002/linkking:latest + ```