Commits

Christian Theune  committed 2181f4e

Add more components: nginx, haproxy, postgresql

Nginx actually generates a real configuration.

Haproxy and postgresql are currently just dummies to demonstrate the
dependencies.

  • Participants
  • Parent commits fe8e5ca

Comments (0)

Files changed (5)

File components/haproxy/component.py

+from batou.component import Component
+from batou.utils import Address
+
+
+class HaProxy(Component):
+
+    def configure(self):
+        self.address = Address(self.host.fqdn, 8002)
+        self.provide('haproxy', self.address)

File components/nginx/component.py

+from batou.component import Component
+from batou.lib.file import File
+from batou.utils import Address
+
+
+class Nginx(Component):
+
+    # Set via environment
+    server_name = 'localhost'
+
+    def configure(self):
+        self.address = Address(self.server_name, 80)
+        self.haproxy = self.require('haproxy')[0]
+        self += File('sprintsite.conf', is_template=True)

File components/nginx/sprintsite.conf

+server {
+    listen ${component.address.listen};
+    server_name ${component.server_name};
+
+    # Ensure canonical hostname
+    if ($host != $server_name) {
+        rewrite (.*) http://$server_name$1 permanent;
+    }
+
+    # disallow hidden files (and prevent various path-based attacks)
+    location ~ /\. {
+        deny all;
+        access_log off;
+        log_not_found off;
+    }
+
+    # the following standard files may not exists
+    location = /favicon.ico {
+        log_not_found off;
+    }
+
+    location = /robots.txt {
+        allow all;
+        log_not_found off;
+    }
+
+    proxy_pass http://${component.haproxy.connect};
+
+}

File components/postgresql/component.py

+from batou.component import Component
+
+
+class PostgreSQL(Component):
+
+    def configure(self):
+        self.provide('database:django', 'postgresql://localhost/django')

File environments/dev-ctheune.cfg

 host_domain =
 
 [hosts]
-localhost = supervisor, django
+localhost = nginx, supervisor, django
+frontend27 = postgresql, haproxy