Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
97 commits
Select commit Hold shift + click to select a range
89f4df3
重新梳理书稿关联分支代码
the5fire Mar 10, 2018
8f263dc
init project
the5fire Mar 10, 2018
25a8a62
完成App和Model代码的创建
the5fire Mar 10, 2018
2a803dd
修复遗漏拆分settings的配置
the5fire Mar 10, 2018
2ecc627
提交migrations
the5fire Mar 10, 2018
93b289e
配置Tag和Category的admin界面
the5fire Mar 10, 2018
35b3d79
修改Category的author为owner
the5fire Mar 10, 2018
054209d
保存category和tag是自动绑定当前用户
the5fire Mar 10, 2018
d485042
增加post admin配置
the5fire Mar 11, 2018
25a4d87
增加文章数量
the5fire Mar 11, 2018
723ff11
增加__str__
the5fire Mar 11, 2018
e6f05ed
配置comment和config的admin模块
the5fire Mar 11, 2018
6509742
自定义list filter
the5fire Mar 20, 2018
ba09408
定制post编辑页面,配置fieldsets
the5fire Mar 21, 2018
a1544c3
添加adminform
the5fire Mar 21, 2018
66f8858
配置自定义site
the5fire Mar 21, 2018
4d099c0
抽象出owneradmin基类
the5fire Mar 21, 2018
b4ab72a
增加logentry的管理功能
the5fire Mar 25, 2018
4865dab
简单的配置url和views
the5fire Mar 25, 2018
2b29e8e
配置template的展示
the5fire Mar 25, 2018
23f1e07
简单展示model的数据到模板中
the5fire Mar 25, 2018
9cbb546
区分首页、分类页、标签页
the5fire Mar 25, 2018
6e39c34
重构views代码,修复n+1问题
the5fire Mar 25, 2018
7195d8e
完善html结构
the5fire Mar 25, 2018
5a6bd07
新增分类导航的渲染代码
the5fire Mar 25, 2018
c940164
增加侧边栏数据展示
the5fire Mar 25, 2018
59644e7
修改post模型,增加pv uv字段
the5fire Mar 25, 2018
676f35e
封装sidebar数据(对应07-03)
the5fire Apr 1, 2018
7c17a03
整理抽象模板代码
the5fire Apr 5, 2018
eb9fab6
改造为class based view
the5fire Apr 8, 2018
4b01adc
08-01 静态页面
the5fire Apr 8, 2018
4de2e24
增加themes文件
the5fire Apr 8, 2018
02db6d5
新增bootstrap样式
the5fire Apr 8, 2018
1828e93
配置本地静态资源
the5fire Apr 8, 2018
4e64b6b
增加搜索和作者页面
the5fire Apr 9, 2018
09e4dcd
增加友链页面
the5fire Apr 9, 2018
8b2cf5c
完成评论功能添加
the5fire Apr 10, 2018
1876ba8
抽象评论功能为独立的tag
the5fire Apr 10, 2018
acc3d04
配置markdown和代码高亮
the5fire Apr 11, 2018
1464dea
实现pv、uv统计
the5fire Apr 12, 2018
7fae3be
添加rss和sitemap输出
the5fire Apr 12, 2018
1923aed
admin替换为xadmin
the5fire Apr 19, 2018
def5ee4
去掉之前忘记移除的save_model和get_queryset方法
the5fire Apr 19, 2018
79f07a3
完成xadmin数据处理的配置
the5fire Apr 19, 2018
f5dd14a
去掉admin 的log配置,自定义title和footer
the5fire Apr 20, 2018
7facb98
配置autocomplete
the5fire Apr 20, 2018
6f80077
配置django-ckeditor和图片上传
the5fire Apr 20, 2018
db28758
配置自定义存储,配置水印
the5fire Apr 21, 2018
3216f0e
调整获取文件大小的方法
the5fire Apr 21, 2018
cf0e44a
使用直接操作图片对象的方式设置水印
the5fire Apr 21, 2018
8ec4c9e
配置restframework,使用api_view和ListCreateAPIView
the5fire Apr 22, 2018
7960a27
使用viewset处理post接口
the5fire Apr 22, 2018
4034496
使用base_name避免namespace不生效的问题
the5fire Apr 22, 2018
0407da6
增加api docs配置
the5fire Apr 22, 2018
14fedd3
增加文章、分类接口的展示以及分页处理,使用query方式获取某个分类下的文章
the5fire Apr 22, 2018
edf20fc
通过category 详情获取文章列表和分页数据
the5fire Apr 22, 2018
dcb3bce
comment form instance
the5fire Apr 22, 2018
56a3d4f
配置hyperlinked serializer
the5fire Apr 23, 2018
47386a0
修复bootstrap模板忘记写</body>的问题
the5fire Apr 30, 2018
4c8acc4
配置django-debug-toolbar
the5fire May 1, 2018
83bd88f
配置line profiler
the5fire May 1, 2018
90fa9b3
配置django-silk
the5fire May 1, 2018
d63e259
去掉silk配置, 配置database mysql
the5fire May 1, 2018
e75b175
配置markdown和ckeditor编辑器切换
the5fire May 2, 2018
9893c14
调整模板组织结构
the5fire May 2, 2018
2ca3486
调整静态文件位置
the5fire May 2, 2018
1e01840
去掉冗余的highlightjs
the5fire May 2, 2018
5d0c9c6
修复sitemap.xml模板的路径
the5fire May 3, 2018
fe851f2
配置cache和debug toolbar
the5fire May 4, 2018
9602c5c
抽取main函数
the5fire May 11, 2018
d2fab1b
增加打包配置
the5fire May 11, 2018
471876c
增加打包版本号处理
the5fire May 12, 2018
5ff3fc2
配置fabfile和supervisord.conf
the5fire May 12, 2018
21e3f87
配置正式环境supervisord
the5fire May 14, 2018
66f0640
增加依赖文件
the5fire May 14, 2018
b035e5c
配置正式supervisord
the5fire May 15, 2018
9b2b725
配置正式product settings,配置404和500异常handler
the5fire May 16, 2018
3e88c93
增加nginx配置
the5fire May 17, 2018
d756334
增加fabric2版本的fabfile文件
the5fire May 20, 2018
92344c3
配置静态文件
the5fire May 20, 2018
13023d1
附录 配置uwsgi启动项目
the5fire May 20, 2018
bdae2de
去掉打包时本地collectstatic的静态文件目录
the5fire May 20, 2018
dc73400
修复外键必填on_delete参数兼容问题
the5fire May 20, 2018
5902136
is_authenticated接口调整
the5fire May 20, 2018
214f34f
配置develop环境的sentry
the5fire May 21, 2018
62a009d
配置评论验证码
the5fire May 21, 2018
00d9485
使用ajax的方式校验验证码
the5fire May 21, 2018
2c34cdf
fix tag autocomplete name typo
the5fire Jun 5, 2018
c7b0e32
fix reverse app name error
the5fire Jun 5, 2018
7c08c48
去掉冗余的代码高亮配置
the5fire Jun 5, 2018
e235f39
增加redis配置
the5fire Jun 12, 2018
3ec4730
调整数据处理到Model层
the5fire Jun 23, 2018
bcc4d51
修改Detail的queryset获取
the5fire Jun 23, 2018
80a7859
fix related tag typo
the5fire Jun 24, 2018
91081e3
部署相关调整
the5fire Nov 1, 2018
877db50
增加验证码的依赖
the5fire Nov 6, 2018
391f4db
fix
the5fire Jan 18, 2019
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 0 additions & 3 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +0,0 @@
## version 0.1.0 -- 2017-07-30

