diff --git a/.cloudbase/container/debug.json b/.cloudbase/container/debug.json new file mode 100644 index 0000000..6d493b8 --- /dev/null +++ b/.cloudbase/container/debug.json @@ -0,0 +1,12 @@ +{ + "containers": [ + { + "name": "fastapiweb", + "domain": "", + "ip": "", + "mode": "compose", + "containerId": "2eff8c8bd0d2909a8b806e8c12acc9fa0362494c45ea739b23c9c66cf59312b0" + } + ], + "config": {} +} \ No newline at end of file diff --git a/Dockerfile b/Dockerfile index 1f2230c..846a554 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,5 +1,5 @@ # 1、从官方 Python 基础镜像开始 -FROM python:3.9 +FROM python:3.10 # 2、将当前工作目录设置为 /code # 这是放置 requirements.txt 文件和应用程序目录的地方 @@ -13,7 +13,7 @@ COPY ./requirements.txt /code/requirements.txt RUN pip install --no-cache-dir --upgrade -r /code/requirements.txt # 5、复制 FastAPI 项目代码 -COPY ./app /code/app +COPY ./cloudcontainers/app /code/app # 6、运行服务 -CMD ["uvicorn", "app.main:app", "--host", "0.0.0.0", "--port", "80"] \ No newline at end of file +CMD ["uvicorn", "cloudcontainers.app.main:app", "--host", "0.0.0.0", "--port", "80"] \ No newline at end of file diff --git a/Dockerfile.development b/Dockerfile.development new file mode 100644 index 0000000..b4ec85d --- /dev/null +++ b/Dockerfile.development @@ -0,0 +1,10 @@ +# Auto-generated by weixin cloudbase vscode extension +FROM ccr.ccs.tencentyun.com/weixincloud/wxcloud-livecoding-toolkit:latest AS toolkit +FROM python:3.10 +COPY --from=toolkit nodemon /usr/bin/nodemon +WORKDIR /code +COPY ./requirements.txt /code/requirements.txt +RUN pip install --no-cache-dir --upgrade -r /code/requirements.txt +COPY ./cloudcontainers/app /code/app + +CMD [ "nodemon", "-x", "uvicorn cloudcontainers.app.main:app --host 0.0.0.0 --port 80", "-w", "/code", "-e", "java, js, mjs, json, ts, cs, py, go" ] \ No newline at end of file diff --git a/__pycache__/main.cpython-310.pyc b/__pycache__/main.cpython-310.pyc deleted file mode 100644 index 5ea4f34..0000000 Binary files a/__pycache__/main.cpython-310.pyc and /dev/null differ diff --git a/app/__pycache__/crud.cpython-310.pyc b/app/__pycache__/crud.cpython-310.pyc deleted file mode 100644 index a20b862..0000000 Binary files a/app/__pycache__/crud.cpython-310.pyc and /dev/null differ diff --git a/app/__pycache__/database.cpython-310.pyc b/app/__pycache__/database.cpython-310.pyc deleted file mode 100644 index 4ea3261..0000000 Binary files a/app/__pycache__/database.cpython-310.pyc and /dev/null differ diff --git a/app/__pycache__/main.cpython-310.pyc b/app/__pycache__/main.cpython-310.pyc deleted file mode 100644 index afb3bcf..0000000 Binary files a/app/__pycache__/main.cpython-310.pyc and /dev/null differ diff --git a/app/__pycache__/models.cpython-310.pyc b/app/__pycache__/models.cpython-310.pyc deleted file mode 100644 index a3d9b7a..0000000 Binary files a/app/__pycache__/models.cpython-310.pyc and /dev/null differ diff --git a/app/database.py b/app/database.py deleted file mode 100644 index 45a8b9f..0000000 --- a/app/database.py +++ /dev/null @@ -1,13 +0,0 @@ -from sqlalchemy import create_engine -from sqlalchemy.ext.declarative import declarative_base -from sqlalchemy.orm import sessionmaker - -SQLALCHEMY_DATABASE_URL = "sqlite:///./sql_app.db" -# SQLALCHEMY_DATABASE_URL = "postgresql://user:password@postgresserver/db" - -engine = create_engine( - SQLALCHEMY_DATABASE_URL, connect_args={"check_same_thread": False} -) -SessionLocal = sessionmaker(autocommit=False, autoflush=False, bind=engine) - -Base = declarative_base() diff --git a/__init__.py b/cloudcontainers/__init__.py similarity index 100% rename from __init__.py rename to cloudcontainers/__init__.py diff --git a/cloudcontainers/__pycache__/__init__.cpython-310.pyc b/cloudcontainers/__pycache__/__init__.cpython-310.pyc new file mode 100644 index 0000000..ba77ae6 Binary files /dev/null and b/cloudcontainers/__pycache__/__init__.cpython-310.pyc differ diff --git a/app/__init__.py b/cloudcontainers/app/__init__.py similarity index 100% rename from app/__init__.py rename to cloudcontainers/app/__init__.py diff --git a/cloudcontainers/app/__pycache__/crud.cpython-310.pyc b/cloudcontainers/app/__pycache__/crud.cpython-310.pyc new file mode 100644 index 0000000..8a988b1 Binary files /dev/null and b/cloudcontainers/app/__pycache__/crud.cpython-310.pyc differ diff --git a/cloudcontainers/app/__pycache__/database.cpython-310.pyc b/cloudcontainers/app/__pycache__/database.cpython-310.pyc new file mode 100644 index 0000000..c3eff1f Binary files /dev/null and b/cloudcontainers/app/__pycache__/database.cpython-310.pyc differ diff --git a/cloudcontainers/app/__pycache__/main.cpython-310.pyc b/cloudcontainers/app/__pycache__/main.cpython-310.pyc new file mode 100644 index 0000000..13ab4db Binary files /dev/null and b/cloudcontainers/app/__pycache__/main.cpython-310.pyc differ diff --git a/cloudcontainers/app/__pycache__/models.cpython-310.pyc b/cloudcontainers/app/__pycache__/models.cpython-310.pyc new file mode 100644 index 0000000..9b5cea1 Binary files /dev/null and b/cloudcontainers/app/__pycache__/models.cpython-310.pyc differ diff --git a/app/__pycache__/schemas.cpython-310.pyc b/cloudcontainers/app/__pycache__/schemas.cpython-310.pyc similarity index 100% rename from app/__pycache__/schemas.cpython-310.pyc rename to cloudcontainers/app/__pycache__/schemas.cpython-310.pyc diff --git a/app/crud.py b/cloudcontainers/app/crud.py similarity index 98% rename from app/crud.py rename to cloudcontainers/app/crud.py index dd5b280..14b49bb 100644 --- a/app/crud.py +++ b/cloudcontainers/app/crud.py @@ -2,7 +2,7 @@ from sqlalchemy.orm import Session from sqlalchemy import select -import models, schemas +from . import models, schemas # 删除 diff --git a/cloudcontainers/app/database.py b/cloudcontainers/app/database.py new file mode 100644 index 0000000..ca4b3a5 --- /dev/null +++ b/cloudcontainers/app/database.py @@ -0,0 +1,15 @@ +from sqlalchemy import create_engine +from sqlalchemy.ext.declarative import declarative_base +from sqlalchemy.orm import sessionmaker +import pymysql + +# SQLALCHEMY_DATABASE_URL = "sqlite:///./sql_app.db" +# 从docker访问ip需要 mysql服务端允许外部访问=> 参考地址:https://blog.csdn.net/weixin_42599091/article/details/125224850 +SQLALCHEMY_DATABASE_URL = "mysql+pymysql://root:Xiao4669805@192.168.31.245:3306/test" + +# SQLALCHEMY_DATABASE_URL, connect_args={"check_same_thread": False} #sqlite + +engine = create_engine(SQLALCHEMY_DATABASE_URL) +SessionLocal = sessionmaker(autocommit=False, autoflush=False, bind=engine) + +Base = declarative_base() diff --git a/app/main.py b/cloudcontainers/app/main.py similarity index 82% rename from app/main.py rename to cloudcontainers/app/main.py index c0d002c..4c7e633 100644 --- a/app/main.py +++ b/cloudcontainers/app/main.py @@ -7,8 +7,8 @@ from pydantic import BaseModel from sqlalchemy.orm import Session -import crud, models, schemas -from database import SessionLocal, engine +from . import crud, models, schemas +from .database import SessionLocal, engine models.Base.metadata.create_all(bind=engine) @@ -73,6 +73,18 @@ async def root(): print('e') return {"message": "触发飞书webhook"} +# 飞书通知 +@app.post("/nihao") +async def root(): + headers = {'Content-Type': 'application/json'} + # https://open.feishu.cn/open-apis/bot/v2/hook/5fb1b44c-3446-42ef-9b3a-dd37731567dd + try: + r = requests.post('https://open.feishu.cn/open-apis/bot/v2/hook/5fb1b44c-3446-42ef-9b3a-dd37731567dd', + data=json.dumps({'msg_type': 'text', "content": {"text": "cityNew有新用户注册"}}), headers=headers) + except(e): + print('e') + return {"message": "nihao"} + # post请求 @app.post("/testPost") async def root(): diff --git a/app/models.py b/cloudcontainers/app/models.py similarity index 70% rename from app/models.py rename to cloudcontainers/app/models.py index 8da01c2..a9b59a4 100644 --- a/app/models.py +++ b/cloudcontainers/app/models.py @@ -1,15 +1,15 @@ from sqlalchemy import Boolean, Column, ForeignKey, Integer, String from sqlalchemy.orm import relationship -from database import Base +from .database import Base class User(Base): __tablename__ = "users" id = Column(Integer, primary_key=True, index=True) - email = Column(String, unique=True, index=True) - hashed_password = Column(String) + email = Column(String(1000), unique=True, index=True) + hashed_password = Column(String(1000)) is_active = Column(Boolean, default=True) items = relationship("Item", back_populates="owner") @@ -19,8 +19,8 @@ class Item(Base): __tablename__ = "items" id = Column(Integer, primary_key=True, index=True) - title = Column(String, index=True) - description = Column(String, index=True) + title = Column(String(1000), index=True) + description = Column(String(1000), index=True) owner_id = Column(Integer, ForeignKey("users.id")) owner = relationship("User", back_populates="items") diff --git a/app/schemas.py b/cloudcontainers/app/schemas.py similarity index 100% rename from app/schemas.py rename to cloudcontainers/app/schemas.py diff --git a/app/sql_app.db b/cloudcontainers/app/sql_app.db similarity index 98% rename from app/sql_app.db rename to cloudcontainers/app/sql_app.db index a10c99d..60efca1 100644 Binary files a/app/sql_app.db and b/cloudcontainers/app/sql_app.db differ diff --git a/docker-compose.yml b/docker-compose.yml new file mode 100644 index 0000000..bdb192f --- /dev/null +++ b/docker-compose.yml @@ -0,0 +1,24 @@ +version: '3' +services: + app: + build: + context: . + dockerfile: Dockerfile.development + volumes: + - .:/code + ports: + - '27081:80' + container_name: wxcloud_fastapiweb + labels: + - wxPort=27083 + - hostPort=27081 + - wxcloud=fastapiweb + - role=container + environment: + - MYSQL_USERNAME= + - MYSQL_PASSWORD= + - MYSQL_ADDRESS= +networks: + default: + external: + name: wxcb0 diff --git a/requirements.txt b/requirements.txt index 9558a21..3f05668 100644 --- a/requirements.txt +++ b/requirements.txt @@ -12,18 +12,25 @@ cffi==1.15.0 charset-normalizer==2.0.12 click==8.1.3 cryptography==37.0.1 +databases==0.6.2 +distlib==0.3.6 dnspython==2.2.1 email-validator==1.1.3 fastapi==0.75.2 fastapi-crudrouter==0.8.5 -fastapi-users==9.3.1 -fastapi-users-db-sqlalchemy==3.0.1 +fastapi-users==10.2.1 +fastapi-users-db-sqlalchemy==4.0.3 +filelock==3.8.2 future==0.18.2 greenlet==1.1.2 grpclib==0.4.2 -h11==0.13.0 +h11==0.12.0 h2==4.1.0 hpack==4.0.0 +httpcore==0.14.7 +httptools==0.5.0 +httpx==0.22.0 +httpx-oauth==0.6.0 hypercorn==0.13.2 hyperframe==6.0.1 idna==3.3 @@ -39,6 +46,8 @@ opengraph-py3==0.71 passlib==1.7.4 pikachuwechat==0.1.2 ping3==4.0.3 +pipenv==2022.11.30 +platformdirs==2.6.0 prettytable==3.3.0 priority==2.0.0 pycodestyle==2.10.0 @@ -46,13 +55,18 @@ pycparser==2.21 pydantic==1.9.0 pyecharts==1.9.1 pyee==9.0.4 -PyJWT==2.3.0 +PyJWT==2.6.0 +PyMySQL==1.0.2 pypng==0.0.21 PyQRCode==1.2.1 +python-dotenv==0.21.0 python-multipart==0.0.5 +PyYAML==6.0 qrcode==7.3.1 quart==0.17.0 requests==2.27.1 +rfc3986==1.5.0 +schedule==1.1.0 simplejson==3.17.6 six==1.16.0 sniffio==1.2.0 @@ -65,6 +79,10 @@ tomli==2.0.1 typing_extensions==4.2.0 urllib3==1.26.9 uvicorn==0.17.6 +uvloop==0.17.0 +virtualenv==20.17.1 +virtualenv-clone==0.5.7 +watchgod==0.8.2 wcwidth==0.2.5 websockets==10.3 wechaty==0.8.39