Skip to content

Commit

Permalink
整合rest+lua-template
Browse files Browse the repository at this point in the history
  • Loading branch information
supermy committed Jul 3, 2015
1 parent 7256ce8 commit b3d5239
Show file tree
Hide file tree
Showing 19 changed files with 1,162 additions and 59 deletions.
5 changes: 5 additions & 0 deletions build.sh
Original file line number Diff line number Diff line change
@@ -1,9 +1,14 @@
#!/usr/bin/env bash
# 通用工具构造
cd common
sh build.sh
cd ..

#分布式系统build
docker build -t supermy/docker-mongodb:3.0.4 /Users/moyong/project/env-myopensource/3-tools/mytools/mymongodb/base/
docker build -t supermy/docker-mynginx:2.1 /Users/moyong/project/env-myopensource/3-tools/mytools/web+app/mynginx/
docker build -t supermy/docker-mytomcat:7 /Users/moyong/project/env-myopensource/3-tools/mytools/web+app/mytomcat/

cd /Users/moyong/project/env-myopensource/mytools/web+app/mynginx
fig stop && fig rm --force -v && fig build

Expand Down
6 changes: 3 additions & 3 deletions common/build.sh
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
#!/usr/bin/env bash
docker build -t supermy/docker-docker-debian:7 mydebian
docker build -t supermy/docker-docker-jre:7 myjre7
docker build -t supermy/docker-debian:7 mydebian
docker build -t supermy/docker-jre:7 myjre7
docker build -t supermy/docker-jdk:7 myjava7
docker build -t supermy/docker-solr:4.10.2 mysolr

docker build -t supermy/docker-kafka:0.8 mykafka

docker build -t supermy/docker-rabbitmq_base:3.5 myrabbitmq
docker build -t supermy/docker-rabbitmq-base:3.5 myrabbitmq
docker build -t supermy/docker-rabbitmq:3.5 myrabbitmq/rabbitmq

docker build -t supermy/docker-myflume:latest myflume
Expand Down
12 changes: 5 additions & 7 deletions common/mydebian/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
FROM debian:latest
FROM debian:7.8

#2015-01-24修订,中文语言
MAINTAINER supermy <[email protected]>
Expand All @@ -12,6 +12,7 @@ MAINTAINER supermy <[email protected]>
# deb-src http://mirrors.163.com/debian/ wheezy main non-free contrib \n \
# deb-src http://mirrors.163.com/debian/ wheezy-proposed-updates main contrib non-free \n \
# deb-src http://mirrors.163.com/debian-security/ wheezy/updates main contrib non-free \n \
# \
# ' /etc/apt/sources.list

#
Expand All @@ -22,13 +23,10 @@ MAINTAINER supermy <[email protected]>
# deb-src http://ftp.sjtu.edu.cn/debian/ wheezy-proposed-updates main contrib non-free \n \
# deb-src http://ftp.sjtu.edu.cn/debian-security/ wheezy/updates main contrib non-free \n \

RUN cat /etc/apt/sources.list
#RUN cat /etc/apt/sources.list


RUN apt-get -y update
#&& apt-get -y upgrade

RUN apt-get install -qq -y curl wget sudo
RUN apt-get -y update && apt-get install -qq -y curl wget sudo

RUN apt-get -y install locales && \
sed -i 's/# zh_CN.UTF-8 UTF-8/zh_CN.UTF-8 UTF-8/' /etc/locale.gen && \
Expand Down Expand Up @@ -80,4 +78,4 @@ ENV LANG zh_CN.UTF-8
ENV LANGUAGE zh_CN:zh

#userage
#docker build -t supermy/docker-debian:7 mydebian
#docker build -t supermy/docker-debian:7 mydebian
2 changes: 2 additions & 0 deletions mymongodb/base/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@ FROM supermy/docker-debian:7
# add our user and group first to make sure their IDs get assigned consistently, regardless of whatever dependencies get added
RUN groupadd -r mongodb && useradd -r -g mongodb mongodb

#RUN export http_proxy=http://172.16.71.25:8087

RUN apt-get update \
&& apt-get install -y --no-install-recommends \
ca-certificates curl \
Expand Down
10 changes: 10 additions & 0 deletions web+app/README.log
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
2015-07-03
lua+template 与 spring-data-rest 完成整合;
http://192.168.59.103/channel-manage?page=0&start=0&size=15

todo 翻页函数

