diff --git a/Dockerfile b/Dockerfile index c435f4a..04efcce 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,21 +1,17 @@ -FROM python:3.6.4 +FROM wuyue/python3-app:with_nginx MAINTAINER wuyue92tree@163.com -RUN cp /usr/share/zoneinfo/Asia/Shanghai /etc/localtime \ - && mkdir -p /data/src \ - && mkdir -p /data/logs +COPY . /data/src +COPY ./deploy.ini /etc/supervisor/conf.d/ +COPY ./_product/nginx.conf /usr/local/nginx/conf/nginx.conf -COPY ./requirements.txt /data/src -COPY ./manage.py /data/src +RUN pip install -r requirements.txt -i http://mirrors.aliyun.com/pypi/simple --trusted-host mirrors.aliyun.com \ + && pip install https://github.com/darklow/django-suit/tarball/v2 -WORKDIR /data/src +RUN python manage.py collectstatic --noinput -RUN pip install -r requirements.txt -i http://mirrors.aliyun.com/pypi/simple --trusted-host mirrors.aliyun.com\ - && pip install https://github.com/darklow/django-suit/tarball/v2 \ - && pip install git+https://github.com/Supervisor/supervisor +WORKDIR /data/src -EXPOSE 3031 EXPOSE 5555 EXPOSE 9001 - -CMD supervisord -nc /etc/supervisor/supervisor.conf \ No newline at end of file +EXPOSE 80 diff --git a/README.md b/README.md index c0df966..ba8dfd3 100644 --- a/README.md +++ b/README.md @@ -13,7 +13,7 @@ - python3.6+ -- django2.1.5 +- django2.2.1 ## 初始化 @@ -43,7 +43,9 @@ git clone https://github.com/wuyue92tree/rest_backend.git cd rest_backend -docker-compose up +docker build -t rest_backend . + +docker run -tid -v :/data/src/log -p 80:80 rest_backend ``` diff --git a/_product/nginx.conf b/_product/nginx.conf index 1dcee87..1dd0280 100644 --- a/_product/nginx.conf +++ b/_product/nginx.conf @@ -1,37 +1,57 @@ -server { - # the port your site will be served on - listen 80; - # the domain name it will serve for - server_name localhost; # substitute your machine's IP address or FQDN - charset utf-8; - - # access_log /data/logs/access_log; - # error_log /data/logs/error_log; - - # max upload size - client_max_body_size 75M; # adjust to taste - - # Django media - # location /media { - # alias /data/src/media; # your Django project's media files - amend as required - # } - - # location /media/images { - # autoindex on; - # autoindex_exact_size off; - # autoindex_localtime on; - # alias /data/src/static/media/images; # your Django project's media files - amend as required - #} - - location /static { - alias /data/src/static; # your Django project's static files - amend as required +#user nobody; +worker_processes 4; - } +#pid logs/nginx.pid; + +events { + worker_connections 1024; +} + + +http { + include 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 logs/access.log main; + + sendfile on; + #tcp_nopush on; + + #keepalive_timeout 0; + keepalive_timeout 65; + + #gzip on; + server { + # the port your site will be served on + listen 80; + # the domain name it will serve for + server_name localhost; # substitute your machine's IP address or FQDN + charset utf-8; + + access_log /data/src/log/access_log; + error_log /data/src/log/error_log; + + # max upload size + client_max_body_size 75M; # adjust to taste + + # Django media + location /media { + alias /data/src/media; # your Django project's media files - amend as required + } + + location /static { + alias /data/src/static; # your Django project's static files - amend as required - # Finally, send all non-media requests to the Django server. - location / { + } - uwsgi_pass rest_backend:3031; - include /etc/nginx/uwsgi_params; # the uwsgi_params file you installed + # Finally, send all non-media requests to the Django server. + location / { + uwsgi_pass 127.0.0.1:3031; + include /usr/local/nginx/conf/uwsgi_params; # the uwsgi_params file you installed + } } -} \ No newline at end of file +} diff --git a/_product/supervisor/supervisor.conf b/_product/supervisor/supervisor.conf deleted file mode 100644 index ea882bd..0000000 --- a/_product/supervisor/supervisor.conf +++ /dev/null @@ -1,153 +0,0 @@ -; Sample supervisor config file. -; -; For more information on the config file, please see: -; http://supervisord.org/configuration.html -; -; Notes: -; - Shell expansion ("~" or "$HOME") is not supported. Environment -; variables can be expanded using this syntax: "%(ENV_HOME)s". -; - Quotes around values are not supported, except in the case of -; the environment= options as shown below. -; - Comments must have a leading space: "a=b ;comment" not "a=b;comment". -; - Command will be truncated if it looks like a config file comment, e.g. -; "command=bash -c 'foo ; bar'" will truncate to "command=bash -c 'foo ". - -[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] ; inet (TCP) server disabled by default -port=0.0.0.0:9001 ; ip_address:port specifier, *:port for all iface -;username=user ; default is no username (open server) -;password=123 ; default is no password (open server) - -[supervisord] -logfile=/tmp/supervisord.log ; main log file; default $CWD/supervisord.log -logfile_maxbytes=50MB ; max main logfile bytes b4 rotation; default 50MB -logfile_backups=10 ; # of main logfile backups; 0 means none, default 10 -loglevel=info ; log level; default info; others: debug,warn,trace -pidfile=/tmp/supervisord.pid ; supervisord pidfile; default supervisord.pid -nodaemon=false ; start in foreground if true; default false -minfds=1024 ; min. avail startup file descriptors; default 1024 -minprocs=200 ; min. avail process descriptors;default 200 -;umask=022 ; process file creation umask; default 022 -;user=chrism ; default is current user, required if root -;identifier=supervisor ; supervisord identifier, default is 'supervisor' -;directory=/tmp ; default is not to cd during start -;nocleanup=true ; don't clean up tempfiles at start; default false -;childlogdir=/tmp ; 'AUTO' child log dir, default $TEMP -;environment=KEY="value" ; key value pairs to add to environment -;strip_ansi=false ; strip ansi escape codes in logs; def. false - -; The rpcinterface:supervisor section must remain in the config file for -; RPC (supervisorctl/web interface) to work. Additional interfaces may be -; added by defining them in separate [rpcinterface:x] sections. - -[rpcinterface:supervisor] -supervisor.rpcinterface_factory = supervisor.rpcinterface:make_main_rpcinterface - -; The supervisorctl section configures how supervisorctl will connect to -; supervisord. configure it match the settings in either the unix_http_server -; or inet_http_server section. - -[supervisorctl] -serverurl=unix:///tmp/supervisor.sock ; use a unix:// URL for a unix socket -;serverurl=http://127.0.0.1:9001 ; use an http:// url to specify an inet socket -;username=chris ; should be same as in [*_http_server] if set -;password=123 ; should be same as in [*_http_server] if set -;prompt=mysupervisor ; cmd line prompt (default "supervisor") -;history_file=~/.sc_history ; use readline history if available - -; The sample program section below shows all possible program subsection values. -; Create one or more 'real' program: sections to be able to control them under -; supervisor. - -;[program:theprogramname] -;command=/bin/cat ; the program (relative uses PATH, can take args) -;process_name=%(program_name)s ; process_name expr (default %(program_name)s) -;numprocs=1 ; number of processes copies to start (def 1) -;directory=/tmp ; directory to cwd to before exec (def no cwd) -;umask=022 ; umask for process (default None) -;priority=999 ; the relative start priority (default 999) -;autostart=true ; start at supervisord start (default: true) -;startsecs=1 ; # of secs prog must stay up to be running (def. 1) -;startretries=3 ; max # of serial start failures when starting (default 3) -;autorestart=unexpected ; when to restart if exited after running (def: unexpected) -;exitcodes=0 ; 'expected' exit codes used with autorestart (default 0) -;stopsignal=QUIT ; signal used to kill process (default TERM) -;stopwaitsecs=10 ; max num secs to wait b4 SIGKILL (default 10) -;stopasgroup=false ; send stop signal to the UNIX process group (default false) -;killasgroup=false ; SIGKILL the UNIX process group (def false) -;user=chrism ; setuid to this UNIX account to run the program -;redirect_stderr=true ; redirect proc stderr to stdout (default false) -;stdout_logfile=/a/path ; stdout log path, NONE for none; default AUTO -;stdout_logfile_maxbytes=1MB ; max # logfile bytes b4 rotation (default 50MB) -;stdout_logfile_backups=10 ; # of stdout logfile backups (0 means none, default 10) -;stdout_capture_maxbytes=1MB ; number of bytes in 'capturemode' (default 0) -;stdout_events_enabled=false ; emit events on stdout writes (default false) -;stdout_syslog=false ; send stdout to syslog with process name (default false) -;stderr_logfile=/a/path ; stderr log path, NONE for none; default AUTO -;stderr_logfile_maxbytes=1MB ; max # logfile bytes b4 rotation (default 50MB) -;stderr_logfile_backups=10 ; # of stderr logfile backups (0 means none, default 10) -;stderr_capture_maxbytes=1MB ; number of bytes in 'capturemode' (default 0) -;stderr_events_enabled=false ; emit events on stderr writes (default false) -;stderr_syslog=false ; send stderr to syslog with process name (default false) -;environment=A="1",B="2" ; process environment additions (def no adds) -;serverurl=AUTO ; override serverurl computation (childutils) - -; The sample eventlistener section below shows all possible eventlistener -; subsection values. Create one or more 'real' eventlistener: sections to be -; able to handle event notifications sent by supervisord. - -;[eventlistener:theeventlistenername] -;command=/bin/eventlistener ; the program (relative uses PATH, can take args) -;process_name=%(program_name)s ; process_name expr (default %(program_name)s) -;numprocs=1 ; number of processes copies to start (def 1) -;events=EVENT ; event notif. types to subscribe to (req'd) -;buffer_size=10 ; event buffer queue size (default 10) -;directory=/tmp ; directory to cwd to before exec (def no cwd) -;umask=022 ; umask for process (default None) -;priority=-1 ; the relative start priority (default -1) -;autostart=true ; start at supervisord start (default: true) -;startsecs=1 ; # of secs prog must stay up to be running (def. 1) -;startretries=3 ; max # of serial start failures when starting (default 3) -;autorestart=unexpected ; autorestart if exited after running (def: unexpected) -;exitcodes=0 ; 'expected' exit codes used with autorestart (default 0) -;stopsignal=QUIT ; signal used to kill process (default TERM) -;stopwaitsecs=10 ; max num secs to wait b4 SIGKILL (default 10) -;stopasgroup=false ; send stop signal to the UNIX process group (default false) -;killasgroup=false ; SIGKILL the UNIX process group (def false) -;user=chrism ; setuid to this UNIX account to run the program -;redirect_stderr=false ; redirect_stderr=true is not allowed for eventlisteners -;stdout_logfile=/a/path ; stdout log path, NONE for none; default AUTO -;stdout_logfile_maxbytes=1MB ; max # logfile bytes b4 rotation (default 50MB) -;stdout_logfile_backups=10 ; # of stdout logfile backups (0 means none, default 10) -;stdout_events_enabled=false ; emit events on stdout writes (default false) -;stdout_syslog=false ; send stdout to syslog with process name (default false) -;stderr_logfile=/a/path ; stderr log path, NONE for none; default AUTO -;stderr_logfile_maxbytes=1MB ; max # logfile bytes b4 rotation (default 50MB) -;stderr_logfile_backups=10 ; # of stderr logfile backups (0 means none, default 10) -;stderr_events_enabled=false ; emit events on stderr writes (default false) -;stderr_syslog=false ; send stderr to syslog with process name (default false) -;environment=A="1",B="2" ; process environment additions -;serverurl=AUTO ; override serverurl computation (childutils) - -; The sample group section below shows all possible group values. Create one -; or more 'real' group: sections to create "heterogeneous" process groups. - -;[group:thegroupname] -;programs=progname1,progname2 ; each refers to 'x' in [program:x] definitions -;priority=999 ; the relative start priority (default 999) - -; The [include] section can just contain the "files" setting. This -; setting can list multiple files (separated by whitespace or -; newlines). It can also contain wildcards. The filenames are -; interpreted as relative to this file. Included files *cannot* -; include files themselves. - -[include] -; files = relative/directory/*.ini -files = /etc/supervisor/conf.d/*.ini diff --git a/_product/supervisor/conf.d/rest_backend.ini b/deploy.ini similarity index 76% rename from _product/supervisor/conf.d/rest_backend.ini rename to deploy.ini index 19c854b..aed51a1 100644 --- a/_product/supervisor/conf.d/rest_backend.ini +++ b/deploy.ini @@ -1,55 +1,55 @@ [program:uwsgi] directory = /data/src ; 程序的启动目录 -command = uwsgi uwsgi.ini ; 启动命令,可以看出与手动在命令行启动的命令是一样的 +command = uwsgi /data/src/_product/uwsgi.ini ; 启动命令,可以看出与手动在命令行启动的命令是一样的 autostart = true ; 在 supervisord 启动的时候也自动启动 startsecs = 5 ; 启动 5 秒后没有异常退出,就当作已经正常启动了 autorestart = true ; 程序异常退出后自动重启 startretries = 3 ; 启动失败自动重试次数,默认是 3 -; user = wuyue ; 用哪个用户启动 +; user = root ; 用哪个用户启动 redirect_stderr = true ; 把 stderr 重定向到 stdout,默认 false stdout_logfile_maxbytes = 20MB ; stdout 日志文件大小,默认 50MB stdout_logfile_backups = 20 ; stdout 日志文件备份数 ; stdout 日志文件,需要注意当指定目录不存在时无法正常启动,所以需要手动创建目录(supervisord 会自动创建日志文件) -stdout_logfile = /data/logs/uwsgi.log +stdout_logfile = /data/src/log/uwsgi_stdout.log -[program:celery_flower] +[program:nginx] directory = /data/src ; 程序的启动目录 -command = celery -A rest_backend.settings.celery_product flower -l info ; 启动命令,可以看出与手动在命令行启动的命令是一样的 +command = /usr/local/nginx/sbin/nginx -g 'daemon off;' ; 启动命令,可以看出与手动在命令行启动的命令是一样的 autostart = true ; 在 supervisord 启动的时候也自动启动 startsecs = 5 ; 启动 5 秒后没有异常退出,就当作已经正常启动了 autorestart = true ; 程序异常退出后自动重启 startretries = 3 ; 启动失败自动重试次数,默认是 3 -; user = wuyue ; 用哪个用户启动 +; user = root ; 用哪个用户启动 redirect_stderr = true ; 把 stderr 重定向到 stdout,默认 false stdout_logfile_maxbytes = 20MB ; stdout 日志文件大小,默认 50MB stdout_logfile_backups = 20 ; stdout 日志文件备份数 ; stdout 日志文件,需要注意当指定目录不存在时无法正常启动,所以需要手动创建目录(supervisord 会自动创建日志文件) -stdout_logfile = /data/logs/celery_flower.log +stdout_logfile = /data/src/log/nginx_stdout.log -[program:celery_beat] +[program:celery_flower] directory = /data/src ; 程序的启动目录 -command = rm -f celerybeat.pid && celery -A rest_backend.settings.celery_product beat -l info ; 启动命令,可以看出与手动在命令行启动的命令是一样的 +command = celery -A rest_backend.settings.celery_product flower -l info --persistent=True --db=./db/flower ; 启动命令,可以看出与手动在命令行启动的命令是一样的 autostart = true ; 在 supervisord 启动的时候也自动启动 startsecs = 5 ; 启动 5 秒后没有异常退出,就当作已经正常启动了 autorestart = true ; 程序异常退出后自动重启 startretries = 3 ; 启动失败自动重试次数,默认是 3 -; user = wuyue ; 用哪个用户启动 +; user = root ; 用哪个用户启动 redirect_stderr = true ; 把 stderr 重定向到 stdout,默认 false stdout_logfile_maxbytes = 20MB ; stdout 日志文件大小,默认 50MB stdout_logfile_backups = 20 ; stdout 日志文件备份数 ; stdout 日志文件,需要注意当指定目录不存在时无法正常启动,所以需要手动创建目录(supervisord 会自动创建日志文件) -stdout_logfile = /data/logs/celery_beat.log +stdout_logfile = /data/src/log/celery_flower_stdout.log -[program:celery_worker] +[program:celery] directory = /data/src ; 程序的启动目录 -command = celery -A rest_backend.settings.celery_product worker -l info ; 启动命令,可以看出与手动在命令行启动的命令是一样的 +command = celery -A rest_backend.settings.celery_product worker -l info -B ; 启动命令,可以看出与手动在命令行启动的命令是一样的 autostart = true ; 在 supervisord 启动的时候也自动启动 startsecs = 5 ; 启动 5 秒后没有异常退出,就当作已经正常启动了 autorestart = true ; 程序异常退出后自动重启 startretries = 3 ; 启动失败自动重试次数,默认是 3 -; user = wuyue ; 用哪个用户启动 +; user = root ; 用哪个用户启动 redirect_stderr = true ; 把 stderr 重定向到 stdout,默认 false stdout_logfile_maxbytes = 20MB ; stdout 日志文件大小,默认 50MB stdout_logfile_backups = 20 ; stdout 日志文件备份数 ; stdout 日志文件,需要注意当指定目录不存在时无法正常启动,所以需要手动创建目录(supervisord 会自动创建日志文件) -stdout_logfile = /data/logs/celery_worker.log \ No newline at end of file +stdout_logfile = /data/src/log/celery_stdout.log \ No newline at end of file diff --git a/docker-compose.yml b/docker-compose.yml deleted file mode 100644 index 92d6702..0000000 --- a/docker-compose.yml +++ /dev/null @@ -1,25 +0,0 @@ -version: '3' -services: - rest_backend: - build: . - volumes: - - ./rest_backend:/data/src/rest_backend - - ./templates:/data/src/templates - - ./_product/uwsgi.ini:/data/src/uwsgi.ini - - ./_product/superviosr:/etc/supervisor - - ./static:/data/src/static - - ./media:/data/src/media - - ./db:/data/src/db - - ./logs:/data/logs - ports: - - '9001:9001' - - '5555:5555' - nginx: - image: nginx:latest - volumes: - - ./_product/nginx.conf:/etc/nginx/conf.d/default.conf - - ./static:/data/src/static - ports: - - '8088:80' - links: - - rest_backend \ No newline at end of file diff --git a/log/.gitkeep b/log/.gitkeep new file mode 100644 index 0000000..e69de29 diff --git a/requirements.txt b/requirements.txt index c7f7ba2..8706839 100644 --- a/requirements.txt +++ b/requirements.txt @@ -1,4 +1,5 @@ -Django==2.1.5 +Django==2.2.1 +django-celery-beat==1.3.0 django-cors-headers==2.2.0 django-debug-toolbar==1.9.1 django-rest-swagger==2.2.0 @@ -9,4 +10,5 @@ Pillow==5.1.0 uwsgi==2.0.15 redis==2.10.6 flower==0.9.2 +tornado==5.1.1 # https://github.com/darklow/django-suit/tarball/v2 \ No newline at end of file diff --git a/rest_backend/libs/accounts/__init__.py b/rest_backend/libs/accounts/__init__.py index e69de29..a33456d 100644 --- a/rest_backend/libs/accounts/__init__.py +++ b/rest_backend/libs/accounts/__init__.py @@ -0,0 +1 @@ +default_app_config = 'rest_backend.libs.accounts.apps.AccountsConfig' diff --git a/rest_backend/libs/accounts/apps.py b/rest_backend/libs/accounts/apps.py index 86ec631..4c7e362 100644 --- a/rest_backend/libs/accounts/apps.py +++ b/rest_backend/libs/accounts/apps.py @@ -1,7 +1,12 @@ from __future__ import unicode_literals from django.apps import AppConfig +# from django.utils.translation import gettext_lazy as _ + +__all__ = ['AccountsConfig'] class AccountsConfig(AppConfig): - name = 'accounts' + name = 'rest_backend.libs.accounts' + label = 'accounts' + verbose_name = '用户中心' diff --git a/rest_backend/settings/base.py b/rest_backend/settings/base.py index 7d49b75..d88ae12 100644 --- a/rest_backend/settings/base.py +++ b/rest_backend/settings/base.py @@ -135,7 +135,7 @@ # Internationalization # https://docs.djangoproject.com/en/2.1/topics/i18n/ -LANGUAGE_CODE = 'zh_hans' +LANGUAGE_CODE = 'zh-hans' TIME_ZONE = 'Asia/Shanghai' diff --git a/rest_backend/settings/product.py b/rest_backend/settings/product.py index 593fc8a..041680d 100644 --- a/rest_backend/settings/product.py +++ b/rest_backend/settings/product.py @@ -12,6 +12,8 @@ from .base import * +ALLOWED_HOSTS = ['*'] + DEBUG = False # celery