133 lines
2.9 KiB
HTML
133 lines
2.9 KiB
HTML
|
<?xml version="1.0" encoding="UTF-8" ?>
|
||
|
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
|
||
|
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
|
||
|
|
||
|
<html xmlns="http://www.w3.org/1999/xhtml">
|
||
|
|
||
|
<head>
|
||
|
<title>Templates.html</title>
|
||
|
|
||
|
</head>
|
||
|
|
||
|
<body>
|
||
|
|
||
|
<h1>Templates</h1>
|
||
|
|
||
|
<!-- markdown-toc start - Don't edit this section. Run M-x markdown-toc-generate-toc again -->
|
||
|
**Table of Contents**
|
||
|
|
||
|
- [Templates](#templates)
|
||
|
- [my dictionary in templates](#my-dictionary-in-templates)
|
||
|
- [Real template example](#real-template-example)
|
||
|
- [Checks in template](#checks-in-template)
|
||
|
|
||
|
<!-- markdown-toc end -->
|
||
|
|
||
|
<p>Surok using Jinja2 for templates. <a href="http://jinja.pocoo.org/docs/dev/">Jinja2 documentation</a></p>
|
||
|
|
||
|
<h2>my dictionary in templates</h2>
|
||
|
|
||
|
<p><code>
|
||
|
{
|
||
|
"services": {
|
||
|
"nginx": [
|
||
|
{
|
||
|
"name": "nginx.testing-kl92-s0.marathon.mesos.",
|
||
|
"port": "31200",
|
||
|
"ip": ["10.10.10.1"]
|
||
|
},
|
||
|
{
|
||
|
"name": "nginx.testing-kl123-s1.marathon.mesos.",
|
||
|
"port": "32230",
|
||
|
"ip": ["10.10.10.2"]
|
||
|
}
|
||
|
],
|
||
|
"emailsender": [
|
||
|
{
|
||
|
"name": "emailsender.testing-kl92-s0.marathon.mesos.",
|
||
|
"port": "31201",
|
||
|
"ip": ["10.10.10.1"]
|
||
|
},
|
||
|
{
|
||
|
"name": "emailsender.testing-kl123-s1.marathon.mesos.",
|
||
|
"port": "32232",
|
||
|
"ip": ["10.10.10.1"]
|
||
|
}
|
||
|
],
|
||
|
"service-with-defined-ports": {
|
||
|
"web": [
|
||
|
{
|
||
|
"name": "f.q.d.n",
|
||
|
"port": 12341
|
||
|
}
|
||
|
],
|
||
|
"rpc": [
|
||
|
{
|
||
|
"name": "f.q.d.n",
|
||
|
"port": 12342
|
||
|
}
|
||
|
]
|
||
|
}
|
||
|
},
|
||
|
"env": {
|
||
|
"HOME": "/var/lib/nginx"
|
||
|
}
|
||
|
}
|
||
|
</code></p>
|
||
|
|
||
|
<h2>Real template example</h2>
|
||
|
|
||
|
<p>nginx config
|
||
|
```
|
||
|
upstream matrix-http {
|
||
|
hash $remote<em>addr;
|
||
|
{% for server in my['services']['matrix']['http'] %}
|
||
|
server {{server['name']}}:{{server['port']}} max</em>fails=3;
|
||
|
{% endfor %}
|
||
|
}</p>
|
||
|
|
||
|
<p>upstream riot-http {
|
||
|
hash $remote<em>addr;
|
||
|
{% for server in my['services']['riot'] %}
|
||
|
server {{server['name']}}:{{server['port']}} max</em>fails=3;
|
||
|
{% endfor %}
|
||
|
}</p>
|
||
|
|
||
|
<p>server {
|
||
|
listen 10.15.56.157:80;
|
||
|
server_name matrix.example.com;</p>
|
||
|
|
||
|
<pre><code>client_max_body_size 10m;
|
||
|
|
||
|
location / {
|
||
|
proxy_pass http://riot-http;
|
||
|
proxy_set_header X-Real-IP $remote_addr;
|
||
|
proxy_set_header Host $http_host;
|
||
|
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
|
||
|
}
|
||
|
|
||
|
location /_matrix/ {
|
||
|
proxy_pass http://matrix-http;
|
||
|
proxy_set_header X-Real-IP $remote_addr;
|
||
|
proxy_set_header Host $http_host;
|
||
|
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
|
||
|
}
|
||
|
</code></pre>
|
||
|
|
||
|
<p>}
|
||
|
```</p>
|
||
|
|
||
|
<h2>Checks in template</h2>
|
||
|
|
||
|
<p><em>my['env']</em> is a python os.environ class. Look bellow:
|
||
|
<code>
|
||
|
{% if my['env'].get('DB_HOST') %}
|
||
|
host = '{{my['env']['DB_HOST']}}'
|
||
|
{% else %}
|
||
|
host = 'localhost'
|
||
|
{% endif %}
|
||
|
</code></p>
|
||
|
|
||
|
</body>
|
||
|
</html>
|