diff --git a/docs/App-config-file.html b/docs/App-config-file.html new file mode 100644 index 0000000..8c0bd6e --- /dev/null +++ b/docs/App-config-file.html @@ -0,0 +1,46 @@ + + + + + + +App-config-file.html + + + + + +

Surok app config file

+ +

conf.d/myapp.json + +{ + "services": [ + { + "name": "myapp", + "group": "backend.production", + "ports": ["proxy", "api"] + }, + { + "name": "nginx", + "group": "frontend.production" + } + ], + "conf_name": "myapp_backend_production", + "template": "/etc/surok/templates/myapp.jj2", + "dest": "/etc/myapp/myapp.cfg", + "reload_cmd": "killall -9 myapp; /usr/local/bin/myapp -config /etc/myapp/myapp.cfg" +} + +* services. List of hashes with required services for app. + 1. name - string. App name in Marathon. + 2. group - string. App group in Marathon. Optional. Discovery policy: 1) config 2) SUROKDISCOVERYGROUP environment variable 3) Marathon API + 3. ports - list. Name of opened port. In marathon of course. Optional. +* confname. Unique app config name. +* template. Jinja2 template location. +* dest. Destination config path. +* reloadcmd. Command to execute if generated config is changed.

+ + + diff --git a/docs/App-config-file.md b/docs/App-config-file.md index 58da101..60b63bd 100644 --- a/docs/App-config-file.md +++ b/docs/App-config-file.md @@ -1,3 +1,5 @@ +# Surok app config file + conf.d/myapp.json ``` { @@ -25,4 +27,4 @@ conf.d/myapp.json * **conf_name**. Unique app config name. * **template**. Jinja2 template location. * **dest**. Destination config path. -* **reload_cmd**. Command to execute if generated config is changed. \ No newline at end of file +* **reload_cmd**. Command to execute if generated config is changed. diff --git a/docs/Build.html b/docs/Build.html new file mode 100644 index 0000000..db873f6 --- /dev/null +++ b/docs/Build.html @@ -0,0 +1,44 @@ + + + + + + +Build.html + + + + + +

Build packages and images

+ +

build debian package + +cd build +./build.sh build_package + +A deb-package will be placed in build/out

+ +

build surok base docker image(based on Ubuntu Xenial) + +cd build +./build.sh surok_image +

+ +

build surok base Alpine image + +cd build +./build.sh alpine +

+ +

build surok base CentOS image + +cd build +./build.sh centos +

+ +

ENTRYPOINT is: cd /opt/surok && pytho3 surok.py -c /etc/surok/conf/surok.json

+ + + diff --git a/docs/Main-config-file.html b/docs/Main-config-file.html new file mode 100644 index 0000000..ff6c3da --- /dev/null +++ b/docs/Main-config-file.html @@ -0,0 +1,52 @@ + + + + + + +Main-config-file.html + + + + + +

Surok main config file

+ +

Default location is /etc/surok/conf/surok.json

+ +

conf/surok.json + +{ + "marathon": { + "force": true, + "host": "http://marathon.mesos:8080", + "enabled": false + }, + "confd": "/etc/surok/conf.d", + "domain": "marathon.mesos", + "wait_time": 20, + "lock_dir": "/var/tmp", + "loglevel": "info", + "container": false, + "memcached": { + "enabled": false, + "discovery": { + "enabled": false, + "service": "memcached", + "group": "system" + }, + "hosts": ["localhost:11211"] + } +} + +* marathon section. Restarting app over marathon api if config changed. Disabled by default. +* confd. Directory where located configs apps. +* domain. Domain served by mesos-dns. +* lockdir. Directory where surok writes temporary configs after resolving. +* waittime. Sleep time in main loop. +* container. Not implemented. +* memcached section. Memcached support. Disabled by default.

