`
sillycat
  • 浏览: 2552525 次
  • 性别: Icon_minigender_1
  • 来自: 成都
社区版块
存档分类
最新评论

A Rate-Limiting HTTP Proxy(7)Docker and Deployment

 
阅读更多
A Rate-Limiting HTTP Proxy(7)Docker and Deployment

We plan to use sudo to run the command to start the nginx on port 80, we need to link the command first
>sudo ln -s /opt/openresty/nginx/sbin/nginx /usr/local/sbin/nginx

On MAC it works well, on RaspberryPI, it has this exception while running it
>sudo nginx -p /opt/luaweb/dist/app -c conf/nginx.conf
nginx: [emerg] getgrnam("owner") failed in /opt/luaweb/dist/app/conf/nginx.conf:1

Solution:
I change the nginx.conf and get rid of owner, it works.

After install the things, the URL for luarocks is as follow:
/tool/luarocks/lib/luarocks/rocks

The Makefile will build the binary and prepare the ENV.
IMAGE=sillycat/public
TAG=raspberrypi-openresty
NAME=raspberrypi-openresty

app-init:
rm -fr install
mkdir install
wget https://openresty.org/download/openresty-1.11.2.3.tar.gz -P install/
wget http://luarocks.github.io/luarocks/releases/luarocks-2.4.2.tar.gz -P install/

app-build:
./package.sh
tar -cvzf ./dist/$(NAME)-1.0.tgz ./luaweb-1.0

docker-context:

build: docker-context
docker build -t $(IMAGE):$(TAG) .

run:
docker run -d -p 80:80 --name $(NAME) $(IMAGE):$(TAG)

debug:
docker run -ti -p 80:80 --name $(NAME) $(IMAGE):$(TAG) /bin/bash

clean:
docker stop ${NAME}
docker rm ${NAME}

logs:
docker logs ${NAME}

publish:
docker push ${IMAGE}:${TAG}

fetch:
docker pull ${IMAGE}:${TAG}

And package.sh will help to binary the lua scripts
#!/usr/bin/env bash

rm -rf ./luaweb-1.0
mkdir -p luaweb-1.0/logs
mkdir -p luaweb-1.0/conf
cp -rf conf/nginx-prod.conf luaweb-1.0/conf/nginx.conf
cp -rf html luaweb-1.0
cp -rf lua luaweb-1.0
cp -rf lualib luaweb-1.0

luajit=/opt/openresty/luajit/bin/luajit

function compile() {
    for file in $1
    do
        if test -f $file
        then
            $luajit -b $file $file
        fi
    done
}

compile "./luaweb-1.0/lua/web/*"
compile "./luaweb-1.0/lua/*"

Dockerfile will describe all the steps to set up image
#Set up nginx in Docker

#Prepre the OS
FROM resin/rpi-raspbian:jessie
MAINTAINER Carl Luo <luohuazju@gmail.com>

ENV DEBIAN_FRONTEND noninteractive
RUN apt-get -y update
RUN apt-get install -y apt-utils
RUN apt-get -y dist-upgrade
RUN apt-get install -y build-essential gcc make
RUN apt-get install -y libpcre3 libpcre3-dev zlib1g-dev libgcrypt11-dev
RUN apt-get install -y libssl-dev wget unzip

#install
RUN     mkdir -p /tool
RUN     mkdir -p /install

#install openresty
ADDinstall/openresty-1.11.2.3.tar.gz /install/
WORKDIR /install/openresty-1.11.2.3
RUN./configure --prefix=/tool/openresty
RUN     make
RUN     make install

#install luarocks
ADDinstall/luarocks-2.4.2.tar.gz /install/
WORKDIR /install/luarocks-2.4.2
RUN./configure --with-lua="/tool/openresty/luajit" --lua-suffix="jit" --with-lua-include="/tool/openresty/luajit/include/luajit-2.1"
RUNmake build
RUNmake install

#install dependencies
RUNluarocks install md5

#install app
RUNmkdir -p /share/
ADDdist/raspberrypi-openresty-1.0.tgz /share/

#start the application
EXPOSE  80
RUN     mkdir -p /app/
ADD     start.sh /app/
WORKDIR /app/
CMD[ "./start.sh" ]

RUN ln -sf /dev/stdout /share/luaweb-1.0/logs/access.log
RUN ln -sf /dev/stderr /share/luaweb-1.0/logs/error.log

start.sh is the trigger to start the nginx service
#!/bin/sh -ex

cd /share/luaweb-1.0
/tool/openresty/nginx/sbin/nginx -p /share/luaweb-1.0 -c /share/luaweb-1.0/conf/nginx.conf -g "daemon off;"


References:
Previous Note
http://sillycat.iteye.com/blog/2374164
http://sillycat.iteye.com/blog/2374929
http://sillycat.iteye.com/blog/2374930
http://sillycat.iteye.com/blog/2375094
http://sillycat.iteye.com/blog/2375230
http://sillycat.iteye.com/blog/2376670

http://www.ulos.pl/-configure-error-ssl-modules-require-the-openssl-library
https://serverfault.com/questions/657863/nginx-how-to-use-docker-log-collector-when-nginx-is-running-under-supervisord

分享到:
评论

相关推荐

Global site tag (gtag.js) - Google Analytics