init project
21 changes: 0 additions & 21 deletions LICENSE
Original file line number Diff line number Diff line change
@@ -1,21 +0,0 @@
MIT License

Copyright (c) 2017

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
3 changes: 3 additions & 0 deletions MANIFEST.in
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
include README.md
recursive-include typeidea *.css *.js *.jpg *.gif *.png *.html *.md
prune typeidea/typeidea/static_files
1 change: 0 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1 +0,0 @@
Hello, This is TypeIdea -- Blog system based on Django.
56 changes: 56 additions & 0 deletions conf/dev_supervisord.conf
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
[unix_http_server]
file=/tmp/supervisor.sock ; the path to the socket file
;chmod=0700 ; socket file mode (default 0700)
;chown=nobody:nogroup ; socket file uid:gid owner
;username=user ; default is no username (open server)
;password=123 ; default is no password (open server)

[inet_http_server] ; Web Server的部分
port=127.0.0.1:9001 ;
username=user ; 登录用户名
password=123 ; 登录密码

[supervisord] ; 全局配置部分
logfile=supervisord.log ; 主log文件
logfile_maxbytes=50MB ; rotation配置
logfile_backups=10 ; 备份数量
loglevel=info ; 日志级别,默认 info; 其他选项: debug,warn,trace
pidfile=/tmp/supervisord.pid ; pid文件
nodaemon=false ; 默认是后台运行,如果需要前台运行可以设置为true
;user=chrism ; 默认是当前用户,如果是root用户的话需要配置为root
;directory=/tmp ; 配置所有涉及到目录的根目录,默认是当前运行目录
;environment=KEY="value" ; 全局(所有program)环境变量配置