lua 模板引擎,好用得令人发指
https://github.com/bungle/lua-resty-template
lua 的url 调用类,好用得令人发指
https://github.com/pintsized/lua-resty-http
1 change: 1 addition & 0 deletions web+app/build.sh
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
#!/usr/bin/env bash
docker build -t supermy/docker-mynginx:2.1 mynginx
docker build -t supermy/docker-mytomcat:7 mytomcat
4 changes: 2 additions & 2 deletions web+app/fig.yml
Original file line number Diff line number Diff line change
Expand Up @@ -93,11 +93,11 @@ db:
MYSQL_DATABASE: javatest
MYSQL_ROOT_PASSWORD: mysql
ports:
- "3306"
- "3306:3306"

dbinit:
image: supermy/docker-mysql:latest
entrypoint: /bin/bash
#entrypoint: "/bin/bash"
volumes:
- .:/host
command: -c "sleep 8; mysql -u java --password=java -h mysql javatest < /host/mysql/init.sql; exit 0"
Expand Down
33 changes: 19 additions & 14 deletions web+app/mynginx/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,18 +1,21 @@
FROM debian:latest
#latest=8.1 wheezy=7.8
FROM debian:7.8
#FROM supermy/docker-debian:7


MAINTAINER supermy <[email protected]>

#RUN sed -i '1,3d' /etc/apt/sources.list
#RUN echo '#hello'>> /etc/apt/sources.list
RUN sed -i '1,3d' /etc/apt/sources.list
RUN echo '#hello'>> /etc/apt/sources.list

#RUN sed -i '1a \
# deb http://mirrors.163.com/debian/ wheezy main non-free contrib \n \
# deb http://mirrors.163.com/debian/ wheezy-proposed-updates main contrib non-free \n \
# deb http://mirrors.163.com/debian-security/ wheezy/updates main contrib non-free \n \
# deb-src http://mirrors.163.com/debian/ wheezy main non-free contrib \n \
# deb-src http://mirrors.163.com/debian/ wheezy-proposed-updates main contrib non-free \n \
# deb-src http://mirrors.163.com/debian-security/ wheezy/updates main contrib non-free \n \
# ' /etc/apt/sources.list
RUN sed -i '1a \
deb http://mirrors.163.com/debian/ wheezy main non-free contrib \n \
deb http://mirrors.163.com/debian/ wheezy-proposed-updates main contrib non-free \n \
deb http://mirrors.163.com/debian-security/ wheezy/updates main contrib non-free \n \
deb-src http://mirrors.163.com/debian/ wheezy main non-free contrib \n \
deb-src http://mirrors.163.com/debian/ wheezy-proposed-updates main contrib non-free \n \
deb-src http://mirrors.163.com/debian-security/ wheezy/updates main contrib non-free \n \
' /etc/apt/sources.list

# sohu 更新服务器:
#RUN sed -i '1a \
Expand Down Expand Up @@ -52,9 +55,11 @@ WORKDIR /tmp
RUN wget http://luajit.org/download/LuaJIT-2.0.4.tar.gz
RUN wget http://www.kyne.com.au/~mark/software/download/lua-cjson-2.1.0.tar.gz

#RUN export http_proxy=http://10.77.45.191:8087
RUN wget http://openresty.org/download/ngx_openresty-1.7.10.1.tar.gz
RUN wget http://labs.frickle.com/files/ngx_cache_purge-2.3.tar.gz
#RUN export http_proxy=http://172.16.71.25:8087
RUN wget -e http_proxy=172.16.71.25:8087 http://openresty.org/download/ngx_openresty-1.7.10.1.tar.gz
#RUN wget http://openresty.org/download/ngx_openresty-1.7.10.1.tar.gz
RUN wget -e http_proxy=172.16.71.25:8087 http://labs.frickle.com/files/ngx_cache_purge-2.3.tar.gz
#RUN wget http://labs.frickle.com/files/ngx_cache_purge-2.3.tar.gz


