Repository: tyvekzhang/fastapi-sqlmodel-starter (language: python)

Issue:
docker部署



Discussion / hints:

Fix patch:
diff --git a/fss/.env.example b/.env.example
similarity index 93%
rename from fss/.env.example
rename to .env.example
index b345d4d..2da7e73 100644
--- a/fss/.env.example
+++ b/.env.example
@@ -12,7 +12,7 @@ LINUX_TZ=Asia/Shanghai
 
 # Database
 #SQLALCHEMY_DATABASE_URL=driver://user:pass@localhost:port/dbname
-SQLALCHEMY_DATABASE_URL=sqlite+aiosqlite:///./fss.db
+SQLALCHEMY_DATABASE_URL=sqlite+aiosqlite:///migrations/db/fss.db
 #SQLALCHEMY_DATABASE_URL=postgresql+asyncpg://user:pass@localhost:port/dbname
 #SQLALCHEMY_DATABASE_URL=mysql+aiomysql://user:pass@localhost:port/dbname
 
diff --git a/.github/workflows/ci.yaml b/.github/workflows/ci.yaml
index 3078c7e..591eb39 100644
--- a/.github/workflows/ci.yaml
+++ b/.github/workflows/ci.yaml
@@ -54,5 +54,5 @@ jobs:
           python -m pip install pytest httpx
       - name: Test with pytest
         run: |
-          cd tests
+          alembic upgrade head
           pytest
diff --git a/.gitignore b/.gitignore
index b1c4bcf..9d09010 100644
--- a/.gitignore
+++ b/.gitignore
@@ -3,5 +3,5 @@
 *.lock
 .tox/
 .ruff_cache/
-/fss/fss.db
 .*/
+*.db
diff --git a/Dockerfile b/Dockerfile
new file mode 100644
index 0000000..6018a9e
--- /dev/null
+++ b/Dockerfile
@@ -0,0 +1,25 @@
+FROM tiangolo/uvicorn-gunicorn-fastapi:python3.11-slim
+ENV PYTHONUNBUFFERED=1
+ENV PIP_DEFAULT_TIMEOUT=100
+WORKDIR /app
+
+RUN apt clean && apt update && apt install curl -y
+RUN curl -sSL https://install.python-poetry.org | POETRY_HOME=/opt/poetry python && \
+    cd /usr/local/bin && \
+    ln -s /opt/poetry/bin/poetry && \
+    poetry config virtualenvs.create false
+
+COPY ./pyproject.toml ./poetry.lock* /app/
+
+ARG INSTALL_DEV=false
+RUN bash -c "if [ $INSTALL_DEV == 'true' ] ; then poetry install --no-root ; else poetry install --no-root --only main ; fi"
+
+ENV PYTHONPATH=/app
+
+COPY ./alembic.ini /app/
+COPY ./README.md /app/
+COPY ./migrations /app/migrations
+COPY ./fss /app/fss
+COPY ./tests /app/tests
+
+EXPOSE 9010
diff --git a/README.md b/README.md
index ca601ce..fc65d06 100644
--- a/README.md
+++ b/README.md
@@ -5,7 +5,7 @@ Fss旨在成为PyWeb中对用户最友好的脚手架工具之一。
 ##### Translate to: [English](docs/README_en.md)
 ## 特性
 
-- 开箱即用, 内置常见数据库缓存(Sqlite, PostgreSQL, MySQL, 文件缓存, Redis)
+- 开箱即用, 内置常见数据库、缓存(Sqlite[默认], PostgreSQL, MySQL, 文件缓存[默认], Redis)
 - 自带单表的几乎所有操作
 - 数据库迁移, 静态代码扫描, 接口文档等一众特性
 
@@ -25,7 +25,7 @@ python3 -m venv .env_fss
     - macOS 或 Linux: source .env_fss/bin/activate
 5. 安装 Poetry并下载依赖
 ```shell
-pip install poetry -i https://pypi.tuna.tsinghua.edu.cn/simple
+pip install poetry --trusted-host=mirrors.tuna.tsinghua.edu.cn --index-url=https://mirrors.tuna.tsinghua.edu.cn/pypi/web/simple
 poetry install
 ```
 6. 数据库迁移
diff --git a/alembic.ini b/alembic.ini
index 70e071e..6afa687 100644
--- a/alembic.ini
+++ b/alembic.ini
@@ -61,7 +61,7 @@ version_path_separator = os  # Use os.pathsep. Default configuration used for ne
 # output_encoding = utf-8
 
 ;sqlalchemy.url = driver://user:pass@localhost:port/dbname
-sqlalchemy.url = sqlite+aiosqlite:///./fss/fss.db
+sqlalchemy.url = sqlite+aiosqlite:///migrations/db/fss.db
 ;sqlalchemy.url = postgresql+asyncpg://user:pass@localhost:port/dbname
 ;sqlalchemy.url = mysql+aiomysql://user:pass@localhost:port/dbname
 