[rpcinterface:supervisor] ; 必须启用,supervisorctl通过它来管理进程
supervisor.rpcinterface_factory = supervisor.rpcinterface:make_main_rpcinterface

[supervisorctl] ; 前几项配置必须跟[unix_http_server]保持相同
serverurl=unix:///tmp/supervisor.sock
;username=chris
;password=123
;prompt=mysupervisor ; 进入交互模式时的提示文字,默认是"supervisor"
;history_file=~/.sc_history ; 用户的历史记录,跟bash上的配置类似,开启后可以查看和使用历史命令

[program:typeidea] ;程序配置的部分,一份supervisord.conf可以配置多个程序
command=gunicorn typeidea.wsgi:application -w 4 -b 127.0.0.1:800%(process_num)1d ; 启动命令,需要注意路径,最后的%(process_num)1d是获取当前进程号
process_name=%(program_name)s_%(process_num)s ; 进程名,当下面的numprocs大于1时,必须配置%(process_num)s
numprocs=2 ; 要启动进程数
directory=typeidea ; 同上面配置,启动是所处的目录
priority=999 ; 程序权重,多个程序时不同权重的程序启动先后顺序不同
autostart=true ; supervisord启动是是否自动启动
environment=TYPEIDEA_PROFILE="develop" ; 环境变量配置
;startsecs=1 ; 进程启动多长时间后视为正常运行
;startretries=3 ; 启动失败时重试次数,默认3
;autorestart=unexpected ; 何时重启进程如果程序在正常运行后退出,默认是unexpected也就是异常(不属于下面配置的exitcode时)
;exitcodes=0,2 ; 正常退出的exitcode
;stopsignal=QUIT ; kill进程的信号,默认是TERM,这是Linux中断信号:有如下选项
; TERM, HUP, INT, QUIT, KILL, USR1, or USR2
;stopwaitsecs=10 ; 当执行shutdown后多久关闭进程
;stopasgroup=false ; 停止进程组,比如Flask的Debug模式下,它不会传播信号给子进程,这会导致出现孤儿进程。
;killasgroup=false ; 同上,如果运行程序使用了multiprocessing的话需要用到
;user=chrism ; 使用其他用户身份运行程序
;redirect_stderr=true ; 重定向错误到stdout中,默认关闭
stdout_logfile=stdout.log ;同 [supervisord]
;stdout_logfile_maxbytes=1MB ;
;stdout_logfile_backups=10 ;

16 changes: 16 additions & 0 deletions conf/dev_uwsgi.ini
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
[uwsgi]
http = :9090
chdir = ./typeidea
home=/Users/the5fire/.virtualenvs/typeidea-env3
PYTHONHOME = /Users/the5fire/.virtualenvs/typeidea-env3/bin/

