From 97594d87c2e4e461c23908c283e8abe0321190bc Mon Sep 17 00:00:00 2001 From: honmaple Date: Mon, 12 Dec 2022 16:42:20 +0800 Subject: [PATCH] add Dockerfile and docker-compose.yaml --- Dockerfile | 25 +++++++++++++++++++++++++ config.example | 15 +++++++++++---- docker-compose.yml | 26 ++++++++++++++++++++++++++ forums/api/topic/db.py | 6 +++--- forums/extension/maple.py | 16 ++++++++-------- forums/jinja.py | 13 ++++++------- requirements.txt | 10 ++++++++-- runserver.py | 2 +- 8 files changed, 88 insertions(+), 25 deletions(-) create mode 100644 Dockerfile create mode 100644 docker-compose.yml diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 0000000..d4d2530 --- /dev/null +++ b/Dockerfile @@ -0,0 +1,25 @@ +FROM ubuntu:18.04 + +ENV TZ "Asia/Shanghai" +ENV LANG "C.UTF-8" + +RUN sed -i 's/archive.ubuntu.com/mirrors.163.com/g' /etc/apt/sources.list && \ + sed -i 's/security.ubuntu.com/mirrors.163.com/g' /etc/apt/sources.list && \ + echo $TZ > /etc/timezone && \ + apt update && DEBIAN_FRONTEND=noninteractive apt install -y --no-install-recommends \ + python3-pip python3-setuptools python3-wheel python3.6 tzdata && \ + ln -s /usr/bin/python3.6 /usr/bin/python && ln -s /usr/bin/pip3 /usr/bin/pip + +RUN mkdir -p /web/logs +WORKDIR /web + +ADD requirements.txt /web/requirements.txt +RUN pip3 install -r requirements.txt -i http://mirrors.aliyun.com/pypi/simple/ --trusted-host mirrors.aliyun.com + +ADD runserver.py /web/runserver.py +ADD forums /web/forums +ADD templates /web/templates +ADD static /web/static +ADD translations /web/translations + +CMD ["gunicorn","-b","0.0.0.0:8000","runserver:app"] diff --git a/config.example b/config.example index 85e03fb..506acd9 100755 --- a/config.example +++ b/config.example @@ -6,7 +6,7 @@ # Author: jianglin # Email: mail@honmaple.com # Created: 2016-05-20 12:31:46 (CST) -# Last Update: Wednesday 2019-05-08 16:28:02 (CST) +# Last Update: Monday 2022-12-12 16:40:46 (CST) # By: jianglin # Description: # ************************************************************************** @@ -46,11 +46,18 @@ CACHE_REDIS_PASSWORD = 'your password' CACHE_REDIS_DB = 2 # Redis setting -REDIS = {'db': 1, 'password': 'your password', 'decode_responses': True} +REDIS = { + 'host': 'redis', + 'db': 1, + 'password': 'your password', + 'decode_responses': True +} # some middleware -MIDDLEWARE = ['forums.common.middleware.GlobalMiddleware', - 'forums.common.middleware.OnlineMiddleware'] +MIDDLEWARE = [ + 'forums.common.middleware.GlobalMiddleware', + 'forums.common.middleware.OnlineMiddleware' +] # Mail such as qq MAIL_SERVER = 'smtp.qq.com' diff --git a/docker-compose.yml b/docker-compose.yml new file mode 100644 index 0000000..5cbe1cb --- /dev/null +++ b/docker-compose.yml @@ -0,0 +1,26 @@ +version: "2.2" +services: + redis: + image: redis:alpine + ports: + - 6379:6379 + postgres: + image: postgres:10 + restart: always + ports: + - 5433:5432 + environment: + - POSTGRES_PASSWORD=test + forums: + build: + context: . + ports: + - 8000:8000 + links: + - redis + - postgres + depends_on: + - redis + - postgres + volumes: + - ./config.py:/web/config.py diff --git a/forums/api/topic/db.py b/forums/api/topic/db.py index 467eb89..ef18aa8 100755 --- a/forums/api/topic/db.py +++ b/forums/api/topic/db.py @@ -2,11 +2,11 @@ # -*- coding: utf-8 -*- # ************************************************************************** # Copyright © 2016 jianglin -# File Name: models.py +# File Name: db.py # Author: jianglin -# Email: xiyang0807@gmail.com +# Email: mail@honmaple.com # Created: 2016-12-15 20:52:07 (CST) -# Last Update: Monday 2019-05-06 23:37:22 (CST) +# Last Update: Monday 2022-12-12 15:22:48 (CST) # By: # Description: # ************************************************************************** diff --git a/forums/extension/maple.py b/forums/extension/maple.py index 79b2d6f..2d135f7 100644 --- a/forums/extension/maple.py +++ b/forums/extension/maple.py @@ -4,9 +4,9 @@ # Copyright © 2018 jianglin # File Name: maple.py # Author: jianglin -# Email: xiyang0807@gmail.com +# Email: mail@honmaple.com # Created: 2018-02-11 14:56:08 (CST) -# Last Update: 星期日 2018-02-11 15:26:53 (CST) +# Last Update: Monday 2022-12-12 16:38:21 (CST) # By: # Description: # ******************************************************************************** @@ -17,17 +17,17 @@ from flask_maple.json import CustomJSONEncoder from flask_maple.middleware import Middleware from flask_maple.log import Logging +from PIL import ImageFont -bootstrap = Bootstrap( - css=('styles/monokai.css', 'styles/mine.css'), - js=('styles/upload.js', 'styles/forums.js', 'styles/following.js', - 'styles/topic.js'), - use_auth=True) +bootstrap = Bootstrap(css=('styles/monokai.css', 'styles/mine.css'), + js=('styles/upload.js', 'styles/forums.js', + 'styles/following.js', 'styles/topic.js'), + use_auth=True) def init_app(app): bootstrap.init_app(app) - Captcha(app) + Captcha(app, font=ImageFont.load_default()) Error(app) App(app, json=CustomJSONEncoder) Middleware(app) diff --git a/forums/jinja.py b/forums/jinja.py index 9730191..847f51d 100755 --- a/forums/jinja.py +++ b/forums/jinja.py @@ -4,9 +4,9 @@ # Copyright © 2016 jianglin # File Name: jinja.py # Author: jianglin -# Email: xiyang0807@gmail.com +# Email: mail@honmaple.com # Created: 2016-11-07 21:00:32 (CST) -# Last Update: Wednesday 2019-05-08 16:26:18 (CST) +# Last Update: Monday 2022-12-12 16:11:32 (CST) # By: # Description: # ************************************************************************** @@ -16,7 +16,7 @@ from bleach import clean from flask import Markup, g from flask_babel import format_datetime -from misaka import HtmlRenderer, Markdown +from markdown import markdown as m def safe_clean(text): @@ -27,11 +27,10 @@ def safe_clean(text): def markdown(text, clean=True): - renderer = HtmlRenderer() - md = Markdown(renderer, extensions=('fenced-code', )) + html = m(text, extensions=['markdown.extensions.fenced_code']) if clean: - return Markup(safe_clean(md(text))) - return Markup(md(text)) + return Markup(safe_clean(html)) + return Markup(html) def timesince(dt, default="just now"): diff --git a/requirements.txt b/requirements.txt index 4b93b72..6deb83d 100644 --- a/requirements.txt +++ b/requirements.txt @@ -17,11 +17,17 @@ Flask-Principal==0.4.0 Flask-SQLAlchemy==2.2 Flask-WTF==0.14.2 speaklater==1.3 -Pillow==3.2.0 -misaka==2.0.0 +Pillow==5.4.1 Pygments==2.1 pytz==2018.3 redis==2.10.6 psycopg2-binary==2.7.5 Whoosh==2.7.4 gunicorn==19.9.0 +jinja2==3.0.3 +itsdangerous==2.0.1 +Werkzeug==0.16.1 +wtforms==2.3.1 +SQLAlchemy==1.3.5 +Markdown==3.3.7 +email-validator==1.3.0 diff --git a/runserver.py b/runserver.py index 3ffc52a..d38b26c 100755 --- a/runserver.py +++ b/runserver.py @@ -6,7 +6,7 @@ # Author: jianglin # Email: mail@honmaple.com # Created: 2016-10-25 22:01:29 (CST) -# Last Update: Monday 2019-05-06 23:36:53 (CST) +# Last Update: Monday 2022-12-12 15:29:04 (CST) # By: # Description: # **************************************************************************