diff --git a/doc/examples/README.md b/doc/examples/README.md new file mode 100644 index 0000000..33818c6 --- /dev/null +++ b/doc/examples/README.md @@ -0,0 +1,6 @@ +# Examples + +- [simple static site](basic/README.md) +- [static site with templates](static-template/README.md) +- [print env via NJS](njs/README.md) +- [print env via Perl](perl/README.md) diff --git a/doc/examples/basic/Dockerfile b/doc/examples/basic/Dockerfile new file mode 100644 index 0000000..5652ffa --- /dev/null +++ b/doc/examples/basic/Dockerfile @@ -0,0 +1,8 @@ +FROM docker.io/rockdrilla/angie-conv:v0.0.1 +SHELL [ "/bin/sh", "-ec" ] + +COPY /site/ /etc/angie/site/ +COPY /static/ /etc/angie/static/ + +## not necessary at all - just disables ngx_http_proxy_module configuration +ENV NGX_HTTP_NO_PROXY=1 diff --git a/doc/examples/basic/README.md b/doc/examples/basic/README.md new file mode 100644 index 0000000..31062bd --- /dev/null +++ b/doc/examples/basic/README.md @@ -0,0 +1,20 @@ +# simple static site + +configuration: + +```nginx +server { + listen 8080; +} +``` + +Dockerfile: + +```dockerfile +FROM docker.io/rockdrilla/angie-conv:v0.0.1 + +COPY /site/ /etc/angie/site/ +COPY /static/ /etc/angie/static/ +``` + +both are simple and fine enough. diff --git a/doc/examples/basic/site/http-site.conf b/doc/examples/basic/site/http-site.conf new file mode 100644 index 0000000..8ff8ce6 --- /dev/null +++ b/doc/examples/basic/site/http-site.conf @@ -0,0 +1,3 @@ +server { + listen 8080; +} \ No newline at end of file diff --git a/doc/examples/basic/static/index.html b/doc/examples/basic/static/index.html new file mode 100644 index 0000000..09a2238 --- /dev/null +++ b/doc/examples/basic/static/index.html @@ -0,0 +1,5 @@ + + +

Hello World

+ +
\ No newline at end of file diff --git a/doc/examples/njs/Dockerfile b/doc/examples/njs/Dockerfile new file mode 100644 index 0000000..aa1e2bb --- /dev/null +++ b/doc/examples/njs/Dockerfile @@ -0,0 +1,11 @@ +FROM docker.io/rockdrilla/angie-conv:v0.0.1 +SHELL [ "/bin/sh", "-ec" ] + +COPY /site/ /etc/angie/site/ + +## install 'angie-module-njs' and process package contents +RUN apt-install-angie-mod.sh njs ; \ + apt-clean.sh + +## load ngx_http_js_module +ENV NGX_HTTP_MODULES='njs' diff --git a/doc/examples/njs/README.md b/doc/examples/njs/README.md new file mode 100644 index 0000000..9254696 --- /dev/null +++ b/doc/examples/njs/README.md @@ -0,0 +1,54 @@ +# print env via NJS + +configuration: + +```nginx +server { + listen 8080; + + location / { return 204; } + + js_import ngx_env.js; + location = /env + { + js_content ngx_env.report; + } +} +``` + +NJS script: + +```js +function report(r) { + var s = ""; + const keys = Object.keys(process.env).sort(); + for (const i in keys) { + const k = keys[i]; + const v = process.env[k]; + s += k + '=' + v + "\n"; + } + r.return(200, s); +} + +export default { report }; +``` + +Dockerfile: + +```dockerfile +FROM docker.io/rockdrilla/angie-conv:v0.0.1 + +COPY /site/ /etc/angie/site/ + +## install 'angie-module-njs' and process package contents +RUN apt-install-angie-mod.sh njs ; \ + apt-clean.sh + +## load ngx_http_js_module +ENV NGX_HTTP_MODULES='njs' +``` + +Test URI e.g. with `curl`: +```sh +curl http://127.0.0.1:8080/env +``` diff --git a/doc/examples/njs/site/http-env-js.conf b/doc/examples/njs/site/http-env-js.conf new file mode 100644 index 0000000..7656033 --- /dev/null +++ b/doc/examples/njs/site/http-env-js.conf @@ -0,0 +1,11 @@ +server { + listen 8080; + + location / { return 204; } + + js_import ngx_env.js; + location = /env + { + js_content ngx_env.report; + } +} \ No newline at end of file diff --git a/doc/examples/njs/site/ngx_env.js b/doc/examples/njs/site/ngx_env.js new file mode 100644 index 0000000..38892f3 --- /dev/null +++ b/doc/examples/njs/site/ngx_env.js @@ -0,0 +1,12 @@ +function report(r) { + var s = ""; + const keys = Object.keys(process.env).sort(); + for (const i in keys) { + const k = keys[i]; + const v = process.env[k]; + s += k + '=' + v + "\n"; + } + r.return(200, s); +} + +export default { report }; \ No newline at end of file diff --git a/doc/examples/perl/Dockerfile b/doc/examples/perl/Dockerfile new file mode 100644 index 0000000..ad02f0f --- /dev/null +++ b/doc/examples/perl/Dockerfile @@ -0,0 +1,11 @@ +FROM docker.io/rockdrilla/angie-conv:v0.0.1 +SHELL [ "/bin/sh", "-ec" ] + +COPY /site/ /etc/angie/site/ + +## install 'angie-module-perl' and process package contents +RUN apt-install-angie-mod.sh perl ; \ + apt-clean.sh + +## load ngx_http_perl_module +ENV NGX_HTTP_MODULES='perl' diff --git a/doc/examples/perl/README.md b/doc/examples/perl/README.md new file mode 100644 index 0000000..2c83251 --- /dev/null +++ b/doc/examples/perl/README.md @@ -0,0 +1,64 @@ +# print env via Perl + +configuration: + +```nginx +perl_require ngx_env.pm; +server { + listen 8080; + + location / { return 204; } + + location = /env + { + perl ngx_env::report; + } +} +``` + +Perl script: + +```perl +package ngx_env; + +use nginx; + +sub report { + my $r = shift; + + my $s = ""; + for (sort keys %ENV) { + $s = $s . "$_=$ENV{$_}\n"; + } + + $r->discard_request_body; + $r->send_http_header; + $r->print($s); + + return OK; +} + +1; + +__END__ +``` + +Dockerfile: + +```dockerfile +FROM docker.io/rockdrilla/angie-conv:v0.0.1 + +COPY /site/ /etc/angie/site/ + +## install 'angie-module-perl' and process package contents +RUN apt-install-angie-mod.sh perl ; \ + apt-clean.sh + +## load ngx_http_perl_module +ENV NGX_HTTP_MODULES='perl' +``` + +Test URI e.g. with `curl`: +```sh +curl http://127.0.0.1:8080/env +``` diff --git a/doc/examples/perl/site/http-env-perl.conf b/doc/examples/perl/site/http-env-perl.conf new file mode 100644 index 0000000..45082d4 --- /dev/null +++ b/doc/examples/perl/site/http-env-perl.conf @@ -0,0 +1,11 @@ +perl_require ngx_env.pm; +server { + listen 8080; + + location / { return 204; } + + location = /env + { + perl ngx_env::report; + } +} \ No newline at end of file diff --git a/doc/examples/perl/site/ngx_env.pm b/doc/examples/perl/site/ngx_env.pm new file mode 100644 index 0000000..fb86cec --- /dev/null +++ b/doc/examples/perl/site/ngx_env.pm @@ -0,0 +1,22 @@ +package ngx_env; + +use nginx; + +sub report { + my $r = shift; + + my $s = ""; + for (sort keys %ENV) { + $s = $s . "$_=$ENV{$_}\n"; + } + + $r->discard_request_body; + $r->send_http_header; + $r->print($s); + + return OK; +} + +1; + +__END__ \ No newline at end of file diff --git a/doc/examples/static-template/Dockerfile b/doc/examples/static-template/Dockerfile new file mode 100644 index 0000000..6e4bdb5 --- /dev/null +++ b/doc/examples/static-template/Dockerfile @@ -0,0 +1,8 @@ +FROM docker.io/rockdrilla/angie-conv:v0.0.1 +SHELL [ "/bin/sh", "-ec" ] + +COPY /site/ /etc/angie/site/ +COPY /static/ /etc/angie/static/ + +## instruct entrypoint to process static/ - unroll *.j2 templates, etc. +ENV NGX_PROCESS_STATIC=1 diff --git a/doc/examples/static-template/README.md b/doc/examples/static-template/README.md new file mode 100644 index 0000000..4009644 --- /dev/null +++ b/doc/examples/static-template/README.md @@ -0,0 +1,34 @@ +# static site with templates + +mostly same as [simple static site](../basic/README.md) except environment variable `NGX_PROCESS_STATIC=1`. + +configuration: + +```nginx +server { + listen 8080; +} +``` + +Dockerfile: + +```dockerfile +FROM docker.io/rockdrilla/angie-conv:v0.0.1 + +COPY /site/ /etc/angie/site/ +COPY /static/ /etc/angie/static/ + +## instruct entrypoint to process static/ - unroll *.j2 templates, etc. +ENV NGX_PROCESS_STATIC=1 +``` + +Also note that there's no `index.html` but `index.html.j2`: + +```jinja + + +

Hello World

+ This image is powered by Angie {{ env.ANGIE_VERSION }} and Python {{ env.PYTHON_VERSION }}. + +
+``` diff --git a/doc/examples/static-template/site/http-site.conf b/doc/examples/static-template/site/http-site.conf new file mode 100644 index 0000000..8ff8ce6 --- /dev/null +++ b/doc/examples/static-template/site/http-site.conf @@ -0,0 +1,3 @@ +server { + listen 8080; +} \ No newline at end of file diff --git a/doc/examples/static-template/static/index.html.j2 b/doc/examples/static-template/static/index.html.j2 new file mode 100644 index 0000000..eb5fb53 --- /dev/null +++ b/doc/examples/static-template/static/index.html.j2 @@ -0,0 +1,6 @@ + + +

Hello World

+ This image is powered by Angie {{ env.ANGIE_VERSION }} and Python {{ env.PYTHON_VERSION }}. + +
\ No newline at end of file