From b543d5f08a74916f6901096dfbdeb2fc26a9b249 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=B6=B5=E6=9B=A6?= Date: Fri, 14 Feb 2020 15:52:59 +0800 Subject: [PATCH] support docker-compose --- Dockerfile | 18 +++++ README.md | 7 ++ app/config/config.lua | 154 +++++++++++++++++++++--------------------- conf/nginx-dev.conf | 13 ++-- conf/nginx-prod.conf | 13 ++-- docker-compose.yml | 28 ++++++++ entrypoint.sh | 9 +++ init.sh | 11 +++ 8 files changed, 166 insertions(+), 87 deletions(-) create mode 100644 Dockerfile create mode 100644 docker-compose.yml create mode 100644 entrypoint.sh create mode 100644 init.sh diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 0000000..d1fd087 --- /dev/null +++ b/Dockerfile @@ -0,0 +1,18 @@ +FROM openresty/openresty:centos + +LABEL maintainer="hanxi " + +RUN yum install -y mysql +RUN yum install -y libuuid-devel +RUN /usr/local/openresty/bin/opm get sumory/lor + +ADD . /orchina +WORKDIR /orchina + +ADD ./init.sh / +RUN chmod +x /init.sh + +ADD ./entrypoint.sh / +RUN chmod +x /entrypoint.sh +CMD ["/entrypoint.sh"] + diff --git a/README.md b/README.md index afee1fc..a66c5e4 100644 --- a/README.md +++ b/README.md @@ -10,6 +10,13 @@ ![首页](./docs/index.jpg) +### 采用 Docker 运行 + +```bash +$ docker-composer up --build -d +$ docker-compose run orchina /init.sh +``` + ### 安装 - 首先安装OpenResty和[lor](https://github.com/sumory/lor)框架,安装成功的标志是以下三个命令可以正常输出 diff --git a/app/config/config.lua b/app/config/config.lua index 8ac1b52..f37718f 100644 --- a/app/config/config.lua +++ b/app/config/config.lua @@ -1,80 +1,80 @@ return { - -- 白名单配置:不需要登录即可访问;除非要二次开发,否则不应更改 - whitelist = { - "^/m1", - "^/m2", - - "^/index$", - "^/ask$", - "^/share$", - "^/category/[0-9]+$", - "^/topics/all$", - "^/topic/[0-9]+/view$", - "^/topic/[0-9]+/query$", - - "^/comments/all$", - - "^/user/[0-9a-zA-Z-_]+/index$", - "^/user/[0-9a-zA-z-_]+/topics$", - "^/user/[0-9a-zA-z-_]+/collects$", - "^/user/[0-9a-zA-z-_]+/comments$", - "^/user/[0-9a-zA-z-_]+/follows$", - "^/user/[0-9a-zA-z-_]+/fans$", - "^/user/[0-9a-zA-z-_]+/hot_topics$", - "^/user/[0-9a-zA-z-_]+/like_topics$", - - "^/auth/login$", -- login page - "^/auth/sign_up$", -- sign up page - "^/about$", -- about page - "^/error/$" -- error page - }, - - -- 静态模板配置,保持默认不修改即可 - view_config = { - engine = "tmpl", - ext = "html", - views = "./app/views" - }, - - - -- 分页时每页条数配置 - page_config = { - index_topic_page_size = 10, -- 首页每页文章数 - topic_comment_page_size = 20, -- 文章详情页每页评论数 - notification_page_size = 10, -- 通知每页个数 - }, - - - - -- ########################## 以下配置需要使用者自定义为本地需要的配置 ########################## -- - - -- 生成session的secret,请一定要修改此值为一复杂的字符串,用于加密session - session_secret = "12345678", -- lua-resty-string: salt must be 8 characters or nil - - -- 用于存储密码的盐,请一定要修改此值, 一旦使用不能修改,用户也可自行实现其他密码方案 - pwd_secret = "salt_secret_for_password", - - -- mysql配置 - mysql = { - timeout = 5000, - connect_config = { - host = "127.0.0.1", - port = 3306, - database = "blog", - user = "root", - password = "", - max_packet_size = 1024 * 1024 - }, - pool_config = { - max_idle_timeout = 20000, -- 20s - pool_size = 50 -- connection pool size - } - }, - - - -- 上传文件配置,如上传的头像、文章中的图片等 - upload_config = { - dir = "/data/openresty-china/static", -- 文件目录,修改此值时须同时修改nginx配置文件中的$static_files_path值 - }, + -- 白名单配置:不需要登录即可访问;除非要二次开发,否则不应更改 + whitelist = { + "^/m1", + "^/m2", + + "^/index$", + "^/ask$", + "^/share$", + "^/category/[0-9]+$", + "^/topics/all$", + "^/topic/[0-9]+/view$", + "^/topic/[0-9]+/query$", + + "^/comments/all$", + + "^/user/[0-9a-zA-Z-_]+/index$", + "^/user/[0-9a-zA-z-_]+/topics$", + "^/user/[0-9a-zA-z-_]+/collects$", + "^/user/[0-9a-zA-z-_]+/comments$", + "^/user/[0-9a-zA-z-_]+/follows$", + "^/user/[0-9a-zA-z-_]+/fans$", + "^/user/[0-9a-zA-z-_]+/hot_topics$", + "^/user/[0-9a-zA-z-_]+/like_topics$", + + "^/auth/login$", -- login page + "^/auth/sign_up$", -- sign up page + "^/about$", -- about page + "^/error/$" -- error page + }, + + -- 静态模板配置,保持默认不修改即可 + view_config = { + engine = "tmpl", + ext = "html", + views = "./app/views" + }, + + + -- 分页时每页条数配置 + page_config = { + index_topic_page_size = 10, -- 首页每页文章数 + topic_comment_page_size = 20, -- 文章详情页每页评论数 + notification_page_size = 10, -- 通知每页个数 + }, + + + + -- ########################## 以下配置需要使用者自定义为本地需要的配置 ########################## -- + + -- 生成session的secret,请一定要修改此值为一复杂的字符串,用于加密session + session_secret = "12345678", -- lua-resty-string: salt must be 8 characters or nil + + -- 用于存储密码的盐,请一定要修改此值, 一旦使用不能修改,用户也可自行实现其他密码方案 + pwd_secret = "salt_secret_for_password", + + -- mysql配置 + mysql = { + timeout = 5000, + connect_config = { + host = "ormysql", + port = 3306, + database = "orchina", + user = "orchina", + password = "orchina", + max_packet_size = 1024 * 1024 + }, + pool_config = { + max_idle_timeout = 20000, -- 20s + pool_size = 50 -- connection pool size + } + }, + + + -- 上传文件配置,如上传的头像、文章中的图片等 + upload_config = { + dir = "/data/openresty-china/static", -- 文件目录,修改此值时须同时修改nginx配置文件中的$static_files_path值 + }, } diff --git a/conf/nginx-dev.conf b/conf/nginx-dev.conf index 46647ce..4b6a793 100644 --- a/conf/nginx-dev.conf +++ b/conf/nginx-dev.conf @@ -1,5 +1,5 @@ #generated by `lor framework` - + pid tmp/nginx.pid; worker_processes 4; events { @@ -21,15 +21,18 @@ http { lua_code_cache on; # set off for development; session will lost if set off. #LUA_SHARED_DICT - + server { + resolver local=on ipv6=off; + resolver_timeout 5s; + listen 8888; #server_name openresty-china.com; set $template_root ''; # 用户上传的静态文件目录 set $static_files_path "/data/openresty-china/static"; - + # 头像和文章、评论图片 location /static/avatar { alias $static_files_path; @@ -55,7 +58,7 @@ http { alias ./app/static/libs; } - + # Access log with buffer, or disable it completetely if unneeded access_log logs/dev-access.log combined buffer=16k; # Error log @@ -68,4 +71,4 @@ http { } } - + diff --git a/conf/nginx-prod.conf b/conf/nginx-prod.conf index b31e138..92b0d2d 100644 --- a/conf/nginx-prod.conf +++ b/conf/nginx-prod.conf @@ -1,5 +1,5 @@ #generated by `lor framework` - + pid tmp/nginx.pid; worker_processes 4; events { @@ -21,15 +21,18 @@ http { lua_code_cache on; # set on @production #LUA_SHARED_DICT - + server { + resolver local=on ipv6=off; + resolver_timeout 5s; + listen 80; #server_name openresty-china.com; set $template_root ''; # 用户上传的静态文件目录 set $static_files_path "/data/openresty-china/static"; - + # 头像和文章、评论图片 location /static/avatar { alias $static_files_path; @@ -55,7 +58,7 @@ http { alias ./app/static/libs; } - + # Access log with buffer, or disable it completetely if unneeded access_log logs/prod-access.log combined buffer=16k; # Error log @@ -68,4 +71,4 @@ http { } } - \ No newline at end of file + diff --git a/docker-compose.yml b/docker-compose.yml new file mode 100644 index 0000000..8a13c04 --- /dev/null +++ b/docker-compose.yml @@ -0,0 +1,28 @@ +version: '2' + +services: + ormysql: + image: mysql:5 + restart: always + container_name: ormysql + environment: + - MYSQL_ROOT_PASSWORD=ormysqlroot + - MYSQL_DATABASE=orchina + - MYSQL_USER=orchina + - MYSQL_PASSWORD=orchina + volumes: + - ../ormysql/:/var/lib/mysql + + orchina: + build: + context: ./ + dockerfile: Dockerfile + container_name: orchina + ports: + - "2606:8888" + volumes: + - /etc/localtime:/etc/localtime:ro + - /etc/timezone:/etc/timezone:ro + - ../upload:/data/openresty-china/static + - ../logs:/orchina/logs + diff --git a/entrypoint.sh b/entrypoint.sh new file mode 100644 index 0000000..2b68c80 --- /dev/null +++ b/entrypoint.sh @@ -0,0 +1,9 @@ +#!/bin/sh + +if [ -z "$PROFILE" ];then + PROFILE="dev" +fi + +mkdir -p logs & mkdir -p tmp +echo "Use profile: "${PROFILE} +nginx -p `pwd`/ -c conf/nginx-${PROFILE}.conf -g 'daemon off;' diff --git a/init.sh b/init.sh new file mode 100644 index 0000000..83e8752 --- /dev/null +++ b/init.sh @@ -0,0 +1,11 @@ +#!/bin/sh + +# usage +# docker-compose run orchina /init.sh + +# import sql +mysql -h ormysql -u orchina -porchina -D orchina < /orchina/install/blog.sql + +# copy avatar +cp /orchina/install/avatar/* /data/openresty-china/static/ +