Last active
August 29, 2015 14:06
-
-
Save exarkun/f8b32fdf59a5c23eb0be to your computer and use it in GitHub Desktop.
Flocker configuration for a Twisted Web-based virtual hosting frontend server container
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Flocker and Docker configurations for a Twisted Web-based virtual hosting | |
| frontend server container. The frontend can be linked to other containers to | |
| support multiple HTTP virtual hosts on a single Flocker cluster. | |
| $ ln -sf Dockerfile-proxy Dockerfile | |
| $ docker build -t exarkun/flocker-link-example-proxy:5 . | |
| $ ln -sf Dockerfile-backend Dockerfile | |
| $ docker build -t exarkun/flocker-link-example-backend:2 . | |
| $ flocker-deploy deploy.yml app.yml |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| "version": 1 | |
| "applications": | |
| "proxy": | |
| "image": "exarkun/flocker-link-example-proxy:5" | |
| "ports": | |
| - "internal": 8080 | |
| "external": 8080 | |
| "links": | |
| - "local_port": 8081 | |
| "remote_port": 8091 | |
| "alias": "PROXY_a.example.com" | |
| - "local_port": 8082 | |
| "remote_port": 8092 | |
| "alias": "PROXY_b.example.com" | |
| "kittens": | |
| "image": "exarkun/flocker-link-example-backend:2" | |
| "ports": | |
| - "internal": 8080 | |
| "external": 8091 | |
| "environment": | |
| "CONTENT": "Kittens!" | |
| "puppies": | |
| "image": "exarkun/flocker-link-example-backend:2" | |
| "ports": | |
| - "internal": 8080 | |
| "external": 8092 | |
| "environment": | |
| "CONTENT": "Puppies!" |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| from os import environ | |
| from twisted.web.resource import Resource | |
| from twisted.web.server import Site | |
| from twisted.web.static import Data | |
| from twisted.web.proxy import ReverseProxyResource | |
| resource = Resource() | |
| resource.putChild(b"", Data(environ.get(b"CONTENT", b"Default content."), b"text/plain")) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| "version": 1 | |
| "nodes": | |
| "172.16.255.250": ["proxy"] | |
| "172.16.255.251": ["kittens", "puppies"] |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| FROM ubuntu:14.04 | |
| MAINTAINER Jean-Paul Calderone, [email protected] | |
| RUN apt-get update | |
| RUN apt-get upgrade -y | |
| RUN apt-get install -y python-twisted-web | |
| RUN apt-get autoremove | |
| RUN apt-get clean | |
| RUN mkdir -p /opt/flocker-links /var/run/flocker-links | |
| ADD backend.rpy /opt/flocker-links/backend.rpy | |
| EXPOSE 8080 | |
| WORKDIR /var/run/flocker-links | |
| CMD twistd -n web --resource /opt/flocker-links/backend.rpy |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| FROM ubuntu:14.04 | |
| MAINTAINER Jean-Paul Calderone, [email protected] | |
| RUN apt-get update | |
| RUN apt-get upgrade -y | |
| RUN apt-get install -y python-twisted-web | |
| RUN apt-get autoremove | |
| RUN apt-get clean | |
| RUN mkdir -p /opt/flocker-links /var/run/flocker-links | |
| ADD vhoster.rpy /opt/flocker-links/vhoster.rpy | |
| EXPOSE 8080 | |
| WORKDIR /var/run/flocker-links | |
| CMD twistd -n web --resource /opt/flocker-links/vhoster.rpy |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| from os import environ | |
| from pprint import pprint | |
| from twisted.web.vhost import NameVirtualHost | |
| from twisted.web.proxy import ReverseProxyResource | |
| from twisted.web.server import Site | |
| root = NameVirtualHost() | |
| pprint(environ) | |
| for k, v in environ.items(): | |
| if k.startswith(b"PROXY_") and k.endswith(b"ADDR"): | |
| parts = k.split(b"_") | |
| host = parts[1].lower() | |
| address = v | |
| port = int(environ[k[:-len(b"ADDR")] + b"PORT"]) | |
| print 'Adding virtual', host, 'proxying to', repr(address), repr(port) | |
| root.addHost(host, ReverseProxyResource(address, port, b"")) | |
| print 'Finished adding virtual hosts' | |
| resource = Site(root) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment