Skip to content

Commit

Permalink
Support templating of inlcude directives in nginx.conf
Browse files Browse the repository at this point in the history
Co-authored-by: Timothy Hitchener <thitchener@vmware.com>
Co-authored-by: Andy Brown <browna@vmware.com>

- Varify executable follows include directives to parse included config
files
  • Loading branch information
arjun024 committed Feb 11, 2021
1 parent 199f406 commit 2fe0003
Show file tree
Hide file tree
Showing 102 changed files with 3,094 additions and 1,790 deletions.
5 changes: 5 additions & 0 deletions fixtures/templated_with_include/buildpack.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
nginx:
version: stable
plaintext_env_vars:
- "OVERRIDE"
38 changes: 38 additions & 0 deletions fixtures/templated_with_include/custom.conf
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
daemon off;

error_log stderr;
events { worker_connections 1024; }

http {
charset utf-8;
log_format cloudfoundry 'NginxLog "$request" $status $body_bytes_sent';
access_log /dev/stdout cloudfoundry;
default_type application/octet-stream;
include mime.types;
sendfile on;

tcp_nopush on;
keepalive_timeout 30;
port_in_redirect off; # Ensure that redirects don't include the internal container PORT - 8080

server {
listen {{port}};
resolver {{nameservers}};
root public;
index index.html index.htm Default.htm;

# configuration endpoint
location /test {
default_type application/json;

set $override {{env "OVERRIDE"}};

if ($override != '') {
return 200 {{env "OVERRIDE"}};
}

return 200 "No overrides happening!";
}
}
}

78 changes: 78 additions & 0 deletions fixtures/templated_with_include/mime.types
Original file line number Diff line number Diff line change
@@ -0,0 +1,78 @@
types {
text/html html htm shtml;
text/css css;
text/xml xml;
image/gif gif;
image/jpeg jpeg jpg;
application/x-javascript js;
application/atom+xml atom;
application/rss+xml rss;
font/ttf ttf;
font/woff woff;
font/woff2 woff2;
text/mathml mml;
text/plain txt;
text/vnd.sun.j2me.app-descriptor jad;
text/vnd.wap.wml wml;
text/x-component htc;
text/cache-manifest manifest;
image/png png;
image/tiff tif tiff;
image/vnd.wap.wbmp wbmp;
image/x-icon ico;
image/x-jng jng;
image/x-ms-bmp bmp;
image/svg+xml svg svgz;
image/webp webp;
application/java-archive jar war ear;
application/mac-binhex40 hqx;
application/msword doc;
application/pdf pdf;
application/postscript ps eps ai;
application/rtf rtf;
application/vnd.ms-excel xls;
application/vnd.ms-powerpoint ppt;
application/vnd.wap.wmlc wmlc;
application/vnd.google-earth.kml+xml kml;
application/vnd.google-earth.kmz kmz;
application/x-7z-compressed 7z;
application/x-cocoa cco;
application/x-java-archive-diff jardiff;
application/x-java-jnlp-file jnlp;
application/x-makeself run;
application/x-perl pl pm;
application/x-pilot prc pdb;
application/x-rar-compressed rar;
application/x-redhat-package-manager rpm;
application/x-sea sea;
application/x-shockwave-flash swf;
application/x-stuffit sit;
application/x-tcl tcl tk;
application/x-x509-ca-cert der pem crt;
application/x-xpinstall xpi;
application/xhtml+xml xhtml;
application/zip zip;
application/octet-stream bin exe dll;
application/octet-stream deb;
application/octet-stream dmg;
application/octet-stream eot;
application/octet-stream iso img;
application/octet-stream msi msp msm;
application/json json;
audio/midi mid midi kar;
audio/mpeg mp3;
audio/ogg ogg;
audio/x-m4a m4a;
audio/x-realaudio ra;
video/3gpp 3gpp 3gp;
video/mp4 mp4;
video/mpeg mpeg mpg;
video/quicktime mov;
video/webm webm;
video/x-flv flv;
video/x-m4v m4v;
video/x-mng mng;
video/x-ms-asf asx asf;
video/x-ms-wmv wmv;
video/x-msvideo avi;
}
2 changes: 2 additions & 0 deletions fixtures/templated_with_include/nginx.conf
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
worker_processes 1;
include custom.conf;
1 change: 1 addition & 0 deletions fixtures/templated_with_include/public/index.html
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
<p>Exciting Content</p>
38 changes: 38 additions & 0 deletions fixtures/templated_with_include/sym-nginxconf
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
worker_processes 1;
daemon off;

error_log stderr;
events { worker_connections 1024; }

http {
charset utf-8;
log_format cloudfoundry 'NginxLog "$request" $status $body_bytes_sent';
access_log /dev/stdout cloudfoundry;
default_type application/octet-stream;
include mime.types;
sendfile on;

tcp_nopush on;
keepalive_timeout 30;
port_in_redirect off; # Ensure that redirects don't include the internal container PORT - 8080

server {
listen {{port}};
root public;
index index.html index.htm Default.htm;

# configuration endpoint
location /test {
default_type application/json;

set $override "{{env "OVERRIDE"}}";

if ($override != '') {
return 200 "{{env "OVERRIDE"}}";
}

return 200 "No overrides happening! \"abc\"";
}
}
}

1 change: 1 addition & 0 deletions fixtures/templated_with_include/sym-public/index.html
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
<p>Exciting Content</p>
1 change: 1 addition & 0 deletions fixtures/templated_with_include/sym-public/test.json
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
{ "abcd": 12345 }
19 changes: 14 additions & 5 deletions go.mod
Original file line number Diff line number Diff line change
@@ -1,14 +1,23 @@
module github.com/cloudfoundry/nginx-buildpack

require (
github.com/cloudfoundry/libbuildpack v0.0.0-20210203171418-e004e3b143a6
github.com/cloudfoundry/libbuildpack v0.0.0-20210204163631-5a211522c675
github.com/elazarl/goproxy v0.0.0-20210110162100-a92cc753f88e // indirect
github.com/elazarl/goproxy/ext v0.0.0-20210110162100-a92cc753f88e // indirect
github.com/golang/mock v1.4.4
github.com/miekg/dns v1.1.15
github.com/nxadm/tail v1.4.6 // indirect
github.com/golang/protobuf v1.4.3 // indirect
github.com/google/go-cmp v0.5.4 // indirect
github.com/miekg/dns v1.1.38
github.com/nxadm/tail v1.4.8 // indirect
github.com/onsi/ginkgo v1.15.0
github.com/onsi/gomega v1.10.4
golang.org/x/crypto v0.0.0-20201002170205-7f63de1d35b0 // indirect
github.com/onsi/gomega v1.10.5
golang.org/x/crypto v0.0.0-20201221181555-eec23a3978ad // indirect
golang.org/x/net v0.0.0-20210119194325-5f4716e94777 // indirect
golang.org/x/sys v0.0.0-20210124154548-22da62e12c0c // indirect
golang.org/x/text v0.3.5 // indirect
golang.org/x/tools v0.1.0 // indirect
google.golang.org/protobuf v1.25.0 // indirect
gopkg.in/check.v1 v1.0.0-20201130134442-10cb98267c6c // indirect
gopkg.in/yaml.v2 v2.4.0
)

Expand Down
Loading

0 comments on commit 2fe0003

Please sign in to comment.