diff --git a/docker-compose.yml b/docker-compose.yml
new file mode 100644
index 0000000..42c766b
--- /dev/null
+++ b/docker-compose.yml
@@ -0,0 +1,10 @@
+version: '3.8'
+
+services:
+  fss_server:
+    container_name: fss_server
+    image: tyvek2zhang/fastapi-sqlmodel-starter:v1.0.0
+    restart: always
+    command: "sh -c 'alembic upgrade head && python fss/apiserver.py'"
+    ports:
+      - 9010:9010
diff --git a/docs/README_en.md b/docs/README_en.md
index 5fd0b02..8ec5dca 100644
--- a/docs/README_en.md
+++ b/docs/README_en.md
@@ -5,7 +5,7 @@ Fss aims to be one of the most user-friendly scaffolding tools for PyWeb.
 ##### 翻译成: [简体中文](../README.md)
 ## Features
 
-- Out-of-the-box, built-in support for common database caching (Sqlite, PostgreSQL, MySQL, file cache, Redis)
+- Out-of-the-box, built-in support for common database caching (Sqlite[default], PostgreSQL, MySQL, file cache[default], Redis)
 - Built-in operations for nearly all single-table actions
 - Features such as database migration, static code analysis, API documentation, and more
 
diff --git a/docs/source/usage.rst b/docs/source/usage.rst
index 11a0773..bd046f2 100644
--- a/docs/source/usage.rst
+++ b/docs/source/usage.rst
@@ -24,7 +24,7 @@ Quick Start
 
 5. Install Poetry and download dependencies::
 
-    pip install poetry -i https://pypi.tuna.tsinghua.edu.cn/simple
+    pip install poetry
     poetry install
 
 6. Database migration::
diff --git a/fss/common/config.py b/fss/common/config.py
index bbd7600..5144d91 100644
--- a/fss/common/config.py
+++ b/fss/common/config.py
@@ -10,7 +10,7 @@
 from pydantic.v1 import BaseSettings
 
 current_file_path = os.path.abspath(__file__)
-env_directory = path(current_file_path).parent.parent
+env_directory = path(current_file_path).parent.parent.parent
 
 
 ENV_FILE = os.path.join(env_directory, ".env")
diff --git a/fss/common/persistence/sqlmodel_impl.py b/fss/common/persistence/sqlmodel_impl.py
index e6c32c8..673839b 100644
--- a/fss/common/persistence/sqlmodel_impl.py
+++ b/fss/common/persistence/sqlmodel_impl.py
@@ -47,7 +47,7 @@ async def insert_batch(
             else data
             for data in data_list
         ]
-        statement = insert(self.model).values([data.dict() for data in orm_datas])
+        statement = insert(self.model).values([data.model_dump() for data in orm_datas])
         await db_session.execute(statement)
         return len(data_list)
 
diff --git a/fss/starter/__init__.py b/fss/starter/__init__.py
index a1c351b..6ddcb5b 100644
--- a/fss/starter/__init__.py
+++ b/fss/starter/__init__.py
@@ -5,5 +5,7 @@
 from pathlib import Path
 
 current_dir = os.path.dirname(os.path.abspath(__file__))
+fss_dir = str(Path(current_dir).parent)
 project_dir = str(Path(current_dir).parent.parent)
-sys.path.insert(0, project_dir)
+sys.path.insert(0, fss_dir)
+sys.path.insert(1, project_dir)
diff --git a/fss/starter/system/service/impl/user_service_impl.py b/fss/starter/system/service/impl/user_service_impl.py
index 62ea0ec..4d69778 100644
--- a/fss/starter/system/service/impl/user_service_impl.py
+++ b/fss/starter/system/service/impl/user_service_impl.py
@@ -30,7 +30,7 @@ async def find_by_id(self, id: int) -> Optional[UserQuery]:
         """
         user_do = await self.mapper.select_by_id(id=id)
         if user_do:
-            return UserQuery(**user_do.dict())
+            return UserQuery(**user_do.model_dump())
         else:
             return None
 
diff --git a/migrations/db/README b/migrations/db/README
new file mode 100644
index 0000000..334ad32
--- /dev/null
+++ b/migrations/db/README
@@ -0,0 +1,1 @@
+Use for sqlite


Test patch:
diff --git a/tests/fss.db b/tests/fss.db
deleted file mode 100644
index 22614b3..0000000
Binary files a/tests/fss.db and /dev/null differ
diff --git a/tests/system/v1/test_user.py b/tests/system/v1/test_user.py
index 5f2534e..756ba3a 100644
--- a/tests/system/v1/test_user.py
+++ b/tests/system/v1/test_user.py
@@ -1,5 +1,3 @@
-import random
-
 from fastapi.testclient import TestClient
 
 from fss.common.config import configs
@@ -9,9 +7,8 @@
 
 
 def test_user_register():
-    random_num = random.randint(0, 1000)
     user_data = {
-        "username": f"example_user_{random_num}",
+        "username": "example_user",
         "password": "example_password",
         "nickname": "Example Nickname",
     }