+ + + diff --git a/docs/Main-config-file.md b/docs/Main-config-file.md index a19b3b0..431fb44 100644 --- a/docs/Main-config-file.md +++ b/docs/Main-config-file.md @@ -1,3 +1,7 @@ +# Surok main config file + +Default location is /etc/surok/conf/surok.json + conf/surok.json ``` { @@ -5,7 +9,7 @@ conf/surok.json "force": true, "host": "http://marathon.mesos:8080", "enabled": false - }, + }, "confd": "/etc/surok/conf.d", "domain": "marathon.mesos", "wait_time": 20, @@ -13,13 +17,13 @@ conf/surok.json "loglevel": "info", "container": false, "memcached": { - "enabled": false, - "discovery": { + "enabled": false, + "discovery": { "enabled": false, - "service": "memcached", - "group": "system" - }, - "hosts": ["localhost:11211"] + "service": "memcached", + "group": "system" + }, + "hosts": ["localhost:11211"] } } ``` @@ -29,4 +33,4 @@ conf/surok.json * **lock_dir**. Directory where surok writes temporary configs after resolving. * **wait_time**. Sleep time in main loop. * **container**. Not implemented. -* **memcached section**. Memcached support. Disabled by default. \ No newline at end of file +* **memcached section**. Memcached support. Disabled by default. diff --git a/docs/README.md b/docs/README.md index 3866938..826a53c 100644 --- a/docs/README.md +++ b/docs/README.md @@ -11,14 +11,14 @@ Service discovery for Apache Mesos. **Table of Contents** - [Surok](https://difrex.github.io/surok/) - - [Build](https://difrex.github.io/surok/Build.md) + - [Build](https://difrex.github.io/surok/Build.html) - [Wiki](https://github.com/Difrex/surok/wiki) - **Configuration** - - [Main config file](https://difrex.github.io/surok/Main-config-file.md) - - [App config file](https://difrex.github.io/surok/App-config-file.md) - - [Templates](https://difrex.github.io/surok/Templates.md) + - [Main config file](https://difrex.github.io/surok/Main-config-file.html) + - [App config file](https://difrex.github.io/surok/App-config-file.html) + - [Templates](https://difrex.github.io/surok/Templates.html) - **Usage** - - [Use Surok with Supervisord](https://difrex.github.io/surok/Use-Surok-with-supervisord.md) + - [Use Surok with Supervisord](https://difrex.github.io/surok/Use-Surok-with-supervisord.html) - [Known issues](#known-issues) - [Athors](#authors) - [LICENSE](#license) diff --git a/docs/Templates.html b/docs/Templates.html new file mode 100644 index 0000000..64614d0 --- /dev/null +++ b/docs/Templates.html @@ -0,0 +1,132 @@ + + + + + + +Templates.html + + + + + +

Templates

+ + +**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) + + + +

Surok using Jinja2 for templates. Jinja2 documentation

+ +

my dictionary in templates

+ +

+{ + "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" + } +} +

+ +

Real template example

+ +

nginx config +``` +upstream matrix-http { + hash $remoteaddr; +{% for server in my['services']['matrix']['http'] %} + server {{server['name']}}:{{server['port']}} maxfails=3; +{% endfor %} +}

+ +

upstream riot-http { + hash $remoteaddr; +{% for server in my['services']['riot'] %} + server {{server['name']}}:{{server['port']}} maxfails=3; +{% endfor %} +}

+ +

server { + listen 10.15.56.157:80; + server_name matrix.example.com;

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

} +```

+ +

Checks in template

+ +

my['env'] is a python os.environ class. Look bellow: + +{% if my['env'].get('DB_HOST') %} +host = '{{my['env']['DB_HOST']}}' +{% else %} +host = 'localhost' +{% endif %} +

