Permalink
Browse files

Handle subdomains + Let's Encrypt

  • Loading branch information...
loomchild committed Jan 12, 2018
1 parent 1004057 commit b65e020fd481658a40c5bb322115bbb4a60465fd
Showing with 33 additions and 8 deletions.
  1. +11 −0 puffin/core/applications.py
  2. +22 −8 puffin/core/compose.py
@@ -3,6 +3,7 @@
import os.path
import cachetools
import enum
import re
import yaml
import bleach
@@ -20,6 +21,8 @@
# Name separator between user and application, also check apps/_proxy
APPLICATION_SEPARATOR = "xxxx"
SUBDOMAIN_PATTERN = re.compile('(?:VIRTUAL_HOST|LETSENCRYPT_HOST)_([A-Za-z0-9]+)')
application_cache = cachetools.TTLCache(maxsize=1, ttl=120)
@@ -55,6 +58,14 @@ def __init__(self, application_id):
self.volumes = [v[0] for v in compose_data.get("volumes", {}).items()
if not (v[1] and "external" in v[1])]
subdomains = set()
for service in compose_data["services"].values():
for env in service.get("environment", []):
m = SUBDOMAIN_PATTERN.search(env)
if m:
subdomains.add(m.group(1).lower())
self.subdomains = list(subdomains)
def __eq__(self, other):
return self.application_id == other.application_id
View
@@ -21,22 +21,36 @@ def compose_run(machine, user, application, *arguments, **environment):
args = ["docker-compose", "-f", application.compose, "-p", name]
args += arguments
env = _get_env(machine, user, application, **environment)
process = subprocess.Popen(args,
stderr=subprocess.STDOUT, stdout=subprocess.PIPE,
universal_newlines=True, env=env)
process.wait()
out, err = process.communicate()
out = out.strip()
return out
def _get_env(machine, user, application, **environment):
domain = applications.get_application_domain(user, application)
env = dict(PATH=os.environ['PATH'], VIRTUAL_HOST=domain)
env.update({k: v for (k, v) in zip(
map(lambda s: 'VIRTUAL_HOST_' + s.upper(), application.subdomains),
map(lambda s: s + '.' + domain, application.subdomains))})
if app.config["LETSENCRYPT"] and applications.get_application_https(user, application):
admin = security.get_admin()
env.update(LETSENCRYPT_HOST=domain, LETSENCRYPT_EMAIL=admin.email,
LETSENCRYPT_TEST="true" if app.config["LETSENCRYPT_TEST"] else "")
env.update({k: v for (k, v) in zip(
map(lambda s: 'LETSENCRYPT_HOST_' + s.upper(), application.subdomains),
map(lambda s: s + '.' + domain, application.subdomains))})
env.update(machine_module.get_env_vars(machine))
env.update(**environment)
process = subprocess.Popen(args,
stderr=subprocess.STDOUT, stdout=subprocess.PIPE,
universal_newlines=True, env=env)
process.wait()
out, err = process.communicate()
out = out.strip()
return out
env.update(**environment)
return env

0 comments on commit b65e020

Please sign in to comment.