liuyuqi-dellpc 1 year ago
parent
commit
738e44e4b5
9 changed files with 193 additions and 33 deletions
  1. 5 31
      .pre-commit-config.yaml
  2. 23 0
      README.md
  3. 4 0
      backend/Dockerfile
  4. 1 1
      backend/main.py
  5. 2 1
      deploy/nginx/default.conf
  6. 5 0
      deploy/nginx/nginx.conf
  7. 27 0
      docs/Deploy.md
  8. 120 0
      docs/mkdocs.yml
  9. 6 0
      frontend/Dockerfile

+ 5 - 31
.pre-commit-config.yaml

@@ -1,38 +1,12 @@
-# See https://pre-commit.com for more information
-# See https://pre-commit.com/hooks.html for more hooks
 repos:
-  - repo: https://github.com/pre-commit/pre-commit-hooks
-    rev: v4.4.0
-    hooks:
-      - id: check-added-large-files
-      - id: check-toml
-      - id: check-yaml
-        args:
-          - --unsafe
-      - id: end-of-file-fixer
-      - id: trailing-whitespace
   - repo: https://github.com/charliermarsh/ruff-pre-commit
-    rev: v0.2.2
+    # Ruff version.
+    rev: 'v0.0.280'
     hooks:
       - id: ruff
-        args:
-          - --fix
-      - id: ruff-format
-  - repo: https://github.com/biomejs/pre-commit
-    rev: v0.1.0
-    hooks:
-      - id: biome-check
-        additional_dependencies: ["@biomejs/biome@1.4.1"]
+        args: [ --fix, --exit-non-zero-on-fix ]
 
   - repo: https://github.com/psf/black
-    rev: 21.12b0
-    hooks:
-        - id: black
-
-  - repo: https://github.com/PyCQA/isort
-    rev: 5.13.2
+    rev: 23.1.0
     hooks:
-        - id: isort
-ci:
-  autofix_commit_msg: 🎨 [pre-commit.ci] Auto format from pre-commit.com hooks
-  autoupdate_commit_msg: ⬆ [pre-commit.ci] pre-commit autoupdate
+      - id: black

+ 23 - 0
README.md

@@ -4,8 +4,31 @@ fastapi
 
 sqlmodel, postgreSQL, React, Chakra UI for the frontend, Traefik as a reverse proxy with HTTPS, and Let's Encrypt for free SSL.
 
+## Develop
+
+```
+docker build --no-cache . -t vue-fastapi-admin
+
+docker compose -f docker-compose.yml up -d
+
+```
+
+访问: http://localhost:8080
+
+username: admin password: 123456
+
+
+
 
 ## Reference
 
 * [tiangolo/full-stack-fastapi-template](https://github.com/tiangolo/full-stack-fastapi-template)
 * [99sbr/fastapi-template](https://github.dev/99sbr/fastapi-template)
+
+* []()
+* []()
+* []()
+* []()
+* []()
+* []()
+

+ 4 - 0
backend/Dockerfile

@@ -1,6 +1,10 @@
 FROM tiangolo/uvicorn-gunicorn-fastapi:python3.10
 
 WORKDIR /app/
+
+RUN sed -i s@/deb.debian.org/@/mirrors.aliyun.com/@g /etc/apt/sources.list.d/debian.sources \
+    && sed -i s@/security.debian.org/@/mirrors.aliyun.com/@g /etc/apt/sources.list.d/debian.sources
+
 RUN curl -sSL https://install.python-poetry.org | POETRY_HOME=/opt/poetry python && \
     cd /usr/local/bin && \
     ln -s /opt/poetry/bin/poetry && \

+ 1 - 1
backend/main.py

@@ -9,4 +9,4 @@
 from app import app
 if __name__ == "__main__":
     import uvicorn
-    uvicorn.run(app, host="0.0.0.0", port=8080, reload=True, workers=1)
+    uvicorn.run(app, host="0.0.0.0", port=8080, reload=True, workers=1, log_config="uvicorn_loggin_config.json")

+ 2 - 1
deploy/nginx/default.conf

@@ -19,7 +19,8 @@ server {
     # try_files $uri /index.html =404;
   }
 
-  location /api {
+   location ^~ /api/ {
+#  location /api {
     proxy_pass http://backend:8888/api;
   }
 

+ 5 - 0
deploy/nginx/nginx.conf

@@ -1,5 +1,6 @@
 server {
   listen 80;
+  server_name localhost;
 
   location / {
     root /usr/share/nginx/html;
@@ -7,5 +8,9 @@ server {
     try_files $uri /index.html =404;
   }
 
+  location ^~ /api/ {
+          proxy_pass http://127.0.0.1:9999;
+  }
+
   include /etc/nginx/extra-conf.d/*.conf;
 }

+ 27 - 0
docs/Deploy.md

@@ -0,0 +1,27 @@
+# Deploy
+
+
+部署的方法很多
+
+## 前后端分别运行
+
+开发模式下可以这样做
+
+## nginx + 前后分离
+
+前端静态打包dist,nginx指定root目录即可,对于/api 请求,反向代理转发到 proxy_pass http://127.0.0.1:9999;
+
+## 前端打包dist,放到后端static目录
+
+前后端合并,适合打包成二进制交付部署
+
+## docker 部署
+
+基于 nginx + 前后分离 模式,后端打包 jiamboy/fastapi 镜像,镜像中安装 nginx,多阶段构建镜像,把前端dist复制到后端镜像。启动命令:先启动nginx(后台自动运行),然后启动python app.py
+
+## docker-compose 部署
+
+前端 + nginx启动一个容器,后端 python.py 启动一个容器,数据库,redis等分别启动一个容器。
+
+
+

+ 120 - 0
docs/mkdocs.yml

@@ -0,0 +1,120 @@
+site_url: https://docs.amis.work/
+site_name: FastAPI-Amis-Admin
+site_description: fastapi-amis-admin是一个拥有高性能,高效率,易拓展的fastapi管理后台框架.启发自Django-Admin,并且拥有不逊色于Django-Admin的强大功能.
+repo_url: https://github.com/amisadmin/fastapi_amis_admin
+edit_uri: edit/master/docs/zh/docs/
+theme:
+  name: material
+  palette:
+    scheme: default
+  features:
+    - navigation.instant
+    - navigation.tracking
+    - navigation.tabs
+    - content.code.annotate
+markdown_extensions:
+  - toc:
+      permalink: true
+  - markdown.extensions.codehilite:
+      guess_lang: false
+  - admonition
+  - codehilite
+  - extra
+  - pymdownx.superfences:
+      custom_fences:
+        - name: mermaid
+          class: mermaid
+          format: !!python/name:pymdownx.superfences.fence_div_format
+
+  - pymdownx.tabbed:
+      alternate_style: true
+  - admonition
+  - codehilite:
+      guess_lang: false
+      linenums: false
+  - footnotes
+  - meta
+  - def_list
+  - pymdownx.arithmatex
+  - pymdownx.betterem:
+      smart_enable: all
+  - pymdownx.caret
+  - pymdownx.critic
+  - pymdownx.details
+  - pymdownx.emoji:
+      emoji_generator: !!python/name:pymdownx.emoji.to_png
+  - pymdownx.inlinehilite
+  - pymdownx.magiclink
+  - pymdownx.mark
+  - pymdownx.smartsymbols
+  - pymdownx.superfences
+  - pymdownx.snippets
+  - pymdownx.tasklist
+  - pymdownx.tilde
+
+extra_javascript:
+  - https://cdn.jsdelivr.net/npm/mermaid@9.4.3/dist/mermaid.min.js
+  - https://hm.baidu.com/hm.js?0b1b8a60b3a22ae45d1f04245f409fe2
+  - js/chat.js
+  - js/sidecar-1.5.0.js
+
+extra:
+  alternate:
+    - name: English
+      link: /
+      lang: en
+    - name: 简体中文
+      link: /zh/
+      lang: zh
+
+nav:
+  - Tutorials:
+      - index.md
+      - tutorials/quickstart.md
+      - 基础教程:
+          - tutorials/basic/PageAdmin.md
+          - tutorials/basic/FormAdmin.md
+          - tutorials/basic/TemplateAdmin.md
+          - tutorials/basic/ModelAdmin.md
+          - tutorials/basic/ModelAction.md
+          - tutorials/basic/Settings.md
+          - tutorials/basic/Inheritance.md
+          - tutorials/basic/i18n.md
+          - tutorials/basic/_more.md
+      - 高级教程:
+          - tutorials/advanced/cli.md
+          - tutorials/advanced/permission.md
+          - tutorials/advanced/user-auth.md
+          - tutorials/advanced/scheduler.md
+          - tutorials/advanced/AdminApp.md
+          - tutorials/advanced/structure.md
+          - tutorials/advanced/debug.md
+          - tutorials/advanced/_more.md
+      - 拓展教程:
+          - extended/about.md
+          - extended/SQLModel.md
+          - extended/alembic.md
+      - about.md
+
+  - API Reference:
+      - Amis:
+          - amis/types.md
+      - Crud:
+          - crud/RouterMixin.md
+          - crud/BaseCrud.md
+          - crud/SQLModelCrud.md
+      - Admin:
+          - amis_admin/BaseAdmin.md
+          - amis_admin/RouterAdmin.md
+          - amis_admin/PageSchemaAdmin.md
+          - amis_admin/PageAdmin.md
+          - amis_admin/TemplateAdmin.md
+          - amis_admin/FormAdmin.md
+          - amis_admin/ModelAdmin.md
+          - amis_admin/ModelAction.md
+          - amis_admin/AdminGroup.md
+          - amis_admin/AdminApp.md
+          - amis_admin/AdminSite.md
+          - amis_admin/Settings.md
+      - Utils:
+          - utils/database.md

+ 6 - 0
frontend/Dockerfile

@@ -1,6 +1,12 @@
 FROM node:20 as build-stage
+
 WORKDIR /app
 COPY package*.json /app/
+
+RUN sed -i 's/dl-cdn.alpinelinux.org/mirrors.tuna.tsinghua.edu.cn/g' /etc/apk/repositories \
+    && cd /opt/vue-fastapi-admin/web && npm i -g pnpm --registry=https://registry.npmmirror.com \
+    && pnpm i && pnpm run build
+
 RUN npm install
 COPY ./ /app/
 ARG VITE_API_URL=${VITE_API_URL}