env = TYPEIDEA_PROFILE=develop
wsgi-file = typeidea/wsgi.py
static-safe=typeidea/static_files
route = /static/(.*) static:typeidea/static_files/$1
route = /media/(.*) static:./typeidea/media/$1
processes = 4
threads = 2
logger = file:errlog.log
greenlet=1
asyncio=10
34 changes: 34 additions & 0 deletions conf/nginx/apps/typeidea.conf
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
upstream backend {
# ip_hash/least_conn或者不填(默认round-robin)
# 需要配合nginx upstream check module才能用
# check interval=10000 rise=2 fall=3 timeout=3000 type=http default_down=false;

# max_failes 最大失败次数, 失败后的等待时间,权重(越高被请求的频率越高)
server 127.0.0.1:9090 max_fails=3 fail_timeout=30s weight=5;
server 127.0.0.1:9091 max_fails=3 fail_timeout=30s weight=5;
}

server {
listen 80 backlog=10000 default;
server_name default;
client_body_in_single_buffer on; # 是否把request body放到一个buffer中。
client_max_body_size 2m; # request body最大限制,2M,如果是上传文件需求可以调整配置。
client_body_buffer_size 50m; # request body buffer大小,超过设置会写入临时文件.
proxy_buffering off; # 关闭proxy buffering,具体可查看本节参考链接

access_log /tmp/access_log_typeidea.log main;

location / {
proxy_pass http://backend;
proxy_http_version 1.1;
proxy_connect_timeout 30;
proxy_set_header Host $host;
proxy_set_header X-Real-IP $http_x_forwarded_for;
proxy_set_header X-Forwarded-For $remote_addr;
proxy_set_header X-Forwarded-Host $http_host;
}
location /static/ {
expire 1d; # 缓存1天
alias /home/the5fire/venvs/typeidea-env/static_files/; # 需要跟最终项目部署后配置的STATIC_ROOT保持一致。
}
}
36 changes: 36 additions & 0 deletions conf/nginx/nginx.conf
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
user root; # 以什么用户身份运行子进程
worker_processes 1; # 一般设置为核数,通过命令:cat /proc/cpuinfo|grep "processor"|wc -l 查看核数
# worker_cpu_affinity 01 10; # 多核情况下启用,设置亲和度,每个worker绑定到一个核上。如果是4核,则: 0001 0010 0100 1000 以此类推。

error_log /var/log/nginx/error.log warn;
pid /var/run/nginx.pid;


events {
use epoll; # 使用epoll提升并发能力,仅Linux系统可用
worker_connections 1024; # 单个worker的同时最大连接数
}


http {
include /etc/nginx/mime.types;
default_type application/octet-stream;

log_format main '$remote_addr - $remote_user [$time_local] "$request" '
'$status $body_bytes_sent "$http_referer" '
'"$http_user_agent" "$http_x_forwarded_for"';

access_log /var/log/nginx/access.log main;

sendfile on; # 开启sendfile调用 —— 零拷贝技术,提供文件传输效率
tcp_nopush on; # 配置TCP_CORK,配置sendfile后才会有效

keepalive_timeout 65; # keepalive超时时间

gzip on; # 开启gzip压缩
gzip_types text/plain application/javascript application/x-javascript text/javascript text/css application/xml; # gzip要处理的文件类型

# include /etc/nginx/conf.d/*.conf; # include 其他文件进来

include apps/typeidea.conf; # 我们的配置文件
}
39 changes: 39 additions & 0 deletions conf/supervisord.conf
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
[unix_http_server]
file={{ deploy_path }}/tmp/supervisor.sock

[inet_http_server]
port=127.0.0.1:9001
username=user
password=123

[supervisord]
logfile={{ deploy_path }}supervisord.log
logfile_maxbytes=50MB
logfile_backups=10
loglevel=info
pidfile={{ deploy_path }}/tmp/supervisord.pid
nodaemon=false

[rpcinterface:supervisor]
supervisor.rpcinterface_factory = supervisor.rpcinterface:make_main_rpcinterface

[supervisorctl]
serverurl=unix://{{ deploy_path }}/tmp/supervisor.sock

