mirror of
https://github.com/fastapiadmin/FastapiAdmin.git
synced 2026-09-20 20:39:55 +00:00
开源准备
This commit is contained in:
@@ -0,0 +1,33 @@
|
||||
# 后端介绍
|
||||
|
||||
> 该项目是一个基于python的web服务框架,基于fastapi和sqlalchemy实现,支持多版本接口,支持swagger文档,支持redis缓存,支持mysql数据库,支持mongodb数据库,支持celery任务队列,支持jwt认证,支持日志记录,支持插件扩展,支持多环境配置,支持uvicorn部署,支持gunicorn部署,支持docker部署,支持nginx部署。
|
||||
|
||||
## 后端
|
||||
|
||||
1. 安装依赖
|
||||
|
||||
```shell
|
||||
cd backend
|
||||
pip3 install -r requirements.txt
|
||||
```
|
||||
|
||||
2. 修改项目数据库配置信息
|
||||
在`app/core/config.py`文件中的`SQLALCHEMY_DATABASE_URI`、`MONGO_DB_URL`、`REDIS_URL`
|
||||
|
||||
3. 创建名为`fastapi_vue_admin`的数据库
|
||||
|
||||
4. 初始化数据库数据
|
||||
|
||||
```shell
|
||||
# 进入后端根目录 backend 下运行
|
||||
# 运行命令后会自动生成数据库内的表和数据
|
||||
# 如已初始化数据库数据,此命令可不执行
|
||||
python3 main.py init
|
||||
```
|
||||
|
||||
5. 启动
|
||||
|
||||
```shell
|
||||
# 进入后端根目录 backend 下运行
|
||||
python3 main.py run
|
||||
```
|
||||
Executable
+210
@@ -0,0 +1,210 @@
|
||||
# 部署介绍
|
||||
|
||||
## docker
|
||||
|
||||
``` dockerfile
|
||||
# 使用官方的 Python 3.10 镜像作为基础镜像
|
||||
FROM python:3.10
|
||||
# 使用 LABEL 替代 MAINTAINER
|
||||
LABEL maintainer="管理员"
|
||||
# 设置 python 环境变量
|
||||
ENV PYTHONUNBUFFERED 1
|
||||
ENV PYTHONDONTWRITEBYTECODE 1
|
||||
# 设置时区
|
||||
ENV TZ Asia/Shanghai
|
||||
|
||||
# 升级pip版本
|
||||
# RUN python -m pip install --upgrade pip
|
||||
|
||||
# 创建容器工作目录
|
||||
RUN mkdir -p /opt/fastapi_project
|
||||
# 设置容器内工作目录
|
||||
WORKDIR /opt/fastapi_project
|
||||
# 将当前主机目录全部文件复制至容器工作目录
|
||||
COPY ./requirements.txt /code/requirements.txt
|
||||
# 安装依赖
|
||||
RUN pip install --no-cache-dir --upgrade -r /opt/fastapiproject/backend/requirements.txt -i https://pypi.tuna.tsinghua.edu.cn/simple
|
||||
|
||||
# 部署 nginx
|
||||
RUN apt-get update && apt-get install -y nginx
|
||||
RUN rm /etc/nginx/sites-enabled/default
|
||||
COPY nginx.conf /etc/nginx/sites-available/
|
||||
RUN ln -s /etc/nginx/sites-available/nginx.conf /etc/nginx/sites-enabled/
|
||||
RUN echo "daemon off;" >> /etc/nginx/nginx.conf
|
||||
|
||||
# # 部署mysql
|
||||
# RUN apt-get install -y mysql-server
|
||||
|
||||
# # 部署redis
|
||||
# RUN apt-get install -y redis-server
|
||||
|
||||
# # 部署mongo
|
||||
# RUN apt-get install -y mongodb
|
||||
|
||||
|
||||
#CMD 运行以下命令,daemon off后台运行,否则启动完就自动关闭
|
||||
CMD ["nginx", "-g", "daemon off;"]
|
||||
|
||||
CMD ["uvicorn", "app.main:app", "--host", "0.0.0.0", "--port", "80"]
|
||||
# 暴露端口
|
||||
EXPOSE 8000
|
||||
# python main.py run 或者 uvicorn main:create_app --host 0.0.0.0 --port 8000 --workers 4
|
||||
ENTRYPOINT ["uvicorn", "backend.main:create_app", "--host", "0.0.0.0", "--port", "8000", "--workers", 4]
|
||||
# ENTRYPOINT ["gunicorn", "-c", "gunicorn.py", "main:create_app"]
|
||||
|
||||
```
|
||||
|
||||
## docker-componse
|
||||
|
||||
```yaml
|
||||
version: "3.10.11"
|
||||
|
||||
# 应用服务
|
||||
services:
|
||||
# 应用服务
|
||||
fastapi_getway:
|
||||
# 容器名称
|
||||
container_name: fastapi
|
||||
# 镜像名称
|
||||
image: fastapi
|
||||
env_file: .env
|
||||
networks:
|
||||
- db_network
|
||||
- web_network
|
||||
# 构建镜像
|
||||
build:
|
||||
context: ./
|
||||
dockerfile: Dockerfile
|
||||
#build: .
|
||||
# 将容器运行在特权模式下,意味着容器内的进程将具
|
||||
# 有访问宿主机的权限,包括文件系统、设备和系统功能等
|
||||
privileged: true
|
||||
# 指定容器中运行的用户
|
||||
user: root
|
||||
# 启动策略为始终重启
|
||||
restart: always
|
||||
# 设置网络模式为host模式
|
||||
network_mode: host
|
||||
# 端口映射
|
||||
ports:
|
||||
- 8020:8020
|
||||
# 文件挂载
|
||||
volumes:
|
||||
- ./:/data/apps
|
||||
- ./uploads:/data/apps/uploads
|
||||
# 执行命令
|
||||
command: python app.py runserver 0.0.0.0:8020 --noreload
|
||||
# 日志配置
|
||||
logging:
|
||||
driver: "json-file"
|
||||
options:
|
||||
max-size: "500m"
|
||||
max-file: "10"
|
||||
# nginx服务
|
||||
nginx:
|
||||
container_name: nginx
|
||||
restart: always
|
||||
image: "nginx:latest"
|
||||
ports:
|
||||
- "5000:5000"
|
||||
volumes:
|
||||
- ./nginx:/etc/nginx/conf.d
|
||||
networks:
|
||||
- web_network
|
||||
depends_on:
|
||||
- flask_api
|
||||
|
||||
# 中间件服务
|
||||
mysql:
|
||||
container_name: mysql
|
||||
image: mysql:latest
|
||||
restart: always
|
||||
ports:
|
||||
- "3306:3306"
|
||||
# 数据卷挂载
|
||||
|
||||
networks:
|
||||
db_network:
|
||||
driver: bridge
|
||||
web_network:
|
||||
driver: bridge
|
||||
|
||||
```
|
||||
|
||||
## nginx
|
||||
|
||||
```nginx
|
||||
########### 每个指令必须有分号结束。#################
|
||||
user administrator administrators; # 配置用户或组,默认为nobody nobody
|
||||
worker_processes 2; # 允许生成的进程数,默认为1
|
||||
pid /nginx/pid/nginx.pid; # 指定 Nginx 进程运行文件存放地址
|
||||
error_log log/error.log debug; # 制定日志路径,级别。这个设置可以放入全局块、http块、server块,级别依次为:debug|info|notice|warn|error|crit|alert|emerg
|
||||
|
||||
events {
|
||||
accept_mutex on; # 设置网络连接序列化,防止惊群现象发生,默认为on
|
||||
multi_accept on; # 设置一个进程是否同时接受多个网络连接,默认为off
|
||||
use epoll; # 事件驱动模型,select|poll|kqueue|epoll|resig|/dev/poll|eventport
|
||||
worker_connections 1024; # 最大连接数,默认为512
|
||||
}
|
||||
|
||||
http {
|
||||
include mime.types; # 文件扩展名与文件类型映射表
|
||||
default_type application/octet-stream; # 默认文件类型,默认为text/plain
|
||||
|
||||
# 取消服务日志
|
||||
access_log off;
|
||||
|
||||
# 自定义日志格式
|
||||
log_format access '$remote_addr–$remote_user [$time_local] $request $status $body_bytes_sent $http_referer $http_user_agent $http_x_forwarded_for';
|
||||
|
||||
# 启用访问日志
|
||||
access_log log/access.log access; # combined为日志格式的默认值
|
||||
|
||||
sendfile on; # 允许sendfile方式传输文件,默认为off,可以在http块、server块、location块
|
||||
sendfile_max_chunk 100k; # 每个进程每次调用传输数量不能大于设定的值,默认为0,即不设上限
|
||||
keepalive_timeout 65; # 连接超时时间,默认为75秒,可以在http、server、location块
|
||||
|
||||
# 定义上游服务器
|
||||
upstream mysvr {
|
||||
server 127.0.0.1:7878;
|
||||
server 192.168.10.121:3333 backup; # 热备
|
||||
}
|
||||
|
||||
# 错误页
|
||||
error_page 404 https://www.baidu.com;
|
||||
|
||||
# 定义一个 server 块
|
||||
server {
|
||||
# 单连接请求上限次数
|
||||
keepalive_requests 120;
|
||||
|
||||
# 监听端口
|
||||
listen 4545;
|
||||
|
||||
# 监听地址
|
||||
server_name 127.0.0.1;
|
||||
|
||||
# 前端代理
|
||||
location / {
|
||||
proxy_set_header Host $host;
|
||||
root /web/front/;
|
||||
proxy_set_header X-Real-IP $remote_addr;
|
||||
proxy_set_header REMOTE-HOST $remote_addr;
|
||||
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
|
||||
try_files $uri $uri/ /index.html;
|
||||
index /index.html;
|
||||
}
|
||||
|
||||
# 后端代理
|
||||
location /api/ {
|
||||
proxy_set_header Host $host;
|
||||
proxy_set_header X-Real-IP $remote_addr;
|
||||
proxy_set_header REMOTE-HOST $remote_addr;
|
||||
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
|
||||
add_header Access-Control-Allow-Methods *;
|
||||
add_header Access-Control-Allow-Origin $http_origin;
|
||||
proxy_pass http://127.0.0.1:8010/;
|
||||
}
|
||||
}
|
||||
}
|
||||
```
|
||||
@@ -0,0 +1,44 @@
|
||||
# 前端介绍
|
||||
|
||||
这是一个基于Vue3的Vite项目,使用Vue3、Vite、TypeScript、Pinia、Vue-router、Element Plus、Axios等框架。
|
||||
|
||||
npm init vue@latest 创建项目
|
||||
cd frontend 进入项目
|
||||
npm install 安装依赖
|
||||
npm run dev 启动项目
|
||||
|
||||
## 推荐IDE设置
|
||||
|
||||
[VSCode](https://code.visualstudio.com/) + [Volar](https://marketplace.visualstudio.com/items?itemName=Vue.volar) (and disable Vetur).
|
||||
|
||||
## 项目配置
|
||||
|
||||
查看 [Vite Configuration Reference](https://vitejs.dev/config/).
|
||||
|
||||
## 项目启动
|
||||
|
||||
### 初始化依赖
|
||||
|
||||
```sh
|
||||
npm install
|
||||
```
|
||||
|
||||
### 启动开发环境
|
||||
|
||||
```sh
|
||||
npm run dev
|
||||
```
|
||||
|
||||
### 构建项目
|
||||
|
||||
```sh
|
||||
npm run build
|
||||
```
|
||||
|
||||
### 项目检查
|
||||
|
||||
```sh
|
||||
[ESLint](https://eslint.org/)
|
||||
|
||||
npm run lint
|
||||
```
|
||||
Executable
+62
@@ -0,0 +1,62 @@
|
||||
# Markdown转静态网站(mkdocs-material使用)
|
||||
|
||||
## 工具介绍
|
||||
|
||||
- 名称:mkdocs-material
|
||||
- 官网:<https://squidfunk.github.io/mkdocs-material/>
|
||||
- 完整文档信息清访问 [mkdocs官网](https://www.mkdocs.org).
|
||||
|
||||
## 工具安装
|
||||
|
||||
```sh
|
||||
pip install mkdocs-material
|
||||
```
|
||||
|
||||
## 工具使用
|
||||
|
||||
### 创建项目
|
||||
|
||||
```sh
|
||||
mkdocs new my_docs
|
||||
```
|
||||
|
||||
### 编辑构建文档
|
||||
|
||||
```yaml
|
||||
theme:
|
||||
name: material
|
||||
```
|
||||
|
||||
### 启动服务
|
||||
|
||||
```sh
|
||||
mkdocs serve
|
||||
```
|
||||
|
||||
### 构建静态站点
|
||||
|
||||
```sh
|
||||
mkdocs build
|
||||
```
|
||||
|
||||
### 获取帮助
|
||||
|
||||
```sh
|
||||
mkdocs -h
|
||||
```
|
||||
|
||||
### 生成所有依赖
|
||||
|
||||
```sh
|
||||
pip freeze > requirements.txt
|
||||
```
|
||||
|
||||
```requirements.txt
|
||||
mkdocs
|
||||
mkdocs-include-markdown-plugin
|
||||
mkdocs-material # 安装主题
|
||||
mkdocs-material-extensions
|
||||
mkdocs-pdf-export-plugin
|
||||
mkdocs-minify-plugin # 插件
|
||||
mkdocs-git-revision-date-localized-plugin
|
||||
```
|
||||
Reference in New Issue
Block a user