Skip to content

Commit

Permalink
Merge pull request #14 from 0623FifiChang/main
Browse files Browse the repository at this point in the history
Major updates
  • Loading branch information
kuanting authored Jun 11, 2024
2 parents c02f9bb + 77e649c commit 9552f76
Show file tree
Hide file tree
Showing 63 changed files with 3,566 additions and 857 deletions.
3 changes: 3 additions & 0 deletions api-server/.gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -150,3 +150,6 @@ dist
.yarn/build-state.yml
.yarn/install-state.gz
.pnp.\*

# Folder to store user pictures
/uploads
23 changes: 23 additions & 0 deletions api-server/docker_backend-deployment/.env.example
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
# .env default file

# rabbitmq_service、mysql_service是在docker-compose.yml中建立好的rabbit和Mysql服務

# """
# Parameters used to build the Docker image for the backend (2023aiotlab/api_server).
# """

# RabbitMQ connection parameters
RABBITMQ_SERVICE_SERVICE_HOST=rabbitmq_service
RABBITMQ_SERVICE_SERVICE_PORT=5672
RABBITMQ_SERVICE_USER=guest
RABBITMQ_SERVICE_PASSWORD=guest

# MySQL connection parameters
MYSQL_SERVICE_SERVICE_HOST=mysql_service
MYSQL_SERVICE_SERVICE_PORT=3306
MYSQL_SERVICE_USER=user
MYSQL_SERVICE_PASSWORD=mysql

MYSQL_ROOT_PASSWORD=password

# HOST 需使用ip或域名,不可使用localhost或127.0.0.1
Binary file removed api-server/docker_backend-deployment/.zip
Binary file not shown.
61 changes: 34 additions & 27 deletions api-server/docker_backend-deployment/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,14 @@

Whether MySQL, RabbitMQ, and the backend application are installed on the same computer or not, here we will link them together to create a complete backend.

After the backend is successfully set up, if the frontend has not been deployed yet, please refer to `aiwings/web_ui/docker_front-deployment/` for instructions on how to deploy the frontend.
If you have successfully set up the backend but the frontend has not been deployed yet, please refer to the instructions in `aiwings/web_ui/docker_front-deployment/` for deploying the frontend.

If you wish to install the backend application and the frontend application on the same computer, you can refer to `aiwings/docker-deployment/` for instructions.

## Applicable scenario
## Applicable scenario for this document

- Wish to deploy **the frontend application and backend application separately on different computers**.
- Want to have **the frontend application and the backend application on different computers separately**.
- This document will provide relevant instructions for backend deployment, including the installation of RabbitMQ and MySQL required for the backend.
- Regardless of whether RabbitMQ and MySQL are already installed, you can follow the instructions below for the operation.
- For frontend application installation, please refer to `aiwings/web_ui/docker_front-deployment/`.

Expand All @@ -20,21 +21,22 @@ If you wish to install the backend application and the frontend application on t

- If you haven't and wish to install RabbitMQ or MySQL on the same computer as the backend application:

- If you haven't installed RabbitMQ yet, please make sure that the ports `15672` and `5672` are not in use if possible.
- If you haven't installed MySQL yet, please make sure that the ports `3306` are not in use if possible.
- If RabbitMQ is not yet installed, please ensure that ports `15672` and `5672` are not occupied by other applications, as the RabbitMQ container will use these ports as the default ports.

## Document explanation
- If MySQL is not yet installed, please ensure that port `3306` is not occupied by other applications, as the MySQL container will use port 3306 as the default port.

Unzipping the `.zip` file will give you the default `.env` file.
## Document explanation

![image](https://i.imgur.com/m6MOZQe.png)
Before embarking on the Docker containerized deployment of the aiwings application, you need to configure two crucial files according to your requirements: the `.env file` and the `docker-compose.yml file.` These two files play vital roles throughout the entire deployment process.

### `.env` file

`RabbitMQ and MySQL connection parameters.`
- Rename the `.env.example` file to `.env`.

- The .env file contains environment variable settings used to configure the aiwings backend application. By modifying these parameter values, users can customize `the backend's connection settings with RabbitMQ and MySQL`.

```python
# rabbitmq_service and mysql_service are service names created in the docker-compose.yml file.
# .env backend default file

# RabbitMQ connection parameters
RABBITMQ_SERVICE_SERVICE_HOST=rabbitmq_service
Expand All @@ -47,50 +49,55 @@ MYSQL_SERVICE_SERVICE_HOST=mysql_service
MYSQL_SERVICE_SERVICE_PORT=3306
MYSQL_SERVICE_USER=user
MYSQL_SERVICE_PASSWORD=mysql
```

**If you haven't installed RabbitMQ or MySQL yet:**
- You can set the usernames and passwords for your new MySQL and RabbitMQ here.
MYSQL_ROOT_PASSWORD=password
```

Note: If you want using docker-compose.yml to install MySQL, the value of MYSQL_SERVICE_USER don't set as 'root'.
#### If not Yet Installed RabbitMQ or MySQL:
- If RabbitMQ or MySQL is not yet installed, you can set the usernames and passwords for the newly created MySQL and RabbitMQ here.

- Default usernames and passwords:
- RabbitMQ: guest/guest
- MySQL: user/mysql
- MYSQL_ROOT: root/password

**If you already install RabbitMQ:**
#### If you already install RabbitMQ:
- Change the value of `RABBITMQ_SERVICE_SERVICE_HOST` to your RabbitMQ server IP. (The IP don't use 127.0.0.1 or localhost)
- If your RabbitMQ server backend not using default port '5672', Change the value of `RABBITMQ_SERVICE_SERVICE_PORT` to your RabbitMQ server port.
- If the backend of your created RabbitMQ server not using default port '5672', Change the value of `RABBITMQ_SERVICE_SERVICE_PORT` to your RabbitMQ backend server port.
- In the docker-compose.yml file, comment out the relevant settings.

**If you already install MySQL:**
#### If you already install MySQL:
- Change the value of `MYSQL_SERVICE_SERVICE_HOST` to your MySQL server IP. (The IP don't use 127.0.0.1 or localhost)
- If your MySQL server not using default port '3306', Change the value of `MYSQL_SERVICE_SERVICE_PORT` to your MySQL server port.
- Because not using the provided docker-compose.yml to create MySQL, you can use 'root' user to connect your MySQL.
- If your created MySQL server not using default port '3306', Change the value of `MYSQL_SERVICE_SERVICE_PORT` to your MySQL server port.
- Because not using the provided docker-compose.yml to create MySQL, you can also change `MYSQL_SERVICE_USER` and `MYSQL_SERVICE_PASSWORD` to 'root' user and its password to connect your MySQL.
- In the docker-compose.yml file, comment out the relevant settings.

### `docker-compose.yml` file

**If you haven't installed RabbitMQ or MySQL yet:**
- It can be used directly without changing anything.
- You can change your MySQL 'root' user's password if you want.
- Default 'root' password: **MYSQL_ROOT_PASSWORD=password**
- The docker-compose.yml file defines the containerized deployment configuration for the aiwings application. Through this file, you can quickly accomplish the deployment of aiwings.

#### If not Yet Installed RabbitMQ or MySQL:
- It can be used directly without changing anything.

**If you already install MySQL:**
#### If you already install MySQL:
- Comment out or delete the entire mysql_service in docker-compose.yml.【line 41~56】
- Comment out or delete the **mysql_service option** in the depends_on of the backend.【Line 66】
- And change the MySQL connection parameters in the .env file.

**If you already install RabbitMQ:**
#### If you already install RabbitMQ:
- Comment out or delete the entire rabbitmq_service in docker-compose.yml.【line 28~39】
- Comment out or delete the **rabbitmq_service option** in the depends_on of the backend.【Line 65】
- And change the MySQL connection parameters in the .env file.

## How to install

### **Installation Method 1: using docker-compose.yml**

1. Open Command Prompt

2. cd to `docker_backend-deployment/` folder
2. cd to `api-server/docker_backend-deployment/` folder

3. Run docker-compose.yml in the background with the following command. Then you can see three container in your docker desktop.
3. Run docker-compose.yml in the background with the following command. Then you can see these containers in your docker desktop.

```
docker-compose up -d
Expand Down
31 changes: 21 additions & 10 deletions api-server/docker_backend-deployment/docker-compose.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,8 @@ services:
- '5672:5672'
- '15672:15672'
environment:
- RABBITMQ_DEFAULT_USER=${RABBITMQ_SERVICE_USER}
- RABBITMQ_DEFAULT_PASS=${RABBITMQ_SERVICE_PASSWORD}
RABBITMQ_DEFAULT_USER: ${RABBITMQ_SERVICE_USER}
RABBITMQ_DEFAULT_PASS: ${RABBITMQ_SERVICE_PASSWORD}
# 若未設定,預設使用者名稱和密碼為guest/ guest
# ${RABBITMQ_SERVICE_USER}來自環境變數.env檔案內容

Expand All @@ -48,7 +48,7 @@ services:
ports:
- '3306:3306'
environment:
MYSQL_ROOT_PASSWORD: password # root password 可自行設定
MYSQL_ROOT_PASSWORD: ${MYSQL_ROOT_PASSWORD} # root password 可自行設定
MYSQL_DATABASE: drone_cloud_test
MYSQL_USER: ${MYSQL_SERVICE_USER}
MYSQL_PASSWORD: ${MYSQL_SERVICE_PASSWORD}
Expand All @@ -64,18 +64,29 @@ services:
depends_on:
- rabbitmq_service
- mysql_service
# rabbitmq_service、mysql_service是前面建立好的服務
ports:
- '3080:3080'
environment:
- RABBITMQ_SERVICE_SERVICE_HOST=${RABBITMQ_SERVICE_SERVICE_HOST}
- MYSQL_SERVICE_SERVICE_HOST=${MYSQL_SERVICE_SERVICE_HOST}
# rabbitmq_service、mysql_service是前面建立好的服務
# environment的優先權大於env_file
env_file:
- ./.env
# RabbitMQ connection parameters
RABBITMQ_SERVICE_SERVICE_HOST: ${RABBITMQ_SERVICE_SERVICE_HOST}
RABBITMQ_SERVICE_SERVICE_PORT: ${RABBITMQ_SERVICE_SERVICE_PORT}
RABBITMQ_SERVICE_USER: ${RABBITMQ_SERVICE_USER}
RABBITMQ_SERVICE_PASSWORD: ${RABBITMQ_SERVICE_PASSWORD}
# MySQL connection parameters
MYSQL_SERVICE_SERVICE_HOST: ${MYSQL_SERVICE_SERVICE_HOST}
MYSQL_SERVICE_SERVICE_PORT: ${MYSQL_SERVICE_SERVICE_PORT}
MYSQL_SERVICE_USER: ${MYSQL_SERVICE_USER}
MYSQL_SERVICE_PASSWORD: ${MYSQL_SERVICE_PASSWORD}
# environment的優先權大於env_file
# env_file:
# - ./.env
# 透過environment或env_file加入系統環境變數的話,就要到容器中修改系統環境變數,用掛載的話則是容易更改【思考後覺得不必要】
# 其他容器服務名稱好像要透過系統環境變數,才可被解析成區域IP
# volumes:
# - ./.env.docker:/app/.env
# - ./src:/app/src


# -d|detach:在後台運行。此為docker run 命令,屬容器級別
# docker-compose.yml檔案 屬於服務級別
# 若要在後台運行,在docker-compose up 後面加上 -d
Loading

0 comments on commit 9552f76

Please sign in to comment.