From 28d1a580cfc2034f1c77ae02dfc9e1e7b4701aa9 Mon Sep 17 00:00:00 2001 From: Jose Diaz-Gonzalez Date: Tue, 20 Sep 2016 00:18:28 -0600 Subject: [PATCH] Move to supporting sigil templates by default --- README.md | 2 +- bin/compile | 20 ++++++++++++++------ conf/{nginx.conf.erb => nginx.conf.sigil} | 10 +++++----- 3 files changed, 20 insertions(+), 12 deletions(-) rename conf/{nginx.conf.erb => nginx.conf.sigil} (69%) diff --git a/README.md b/README.md index 0eaf15d..598bd4d 100644 --- a/README.md +++ b/README.md @@ -25,7 +25,7 @@ heroku buildpacks:set https://github.com/dokku/buildpack-nginx.git You can override the nginx root via setting the `NGINX_ROOT` environment variable. This should be a relative path in your repository. -You may completely override the built-in nginx config by placing an `nginx.conf.erb` file in the root, modeled after our own [`conf/nginx.config.erb`](https://github.com/dokku/buildpack-nginx/blob/master/conf/nginx.conf.erb). This will be used inside of the container, and not by the host Dokku instance. +You may completely override the built-in nginx config by placing an `nginx.conf.sigil` file in the root, modeled after our own [`conf/nginx.config.sigil`](https://github.com/dokku/buildpack-nginx/blob/master/conf/nginx.conf.sigil). This will be used inside of the container, and not by the host Dokku instance. See the [sigil project](https://github.com/gliderlabs/sigil) for more information concerning the sigil format. ## Credits and License diff --git a/bin/compile b/bin/compile index 245b758..6f3b29b 100755 --- a/bin/compile +++ b/bin/compile @@ -31,6 +31,7 @@ if [[ ! -e "$BUILD_DIR/www" ]]; then # Check for a copy the nginx conf file override to the build dir [[ -f "$BUILD_DIR/www/nginx.conf.erb" ]] && mv $BUILD_DIR/www/nginx.conf.erb $BUILD_DIR [[ -f "$BUILD_DIR/www/nginx.conf.sigil" ]] && mv $BUILD_DIR/www/nginx.conf.sigil $BUILD_DIR + [[ -f "$BUILD_DIR/www/app-nginx.conf.sigil" ]] && mv $BUILD_DIR/www/app-nginx.conf.sigil $BUILD_DIR [[ -f "$BUILD_DIR/www/mime.types" ]] && mv $BUILD_DIR/www/mime.types $BUILD_DIR [[ -f "$BUILD_DIR/www/CHECKS" ]] && mv $BUILD_DIR/www/CHECKS $BUILD_DIR [[ -f "$BUILD_DIR/www/app.json" ]] && mv $BUILD_DIR/www/app.json $BUILD_DIR @@ -130,16 +131,20 @@ EOF cd $CUR_DIR +# Add support for app-nginx.conf.sigil +if [ -f $BUILD_DIR/app-nginx.conf.sigil ] ; then + echo "-----> using user provided app-nginx.conf.sigil" + cp $BUILD_DIR/app-nginx.conf.sigil $BUILD_DIR/nginx/nginx.conf.sigil -# Test for user override on nginx config... +# Allow deprecated nginx.conf.erb if [ -f $BUILD_DIR/nginx.conf.erb ] ; then - echo "-----> using user provided nginx.conf.erb" + echo "-----> DEPRECATED: using user provided nginx.conf.erb" cp $BUILD_DIR/nginx.conf.erb $BUILD_DIR/nginx/nginx.conf.erb # ...else, force default file else - echo "-----> using default nginx.conf.erb" - cp conf/nginx.conf.erb $BUILD_DIR/nginx/nginx.conf.erb + echo "-----> using default nginx.conf.sigil" + cp conf/nginx.conf.sigil $BUILD_DIR/nginx/nginx.conf.sigil fi # build mime.types unless overridden by user @@ -152,12 +157,15 @@ else cp conf/mime.types $BUILD_DIR/nginx/mime.types fi - # build a startup script cat <"$BUILD_DIR/start_nginx" #!/usr/bin/env bash rm -f /app/nginx/nginx.conf -erb /app/nginx/nginx.conf.erb > /app/nginx/nginx.conf +if [[ -f /app/nginx/nginx.conf.sigil ]]; then + /app/sigil/sigil -f /app/nginx/nginx.conf.sigil NGINX_ROOT="\$NGINX_ROOT" PORT="\$PORT" | cat -s > /app/nginx/nginx.conf +else + erb /app/nginx/nginx.conf.erb > /app/nginx/nginx.conf +fi exec /app/nginx/nginx -p /app/nginx -c /app/nginx/nginx.conf EOF chmod +x "$BUILD_DIR/start_nginx" diff --git a/conf/nginx.conf.erb b/conf/nginx.conf.sigil similarity index 69% rename from conf/nginx.conf.erb rename to conf/nginx.conf.sigil index 496e90b..62684a9 100644 --- a/conf/nginx.conf.erb +++ b/conf/nginx.conf.sigil @@ -11,13 +11,13 @@ http { types_hash_max_size 2048; include mime.types; server { - listen <%= ENV["PORT"] %>; + listen {{ $.PORT }}; server_name _; - <% if ENV["NGINX_ROOT"] %> - root /app/www/<%= ENV["NGINX_ROOT"] %>; - <% else %> + {{ if ne $.NGINX_ROOT "" }} + root /app/www/{{ $.NGINX_ROOT }}; + {{ else }} root /app/www; - <% end %> + {{ end }} index index.html; location / {