[program:typeidea]
command=gunicorn typeidea.wsgi:application -w 1 -b 0.0.0.0:{{ port_prefix }}%(process_num)1d
process_name=%(program_name)s_%(process_num)s
numprocs={{ process_count }}
directory={{ deploy_path }}
priority=999
autostart=true
environment=TYPEIDEA_PROFILE="{{ profile }}"
startsecs=5
autorestart=unexpected
exitcodes=0,2
stopsignal=TERM
stopwaitsecs=1
redirect_stderr=true
stdout_logfile={{ deploy_path }}/tmp/stdout.log
stdout_logfile_maxbytes=1MB
stdout_logfile_backups=10
13 changes: 13 additions & 0 deletions conf/uwsgi.ini
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
[uwsgi]
http = :9090
chdir = /home/the5fire/venvs/typeidea-env
home=/home/the5fire/venvs/typeidea-env
PYTHONHOME = /home/the5fire/venvs/typeidea-env/bin/

env = TYPEIDEA_PROFILE=product
wsgi-file = bin/wsgi.py
static-safe=/home/the5fire/venvs/typeidea-env/static_files/ ; 配置目录为安全目录,跳过uwsgi的secure检查
route = /static/(.*) static:/home/the5fire/venvs/typeidea-env/static_files/$1
processes = 4
threads = 2
; deamonize=1 ; 用来配置background运行的程序
110 changes: 110 additions & 0 deletions fabfile.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,110 @@
import os
from datetime import datetime

from fabric.api import (
env, run, prefix, local, settings,
roles,
)
from fabric.contrib.files import exists, upload_template
from fabric.decorators import task


env.roledefs = {
'myserver': ['the5fire@<ip>:22'],
}
env.PROJECT_NAME = 'typeidea'
env.SETTINGS_BASE = 'typeidea/typeidea/settings/base.py'
env.DEPLOY_PATH = '/home/the5fire/venvs/typeidea-env'
env.VENV_ACTIVATE = os.path.join(env.DEPLOY_PATH, 'bin', 'activate')
env.PYPI_HOST = '127.0.0.1'
env.PYPI_INDEX = 'http://{}:18080/simple'.format(env.PYPI_HOST)
env.PROCESS_COUNT = 2
env.PORT_PREFIX = 909


class _Version:
origin_record = {}

def replace(self, f, version):
with open(f, 'r') as fd:
origin_content = fd.read()
content = origin_content.replace('${version}', version)

with open(f, 'w') as fd:
fd.write(content)

self.origin_record[f] = origin_content

def set(self, file_list, version):
for f in file_list:
self.replace(f, version)

def revert(self):
for f, content in self.origin_record.items():
with open(f, 'w') as fd:
fd.write(content)


@task
def build(version=None):
""" 本地打包并且上传包到pypi上
1. 配置版本号
2. 打包并上传
"""
if not version:
version = datetime.now().strftime('%m%d%H%M%S') # 当前时间,月日时分秒

_version = _Version()
_version.set(['setup.py', env.SETTINGS_BASE], version)

with settings(warn_only=True):
local('python setup.py bdist_wheel upload -r internal')

_version.revert()


def _ensure_virtualenv():
if exists(env.VENV_ACTIVATE):
return True

if not exists(env.DEPLOY_PATH):
run('mkdir -p %s/tmp' % env.DEPLOY_PATH)

run('python3.6 -m venv %s' % env.DEPLOY_PATH)


def _reload_supervisoird(deploy_path, profile):
template_dir = 'conf'
filename = 'supervisord.conf'
destination = env.DEPLOY_PATH
context = {
'process_count': env.PROCESS_COUNT,
'port_prefix': env.PORT_PREFIX,
'profile': profile,
'deploy_path': deploy_path,
}
upload_template(filename, destination, context=context, use_jinja=True, template_dir=template_dir)
with settings(warn_only=True):
result = run('supervisorctl -c %s/supervisord.conf shutdown' % deploy_path)
if result:
run('supervisord -c %s/supervisord.conf' % deploy_path)


@task
@roles('myserver')
def deploy(version, profile):
""" 部署指定版本
1. 确认虚拟环境已经配置
2. 激活虚拟环境
3. 安装软件包
4. 启动
"""
_ensure_virtualenv()
package_name = env.PROJECT_NAME + '==' + version
with prefix('source %s' % env.VENV_ACTIVATE):
run('pip install %s -i %s --trusted-host %s' % (
package_name,
env.PYPI_INDEX,
env.PYPI_HOST,
))
_reload_supervisoird(env.DEPLOY_PATH, profile)
Loading