Skip to content

Instantly share code, notes, and snippets.

@moshen
Last active September 4, 2016 18:37
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save moshen/16c98e3f2dda3125b63d to your computer and use it in GitHub Desktop.
Save moshen/16c98e3f2dda3125b63d to your computer and use it in GitHub Desktop.
Openresty on Heroku Docker

Use the Heroku toolbelt docker plugin:

heroku docker:start

to run locally and:

heroku docker:release --app APPNAME

to release to heroku

FROM heroku/cedar:14
RUN useradd -d /app -m app
USER app
ENV HOME=/app PORT=3000 \
resty_version=1.7.10.2 rocks_version=2.1.2 \
STDOUT_PIPE="/app/openresty/nginx/logs/access" \
STDERR_PIPE="/app/openresty/nginx/logs/error"
# Install openresty
RUN SRCPATH="/app/src/ngx_openresty-${resty_version}" \
&& mkdir /app/src /app/bin \
&& curl -L "http://openresty.org/download/ngx_openresty-${resty_version}.tar.gz" \
| tar -xz -C "/app/src" \
&& cd "$SRCPATH" \
&& ./configure \
--prefix=/app/openresty \
--with-pcre-jit \
&& make && make install \
&& rm -r "$SRCPATH"
# Install luarocks
RUN SRCPATH="/app/src/luarocks-${rocks_version}" \
&& curl -L "http://luarocks.org/releases/luarocks-${rocks_version}.tar.gz" \
| tar -xz -C "/app/src" \
&& cd "$SRCPATH" \
&& ./configure --prefix=/app/openresty/luajit \
--with-lua=/app/openresty/luajit/ \
--lua-suffix=jit-2.1.0-alpha \
--with-lua-include=/app/openresty/luajit/include/luajit-2.1 \
&& make && make install \
&& rm -r "$SRCPATH"
# Install etlua
RUN BINPATH=/app/openresty/luajit/bin \
&& cd "$BINPATH" \
&& ln -s luajit-* lua \
&& PATH=$PATH:$BINPATH ./luarocks install etlua
COPY template-nginx.lua start-openresty.bash /app/bin/
COPY ./nginx.conf /app/src/
WORKDIR /app
EXPOSE 3000
ONBUILD COPY ./nginx.conf /app/src/
#user app;
worker_processes 1;
daemon off;
#error_log logs/error.log;
#error_log logs/error.log notice;
#error_log logs/error.log info;
error_log <%= os.getenv('STDERR_PIPE') %>;
#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;
access_log <%= os.getenv('STDOUT_PIPE') %> main;
sendfile on;
#tcp_nopush on;
#keepalive_timeout 0;
keepalive_timeout 65;
#gzip on;
server {
listen <%= os.getenv('PORT') %>;
server_name localhost;
#charset koi8-r;
#access_log logs/host.access.log main;
location / {
root html;
index index.html index.htm;
}
#error_page 404 /404.html;
# redirect server error pages to the static page /50x.html
#
error_page 500 502 503 504 /50x.html;
location = /50x.html {
root html;
}
# proxy the PHP scripts to Apache listening on 127.0.0.1:80
#
#location ~ \.php$ {
# proxy_pass http://127.0.0.1;
#}
# pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000
#
#location ~ \.php$ {
# root html;
# fastcgi_pass 127.0.0.1:9000;
# fastcgi_index index.php;
# fastcgi_param SCRIPT_FILENAME /scripts$fastcgi_script_name;
# include fastcgi_params;
#}
# deny access to .htaccess files, if Apache's document root
# concurs with nginx's one
#
#location ~ /\.ht {
# deny all;
#}
}
# another virtual host using mix of IP-, name-, and port-based configuration
#
#server {
# listen 8000;
# listen somename:8080;
# server_name somename alias another.alias;
# location / {
# root html;
# index index.html index.htm;
# }
#}
# HTTPS server
#
#server {
# listen 443 ssl;
# server_name localhost;
# ssl_certificate cert.pem;
# ssl_certificate_key cert.key;
# ssl_session_cache shared:SSL:1m;
# ssl_session_timeout 5m;
# ssl_ciphers HIGH:!aNULL:!MD5;
# ssl_prefer_server_ciphers on;
# location / {
# root html;
# index index.html index.htm;
# }
#}
}
web: /app/bin/start-openresty.bash
#!/bin/bash
mkfifo $STDOUT_PIPE $STDERR_PIPE
cat < $STDOUT_PIPE &
cat < $STDERR_PIPE >&2 &
/app/bin/template-nginx.lua < /app/src/nginx.conf > /app/openresty/nginx/conf/nginx.conf
exec /app/openresty/nginx/sbin/nginx
#!/app/openresty/luajit/bin/lua
-- Process templated files
--
-- stdin should be a conf file (like /app/src/nginx.conf)
local etlua = require "etlua"
print(etlua.render(io.stdin:read("*all")))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment