1
0

doc: examples

This commit is contained in:
Konstantin Demin 2024-09-20 01:27:15 +03:00
parent 73df84bd6e
commit 026fe8757e
Signed by: krd
GPG Key ID: 4D56F87A8BA65FD0
17 changed files with 289 additions and 0 deletions

6
doc/examples/README.md Normal file
View File

@ -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)

View File

@ -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

View File

@ -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.

View File

@ -0,0 +1,3 @@
server {
listen 8080;
}

View File

@ -0,0 +1,5 @@
<hmtl>
<body>
<h1>Hello World</h1>
</body>
</hmtl>

View File

@ -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'

View File

@ -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
```

View File

@ -0,0 +1,11 @@
server {
listen 8080;
location / { return 204; }
js_import ngx_env.js;
location = /env
{
js_content ngx_env.report;
}
}

View File

@ -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 };

View File

@ -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'

View File

@ -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
```

View File

@ -0,0 +1,11 @@
perl_require ngx_env.pm;
server {
listen 8080;
location / { return 204; }
location = /env
{
perl ngx_env::report;
}
}

View File

@ -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__

View File

@ -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

View File

@ -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
<hmtl>
<body>
<h1>Hello World</h1>
This image is powered by Angie {{ env.ANGIE_VERSION }} and Python {{ env.PYTHON_VERSION }}.
</body>
</hmtl>
```

View File

@ -0,0 +1,3 @@
server {
listen 8080;
}

View File

@ -0,0 +1,6 @@
<hmtl>
<body>
<h1>Hello World</h1>
This image is powered by Angie {{ env.ANGIE_VERSION }} and Python {{ env.PYTHON_VERSION }}.
</body>
</hmtl>