feat: docker本地调试:
- 1. import不同系统语法不一致 - 2. mysql允许远程访问
This commit is contained in:
12
.cloudbase/container/debug.json
Normal file
12
.cloudbase/container/debug.json
Normal file
@@ -0,0 +1,12 @@
|
|||||||
|
{
|
||||||
|
"containers": [
|
||||||
|
{
|
||||||
|
"name": "fastapiweb",
|
||||||
|
"domain": "",
|
||||||
|
"ip": "",
|
||||||
|
"mode": "compose",
|
||||||
|
"containerId": "2eff8c8bd0d2909a8b806e8c12acc9fa0362494c45ea739b23c9c66cf59312b0"
|
||||||
|
}
|
||||||
|
],
|
||||||
|
"config": {}
|
||||||
|
}
|
||||||
@@ -1,5 +1,5 @@
|
|||||||
# 1、从官方 Python 基础镜像开始
|
# 1、从官方 Python 基础镜像开始
|
||||||
FROM python:3.9
|
FROM python:3.10
|
||||||
|
|
||||||
# 2、将当前工作目录设置为 /code
|
# 2、将当前工作目录设置为 /code
|
||||||
# 这是放置 requirements.txt 文件和应用程序目录的地方
|
# 这是放置 requirements.txt 文件和应用程序目录的地方
|
||||||
@@ -13,7 +13,7 @@ COPY ./requirements.txt /code/requirements.txt
|
|||||||
RUN pip install --no-cache-dir --upgrade -r /code/requirements.txt
|
RUN pip install --no-cache-dir --upgrade -r /code/requirements.txt
|
||||||
|
|
||||||
# 5、复制 FastAPI 项目代码
|
# 5、复制 FastAPI 项目代码
|
||||||
COPY ./app /code/app
|
COPY ./cloudcontainers/app /code/app
|
||||||
|
|
||||||
# 6、运行服务
|
# 6、运行服务
|
||||||
CMD ["uvicorn", "app.main:app", "--host", "0.0.0.0", "--port", "80"]
|
CMD ["uvicorn", "cloudcontainers.app.main:app", "--host", "0.0.0.0", "--port", "80"]
|
||||||
10
Dockerfile.development
Normal file
10
Dockerfile.development
Normal file
@@ -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" ]
|
||||||
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
@@ -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()
|
|
||||||
BIN
cloudcontainers/__pycache__/__init__.cpython-310.pyc
Normal file
BIN
cloudcontainers/__pycache__/__init__.cpython-310.pyc
Normal file
Binary file not shown.
BIN
cloudcontainers/app/__pycache__/crud.cpython-310.pyc
Normal file
BIN
cloudcontainers/app/__pycache__/crud.cpython-310.pyc
Normal file
Binary file not shown.
BIN
cloudcontainers/app/__pycache__/database.cpython-310.pyc
Normal file
BIN
cloudcontainers/app/__pycache__/database.cpython-310.pyc
Normal file
Binary file not shown.
BIN
cloudcontainers/app/__pycache__/main.cpython-310.pyc
Normal file
BIN
cloudcontainers/app/__pycache__/main.cpython-310.pyc
Normal file
Binary file not shown.
BIN
cloudcontainers/app/__pycache__/models.cpython-310.pyc
Normal file
BIN
cloudcontainers/app/__pycache__/models.cpython-310.pyc
Normal file
Binary file not shown.
@@ -2,7 +2,7 @@ from sqlalchemy.orm import Session
|
|||||||
from sqlalchemy import select
|
from sqlalchemy import select
|
||||||
|
|
||||||
|
|
||||||
import models, schemas
|
from . import models, schemas
|
||||||
|
|
||||||
|
|
||||||
# 删除
|
# 删除
|
||||||
15
cloudcontainers/app/database.py
Normal file
15
cloudcontainers/app/database.py
Normal file
@@ -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()
|
||||||
@@ -7,8 +7,8 @@ from pydantic import BaseModel
|
|||||||
|
|
||||||
|
|
||||||
from sqlalchemy.orm import Session
|
from sqlalchemy.orm import Session
|
||||||
import crud, models, schemas
|
from . import crud, models, schemas
|
||||||
from database import SessionLocal, engine
|
from .database import SessionLocal, engine
|
||||||
models.Base.metadata.create_all(bind=engine)
|
models.Base.metadata.create_all(bind=engine)
|
||||||
|
|
||||||
|
|
||||||
@@ -73,6 +73,18 @@ async def root():
|
|||||||
print('e')
|
print('e')
|
||||||
return {"message": "触发飞书webhook"}
|
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请求
|
# post请求
|
||||||
@app.post("/testPost")
|
@app.post("/testPost")
|
||||||
async def root():
|
async def root():
|
||||||
@@ -1,15 +1,15 @@
|
|||||||
from sqlalchemy import Boolean, Column, ForeignKey, Integer, String
|
from sqlalchemy import Boolean, Column, ForeignKey, Integer, String
|
||||||
from sqlalchemy.orm import relationship
|
from sqlalchemy.orm import relationship
|
||||||
|
|
||||||
from database import Base
|
from .database import Base
|
||||||
|
|
||||||
|
|
||||||
class User(Base):
|
class User(Base):
|
||||||
__tablename__ = "users"
|
__tablename__ = "users"
|
||||||
|
|
||||||
id = Column(Integer, primary_key=True, index=True)
|
id = Column(Integer, primary_key=True, index=True)
|
||||||
email = Column(String, unique=True, index=True)
|
email = Column(String(1000), unique=True, index=True)
|
||||||
hashed_password = Column(String)
|
hashed_password = Column(String(1000))
|
||||||
is_active = Column(Boolean, default=True)
|
is_active = Column(Boolean, default=True)
|
||||||
|
|
||||||
items = relationship("Item", back_populates="owner")
|
items = relationship("Item", back_populates="owner")
|
||||||
@@ -19,8 +19,8 @@ class Item(Base):
|
|||||||
__tablename__ = "items"
|
__tablename__ = "items"
|
||||||
|
|
||||||
id = Column(Integer, primary_key=True, index=True)
|
id = Column(Integer, primary_key=True, index=True)
|
||||||
title = Column(String, index=True)
|
title = Column(String(1000), index=True)
|
||||||
description = Column(String, index=True)
|
description = Column(String(1000), index=True)
|
||||||
owner_id = Column(Integer, ForeignKey("users.id"))
|
owner_id = Column(Integer, ForeignKey("users.id"))
|
||||||
|
|
||||||
owner = relationship("User", back_populates="items")
|
owner = relationship("User", back_populates="items")
|
||||||
Binary file not shown.
24
docker-compose.yml
Normal file
24
docker-compose.yml
Normal file
@@ -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
|
||||||
@@ -12,18 +12,25 @@ cffi==1.15.0
|
|||||||
charset-normalizer==2.0.12
|
charset-normalizer==2.0.12
|
||||||
click==8.1.3
|
click==8.1.3
|
||||||
cryptography==37.0.1
|
cryptography==37.0.1
|
||||||
|
databases==0.6.2
|
||||||
|
distlib==0.3.6
|
||||||
dnspython==2.2.1
|
dnspython==2.2.1
|
||||||
email-validator==1.1.3
|
email-validator==1.1.3
|
||||||
fastapi==0.75.2
|
fastapi==0.75.2
|
||||||
fastapi-crudrouter==0.8.5
|
fastapi-crudrouter==0.8.5
|
||||||
fastapi-users==9.3.1
|
fastapi-users==10.2.1
|
||||||
fastapi-users-db-sqlalchemy==3.0.1
|
fastapi-users-db-sqlalchemy==4.0.3
|
||||||
|
filelock==3.8.2
|
||||||
future==0.18.2
|
future==0.18.2
|
||||||
greenlet==1.1.2
|
greenlet==1.1.2
|
||||||
grpclib==0.4.2
|
grpclib==0.4.2
|
||||||
h11==0.13.0
|
h11==0.12.0
|
||||||
h2==4.1.0
|
h2==4.1.0
|
||||||
hpack==4.0.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
|
hypercorn==0.13.2
|
||||||
hyperframe==6.0.1
|
hyperframe==6.0.1
|
||||||
idna==3.3
|
idna==3.3
|
||||||
@@ -39,6 +46,8 @@ opengraph-py3==0.71
|
|||||||
passlib==1.7.4
|
passlib==1.7.4
|
||||||
pikachuwechat==0.1.2
|
pikachuwechat==0.1.2
|
||||||
ping3==4.0.3
|
ping3==4.0.3
|
||||||
|
pipenv==2022.11.30
|
||||||
|
platformdirs==2.6.0
|
||||||
prettytable==3.3.0
|
prettytable==3.3.0
|
||||||
priority==2.0.0
|
priority==2.0.0
|
||||||
pycodestyle==2.10.0
|
pycodestyle==2.10.0
|
||||||
@@ -46,13 +55,18 @@ pycparser==2.21
|
|||||||
pydantic==1.9.0
|
pydantic==1.9.0
|
||||||
pyecharts==1.9.1
|
pyecharts==1.9.1
|
||||||
pyee==9.0.4
|
pyee==9.0.4
|
||||||
PyJWT==2.3.0
|
PyJWT==2.6.0
|
||||||
|
PyMySQL==1.0.2
|
||||||
pypng==0.0.21
|
pypng==0.0.21
|
||||||
PyQRCode==1.2.1
|
PyQRCode==1.2.1
|
||||||
|
python-dotenv==0.21.0
|
||||||
python-multipart==0.0.5
|
python-multipart==0.0.5
|
||||||
|
PyYAML==6.0
|
||||||
qrcode==7.3.1
|
qrcode==7.3.1
|
||||||
quart==0.17.0
|
quart==0.17.0
|
||||||
requests==2.27.1
|
requests==2.27.1
|
||||||
|
rfc3986==1.5.0
|
||||||
|
schedule==1.1.0
|
||||||
simplejson==3.17.6
|
simplejson==3.17.6
|
||||||
six==1.16.0
|
six==1.16.0
|
||||||
sniffio==1.2.0
|
sniffio==1.2.0
|
||||||
@@ -65,6 +79,10 @@ tomli==2.0.1
|
|||||||
typing_extensions==4.2.0
|
typing_extensions==4.2.0
|
||||||
urllib3==1.26.9
|
urllib3==1.26.9
|
||||||
uvicorn==0.17.6
|
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
|
wcwidth==0.2.5
|
||||||
websockets==10.3
|
websockets==10.3
|
||||||
wechaty==0.8.39
|
wechaty==0.8.39
|
||||||
|
|||||||
Reference in New Issue
Block a user