Browse Source

add Dockerfile and docker-compose.yaml

honmaple 2 years ago
parent
commit
57928c3520
9 changed files with 94 additions and 31 deletions
  1. 25 0
      Dockerfile
  2. 11 4
      config.example
  3. 26 0
      docker-compose.yml
  4. 6 6
      forums/admin/views.py
  5. 3 3
      forums/api/topic/db.py
  6. 8 8
      forums/extension/maple.py
  7. 6 7
      forums/jinja.py
  8. 8 2
      requirements.txt
  9. 1 1
      runserver.py

+ 25 - 0
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"]

+ 11 - 4
config.example

@@ -6,7 +6,7 @@
 # Author: jianglin
 # Author: jianglin
 # Email: mail@honmaple.com
 # Email: mail@honmaple.com
 # Created: 2016-05-20 12:31:46 (CST)
 # 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
 #          By: jianglin
 # Description:
 # Description:
 # **************************************************************************
 # **************************************************************************
@@ -46,11 +46,18 @@ CACHE_REDIS_PASSWORD = 'your password'
 CACHE_REDIS_DB = 2
 CACHE_REDIS_DB = 2
 
 
 # Redis setting
 # Redis setting
-REDIS = {'db': 1, 'password': 'your password', 'decode_responses': True}
+REDIS = {
+    'host': 'redis',
+    'db': 1,
+    'password': 'your password',
+    'decode_responses': True
+}
 
 
 # some middleware
 # 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 such as qq
 MAIL_SERVER = 'smtp.qq.com'
 MAIL_SERVER = 'smtp.qq.com'

+ 26 - 0
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

+ 6 - 6
forums/admin/views.py

@@ -4,9 +4,9 @@
 # Copyright © 2016 jianglin
 # Copyright © 2016 jianglin
 # File Name: views.py
 # File Name: views.py
 # Author: jianglin
 # Author: jianglin
-# Email: xiyang0807@gmail.com
+# Email: mail@honmaple.com
 # Created: 2016-12-17 13:15:10 (CST)
 # Created: 2016-12-17 13:15:10 (CST)
-# Last Update: Wednesday 2019-05-08 14:32:26 (CST)
+# Last Update: Monday 2022-12-12 16:51:58 (CST)
 #          By:
 #          By:
 # Description:
 # Description:
 # **************************************************************************
 # **************************************************************************
@@ -29,8 +29,8 @@ class BaseView(ModelView):
     can_view_details = True
     can_view_details = True
     form_base_class = BaseForm
     form_base_class = BaseForm
 
 
-    # def is_accessible(self):
-    #     return super_permission.can()
+    def is_accessible(self):
+        return super_permission.can()
 
 
-    # def inaccessible_callback(self, name, **kwargs):
-    #     abort(404)
+    def inaccessible_callback(self, name, **kwargs):
+        abort(404)

+ 3 - 3
forums/api/topic/db.py

@@ -2,11 +2,11 @@
 # -*- coding: utf-8 -*-
 # -*- coding: utf-8 -*-
 # **************************************************************************
 # **************************************************************************
 # Copyright © 2016 jianglin
 # Copyright © 2016 jianglin
-# File Name: models.py
+# File Name: db.py
 # Author: jianglin
 # Author: jianglin
-# Email: xiyang0807@gmail.com
+# Email: mail@honmaple.com
 # Created: 2016-12-15 20:52:07 (CST)
 # 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:
 #          By:
 # Description:
 # Description:
 # **************************************************************************
 # **************************************************************************

+ 8 - 8
forums/extension/maple.py

@@ -4,9 +4,9 @@
 # Copyright © 2018 jianglin
 # Copyright © 2018 jianglin
 # File Name: maple.py
 # File Name: maple.py
 # Author: jianglin
 # Author: jianglin
-# Email: xiyang0807@gmail.com
+# Email: mail@honmaple.com
 # Created: 2018-02-11 14:56:08 (CST)
 # 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:
 #          By:
 # Description:
 # Description:
 # ********************************************************************************
 # ********************************************************************************
@@ -17,17 +17,17 @@ from flask_maple.app import App
 from flask_maple.json import CustomJSONEncoder
 from flask_maple.json import CustomJSONEncoder
 from flask_maple.middleware import Middleware
 from flask_maple.middleware import Middleware
 from flask_maple.log import Logging
 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):
 def init_app(app):
     bootstrap.init_app(app)
     bootstrap.init_app(app)
-    Captcha(app)
+    Captcha(app, font=ImageFont.load_default())
     Error(app)
     Error(app)
     App(app, json=CustomJSONEncoder)
     App(app, json=CustomJSONEncoder)
     Middleware(app)
     Middleware(app)

+ 6 - 7
forums/jinja.py

@@ -4,9 +4,9 @@
 # Copyright © 2016 jianglin
 # Copyright © 2016 jianglin
 # File Name: jinja.py
 # File Name: jinja.py
 # Author: jianglin
 # Author: jianglin
-# Email: xiyang0807@gmail.com
+# Email: mail@honmaple.com
 # Created: 2016-11-07 21:00:32 (CST)
 # 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:
 #          By:
 # Description:
 # Description:
 # **************************************************************************
 # **************************************************************************
@@ -16,7 +16,7 @@ from forums import default
 from bleach import clean
 from bleach import clean
 from flask import Markup, g
 from flask import Markup, g
 from flask_babel import format_datetime
 from flask_babel import format_datetime
-from misaka import HtmlRenderer, Markdown
+from markdown import markdown as m
 
 
 
 
 def safe_clean(text):
 def safe_clean(text):
@@ -27,11 +27,10 @@ def safe_clean(text):
 
 
 
 
 def markdown(text, clean=True):
 def markdown(text, clean=True):
-    renderer = HtmlRenderer()
-    md = Markdown(renderer, extensions=('fenced-code', ))
+    html = m(text, extensions=['markdown.extensions.fenced_code'])
     if clean:
     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"):
 def timesince(dt, default="just now"):

+ 8 - 2
requirements.txt

@@ -17,11 +17,17 @@ Flask-Principal==0.4.0
 Flask-SQLAlchemy==2.2
 Flask-SQLAlchemy==2.2
 Flask-WTF==0.14.2
 Flask-WTF==0.14.2
 speaklater==1.3
 speaklater==1.3
-Pillow==3.2.0
-misaka==2.0.0
+Pillow==5.4.1
 Pygments==2.1
 Pygments==2.1
 pytz==2018.3
 pytz==2018.3
 redis==2.10.6
 redis==2.10.6
 psycopg2-binary==2.7.5
 psycopg2-binary==2.7.5
 Whoosh==2.7.4
 Whoosh==2.7.4
 gunicorn==19.9.0
 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

+ 1 - 1
runserver.py

@@ -6,7 +6,7 @@
 # Author: jianglin
 # Author: jianglin
 # Email: mail@honmaple.com
 # Email: mail@honmaple.com
 # Created: 2016-10-25 22:01:29 (CST)
 # 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:
 #          By:
 # Description:
 # Description:
 # **************************************************************************
 # **************************************************************************