diff --git a/Dockerfile b/Dockerfile index eb4072a..ed8370b 100644 --- a/Dockerfile +++ b/Dockerfile @@ -4,7 +4,6 @@ RUN sed -i 's/dl-cdn.alpinelinux.org/mirrors.tuna.tsinghua.edu.cn/g' /etc/apk/re RUN apk add git python3 py3-pip RUN pip config set global.index-url https://pypi.tuna.tsinghua.edu.cn/simple RUN python3 -m pip install --upgrade pip && pip3 install --upgrade setuptools -COPY . /web-gpt -RUN pip3 install -r /web-gpt/requirements.txt -RUN pip3 install waitress +COPY ./project /web-gpt/project +RUN pip3 install -r /web-gpt/project/requirements.txt CMD cd /web-gpt && waitress-serve --listen 0.0.0.0:5000 project:app \ No newline at end of file diff --git a/docker-compose.yaml b/docker-compose.yaml new file mode 100644 index 0000000..51675cc --- /dev/null +++ b/docker-compose.yaml @@ -0,0 +1,33 @@ +version: '3' + +volumes: + web-gpt: + db: + + +services: + web-gpt: + image: web-gpt + restart: always + depends_on: + - db + build: + context: . + + volumes: + - ./instance:/web-gpt/instance + + ports: + - 5000:5000 + + db: + image: mariadb + restart: always + command: --transaction-isolation=READ-COMMITTED --log-bin=binlog --binlog-format=ROW + volumes: + - ./db:/var/lib/mysql + environment: + - MYSQL_ROOT_PASSWORD= + - MYSQL_PASSWORD= + - MYSQL_DATABASE=web-gpt + - MYSQL_USER=web-gpt diff --git a/instance/config.yaml b/instance/config.yaml index e21bb1e..2ff6dad 100644 --- a/instance/config.yaml +++ b/instance/config.yaml @@ -8,8 +8,8 @@ app: 4. 网站不做关键词过滤,但请不要违反相关法律 5. GPT生成的任何内容不保证准确性,请自行甄别 - SQLALCHEMY_DATABASE_URI: sqlite:///sqlite.db - # SQLALCHEMY_DATABASE_URI: mysql://username:password@server/db + # SQLALCHEMY_DATABASE_URI: sqlite:///sqlite.db + SQLALCHEMY_DATABASE_URI: mysql+pymysql://web-gpt:@db/web-gpt # LOGGING_LEVEL: CRITICAL | FATAL | ERROR | WARN | WARNING | INFO | DEBUG | NOTSET LOGGING_LEVEL: INFO diff --git a/project/__init__.py b/project/__init__.py index e84244b..1d9a98d 100644 --- a/project/__init__.py +++ b/project/__init__.py @@ -6,6 +6,8 @@ import logging import time import traceback import os +import waitress +import pymysql # init SQLAlchemy so we can use it later in our models db = SQLAlchemy() diff --git a/project/models.py b/project/models.py index ea04e47..7b5c28c 100644 --- a/project/models.py +++ b/project/models.py @@ -18,6 +18,6 @@ class Conversation(db.Model): userid = db.Column(db.Integer) useremail = db.Column(db.String(100), nullable=False) username = db.Column(db.String(100), nullable=False) - request = db.Column(db.String(10000)) - response = db.Column(db.String(10000)) + request = db.Column(db.TEXT) + response = db.Column(db.TEXT) datetime = db.Column(db.DateTime, server_default=func.now()) diff --git a/requirements.txt b/project/requirements.txt similarity index 79% rename from requirements.txt rename to project/requirements.txt index e184a48..d15acef 100644 --- a/requirements.txt +++ b/project/requirements.txt @@ -2,6 +2,8 @@ Flask==2.2.3 Flask_Login==0.6.2 flask_sqlalchemy==3.0.3 openai==0.27.2 +PyMySQL==1.0.3 PyYAML==6.0 SQLAlchemy==2.0.7 +waitress==2.1.2 Werkzeug==2.2.3