# mysql depends bit ,不兼容lua-5.3.0 ,兼容lua-5.2.0
Expand Down
6 changes: 6 additions & 0 deletions web+app/mynginx/nginx.d/channel.conf
Original file line number Diff line number Diff line change
@@ -1,3 +1,9 @@
#location /channel_auth {
# proxy_pass http://172.16.71.25:8080/channel_auth/;
# root /data/www;
# index index.html index.htm index.jsp;
#
#}
location /channel-manage {
default_type "text/html";
content_by_lua_file /usr/local/nginx/conf/nginx.d/lua/channel-manage.lua;
Expand Down
105 changes: 88 additions & 17 deletions web+app/mynginx/nginx.d/lua/channel-manage.lua
Original file line number Diff line number Diff line change
@@ -1,24 +1,95 @@
local args = ngx.req.get_uri_args()
--local args = ngx.req.get_post_args()
local myargs = ''

local function isempty(s)
return s == nil or s == '' or s == ngx.null
end

for key, val in pairs(args) do
-- if type(val) == "table" then
-- ngx.say(key, ": ", table.concat(val, ", "))
-- else
-- ngx.say(key, ": ", val)
-- end
if isempty(myargs) then

else
myargs=myargs.."&"
end
myargs=myargs..key.."="..val;

end

-- ngx.say(myargs);

local http = require "resty.http"

local httpc = http.new()
local res, err = httpc:request_uri("http://192.168.0.121:8080/channel_auth/filter?"..myargs, {
method = "GET",
body = myargs,
headers = {
["Content-Type"] = "application/x-www-form-urlencoded",
}
})

if not res then
ngx.say("failed to request: ", err)
return
end

-- In this simple form, there is no manual connection step, so the body is read
-- all in one go, including any trailers, and the connection closed or keptalive
-- for you.

ngx.status = res.status

for k,v in pairs(res.headers) do
--
end

--ngx.say(res.body);

local jsonvalue=cjson.decode(res.body);
--
--ngx.say("================");
--
--for name, value in pairs(jsonvalue._embedded.channel_auth[1]) do
-- ngx.say(name);
-- ngx.say(cjson.encode(value));
---- for name, value in pairs(value) do
---- ngx.say(name);
---- end
--end



local template = require "resty.template"


template.render("channel-list.html", {
channels = jsonvalue._embedded.channel_auth ,
page = jsonvalue.page
})

--模板嵌套的例子
--id/name/code/pwd/token/token_expire/iplist/ip_bind_time/ip_time_out/connect_count/limit_bandwidth/status/
template.render("channel-list.html", { channels = {
{id=1,name = "Jane", code = "1001" ,pwd="asdfkjs;dlkfjqwer",token_expire="10",
iplist="192.168.59.3",
ip_bind_time=60,ip_time_out=60,connect_count=300,limit_bandwidth="10M",status=1},
{id=1,name = "Jane", code = "1001" ,pwd="asdfkjs;dlkfjqwer",token_expire="10",
iplist="192.168.59.3",
ip_bind_time=60,ip_time_out=60,connect_count=300,limit_bandwidth="10M",status=1},
{id=1,name = "Jane", code = "1001" ,pwd="asdfkjs;dlkfjqwer",token_expire="10",
iplist="192.168.59.3",
ip_bind_time=60,ip_time_out=60,connect_count=300,limit_bandwidth="10M",status=1},
{id=1,name = "Jane", code = "1001" ,pwd="asdfkjs;dlkfjqwer",token_expire="10",
iplist="192.168.59.3",
ip_bind_time=60,ip_time_out=60,connect_count=300,limit_bandwidth="10M",status=1},
{id=1,name = "Jane", code = "1001" ,pwd="asdfkjs;dlkfjqwer",token_expire="10",
iplist="192.168.59.3",
ip_bind_time=60,ip_time_out=60,connect_count=300,limit_bandwidth="10M",status=1}
}})
--template.render("channel-list-test.html", { channels = {
-- {id=1,name = "Jane", code = "1001" ,pwd="asdfkjs;dlkfjqwer",token_expire="10",
-- iplist="192.168.59.3",
-- ip_bind_time=60,ip_time_out=60,connect_count=300,limit_bandwidth="10M",status=1},
-- {id=1,name = "Jane", code = "1001" ,pwd="asdfkjs;dlkfjqwer",token_expire="10",
-- iplist="192.168.59.3",
-- ip_bind_time=60,ip_time_out=60,connect_count=300,limit_bandwidth="10M",status=1},
-- {id=1,name = "Jane", code = "1001" ,pwd="asdfkjs;dlkfjqwer",token_expire="10",
-- iplist="192.168.59.3",
-- ip_bind_time=60,ip_time_out=60,connect_count=300,limit_bandwidth="10M",status=1},
-- {id=1,name = "Jane", code = "1001" ,pwd="asdfkjs;dlkfjqwer",token_expire="10",
-- iplist="192.168.59.3",
-- ip_bind_time=60,ip_time_out=60,connect_count=300,limit_bandwidth="10M",status=1},
-- {id=1,name = "Jane", code = "1001" ,pwd="asdfkjs;dlkfjqwer",token_expire="10",
-- iplist="192.168.59.3",
-- ip_bind_time=60,ip_time_out=60,connect_count=300,limit_bandwidth="10M",status=1}
--}})

Loading

0 comments on commit b3d5239

Please sign in to comment.