+ + + diff --git a/docs/Templates.md b/docs/Templates.md index 55e592e..50ea7d5 100644 --- a/docs/Templates.md +++ b/docs/Templates.md @@ -1,5 +1,16 @@ # Templates + +**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) + + + + Surok using Jinja2 for templates. [Jinja2 documentation](http://jinja.pocoo.org/docs/dev/) ## my dictionary in templates diff --git a/docs/Use-Surok-with-supervisord.html b/docs/Use-Surok-with-supervisord.html new file mode 100644 index 0000000..b6ad4e3 --- /dev/null +++ b/docs/Use-Surok-with-supervisord.html @@ -0,0 +1,93 @@ + + + + + + +Use-Surok-with-supervisord.html + + + + + +

Use Surok with supervisord

+ + +**Table of Contents** + +- [Use Surok with supervisord](#use-surok-with-supervisord) + - [supervisord.conf](#supervisordconf) + - [surok service conf](#surok-service-conf) + - [install supervisord in you container and set it as entrypoint](#install-supervisord-in-you-container-and-set-it-as-entrypoint) + + + +

supervisord.conf

+ +

Write supervisord.conf. Example: +```ini +[unixhttpserver] +file=/tmp/supervisor.sock

+ +

[supervisord] +logfile=/tmp/supervisord.log ; (main log file;default $CWD/supervisord.log) +logfilemaxbytes=50MB ; (max main logfile bytes b4 rotation;default 50MB) +logfilebackups=10 ; (num of main logfile rotation backups;default 10) +loglevel=info ; (log level;default info; others: debug,warn,trace) +pidfile=/tmp/supervisord.pid ; (supervisord pidfile;default supervisord.pid) +nodaemon=true ; (start in foreground if true;default false) +minfds=1024 ; (min. avail startup file descriptors;default 1024) +minprocs=200

+ +

[supervisorctl] +serverurl=unix:///tmp/supervisor.sock

+ +

[rpcinterface:supervisor] +supervisor.rpcinterfacefactory = supervisor.rpcinterface:makemain_rpcinterface

+ +

[program:surok] +command=/usr/bin/python3 /opt/surok/surok.py -c /etc/surok/conf/surok.json

+ +

[program:myservice] +command=/app/myservice -conf /app/conf/my_service.conf +user=www-data +startsecs=2 +```

+ +

surok service conf

+ +

Write /etc/surok/conf.d/my_service.json config like that +```json +{ + "services": [ + { + "name": "my-service", + "group": "production.web" + }

+ +
],
+"conf_name": "my_service",
+"template": "/etc/surok/templates/my-service.jj2",
+"dest": "/app/conf/my_service.conf",
+"reload_cmd": "/usr/bin/supervisorctl restart my_service"
+
+ +

} +```

+ +

install supervisord in you container and set it as entrypoint

+ +

```dockerfile +...

+ +

Install supervisord and provide config

+ +

RUN easy_install supervisor +ADD supervisord.conf /etc

+ +

ENTRYPOINT /usr/bin/supervisord -c /etc/supervisord.conf +```

+ + + diff --git a/docs/Use-Surok-with-supervisord.md b/docs/Use-Surok-with-supervisord.md index 2b7ca3b..e218e82 100644 --- a/docs/Use-Surok-with-supervisord.md +++ b/docs/Use-Surok-with-supervisord.md @@ -1,5 +1,16 @@ # Use Surok with supervisord + +**Table of Contents** + +- [Use Surok with supervisord](#use-surok-with-supervisord) + - [supervisord.conf](#supervisordconf) + - [surok service conf](#surok-service-conf) + - [install supervisord in you container and set it as entrypoint](#install-supervisord-in-you-container-and-set-it-as-entrypoint) + + + + ## supervisord.conf Write supervisord.conf. Example: ```ini @@ -57,4 +68,4 @@ RUN easy_install supervisor ADD supervisord.conf /etc ENTRYPOINT /usr/bin/supervisord -c /etc/supervisord.conf -``` \ No newline at end of file +``` diff --git a/docs/index.html b/docs/index.html index 280d6ba..e4b59f5 100644 --- a/docs/index.html +++ b/docs/index.html @@ -28,17 +28,17 @@