Poke backends through into static apps.

I've written this up to use a heroku-specific config file (`backends.yml`,
which is optional) rather than nginx config so that in principle we can move it
to implementations other than nginx.
parent 73a37261
...@@ -14,6 +14,8 @@ nginx_tarball_url="https://s3-external-1.amazonaws.com/heroku-buildpack-ruby/ngi ...@@ -14,6 +14,8 @@ nginx_tarball_url="https://s3-external-1.amazonaws.com/heroku-buildpack-ruby/ngi
mkdir -p $build_dir/bin mkdir -p $build_dir/bin
curl -L $nginx_tarball_url | tar xzv -C $build_dir/bin curl -L $nginx_tarball_url | tar xzv -C $build_dir/bin
nginx_version=$($build_dir/bin/nginx-$STACK -V 2>&1 | head -1 | awk '{ print $NF }') nginx_version=$($build_dir/bin/nginx-$STACK -V 2>&1 | head -1 | awk '{ print $NF }')
cp -a $bp_dir/scripts/boot $build_dir/bin/boot
cp -a $bp_dir/scripts/config $build_dir/bin/config
echo "-----> Installed ${nginx_version} to /app/bin" echo "-----> Installed ${nginx_version} to /app/bin"
mkdir -p $build_dir/config mkdir -p $build_dir/config
......
...@@ -5,5 +5,5 @@ cat <<EOF ...@@ -5,5 +5,5 @@ cat <<EOF
--- ---
addons: [] addons: []
default_process_types: default_process_types:
web: erb config/nginx.conf.erb > config/nginx.conf && bin/nginx -p . -c config/nginx.conf web: bin/boot
EOF EOF
...@@ -25,9 +25,15 @@ http { ...@@ -25,9 +25,15 @@ http {
client_body_timeout 5; client_body_timeout 5;
server { server {
listen <%= ENV["PORT"] %>; listen <%= port %>;
server_name _; server_name _;
keepalive_timeout 5; keepalive_timeout 5;
root public/; root public/;
<% backends.each do |backend| %>
location <%= backend['mount_point'] %> {
proxy_pass <%= backend['url'] %>;
}
<% end %>
} }
} }
#!/bin/bash -e
HERE=$(dirname "$0")
"${HERE}/config/make-config" && "${HERE}/nginx" -p . -c config/nginx.conf
\ No newline at end of file
#!/usr/bin/env ruby
TEMPLATE = 'config/nginx.conf.erb'
BACKENDS = 'backends.yml'
CONFIG = 'config/nginx.conf'
require 'erb'
require 'yaml'
def port
ENV['PORT'] || 5000
end
def backends
YAML.load(File.read(BACKENDS))
rescue Errno::ENOENT
[]
end
erb = ERB.new(File.read(TEMPLATE))
File.write(CONFIG, erb.result(binding))
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment