Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
37 commits
Select commit Hold shift + click to select a range
bf15db7
Get certs through letsencrypt
Nov 8, 2016
2e36d86
pin package requirements
Nov 23, 2016
546941d
handle ConsulException
Nov 23, 2016
a3df1c2
use python 3.5 in CI
Nov 23, 2016
a3c1624
py 3.5.2
Nov 23, 2016
0a0ccef
ns and import fixes
Nov 23, 2016
47a33b1
rm tests/init
Nov 23, 2016
cd1fab5
update structure for dockerfile build
Dec 23, 2016
1326d01
update requirements
Dec 23, 2016
bc6b716
slight code refactor
Dec 23, 2016
37f2292
certificate model: validate through x509 certificate loading
Dec 23, 2016
71b1fcf
slight refactor
Dec 27, 2016
d59dc45
Merge remote-tracking branch 'origin/master' into letsencrypt
Dec 27, 2016
1174131
app.py slight refactor
Dec 27, 2016
c8bc75c
refactor stuff
Dec 27, 2016
82cc36d
fix cross-imports
Jan 18, 2017
6da82e5
vergilius small refactor
Jan 19, 2017
a405677
update tests
Jan 19, 2017
745fa0c
update tests
Jan 19, 2017
0594c78
update tests
Jan 19, 2017
fc4e775
update tests
Jan 19, 2017
7323bc1
update tests
Jan 19, 2017
204086f
make dummy cert for unit testing
Jan 19, 2017
e0b6c5e
refactor tests
Jan 20, 2017
cc64a65
cleanup tests
Jan 20, 2017
ea09f20
dummycert update
Jan 20, 2017
533eaf6
models.Service: track data change cause index changes on every health…
Jan 24, 2017
324dde1
acmecertprovider slight refactor
Jan 24, 2017
6504d84
Service: nodes filtering and compare without checks
Jan 24, 2017
afe8d4b
sighandler fix
Jan 24, 2017
d22df13
service: log nginx stderr on invalid config
Jan 24, 2017
d5d21cf
log level through config
Jan 24, 2017
f283138
some small typo fixes
Jan 24, 2017
c00c44d
process well-known in real http config
Feb 9, 2017
81df86b
update locking for certificate
Feb 9, 2017
99f7430
fix Certificate ready_event
Feb 9, 2017
3a74995
dont reacquire certificate if certificate provider fails with exception
Mar 6, 2017
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
*.pyc
.*.swp
/*.egg-info
/.tox

*.iml
.idea/
/venv-vergilius
20 changes: 10 additions & 10 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -4,22 +4,22 @@ MAINTAINER Vasiliy Ostanin <bazilio91@gmail.ru>
RUN add-apt-repository ppa:nginx/development
RUN apt-get update
#apt-get upgrade -y -o Dpkg::Options::="--force-confold" && \
RUN apt-get install -y ca-certificates nginx git-core python build-essential autoconf libtool \
python-dev libffi-dev libssl-dev python-pip dialog nano
RUN apt-get install -y ca-certificates nginx git-core python3 build-essential autoconf libtool \
python3-dev libffi-dev libssl-dev python3-pip dialog nano
ENV TERM screen

ADD init.d/01_env.sh /etc/init.d/
ADD services/nginx.sh /etc/service/nginx/run
ADD services/vergilius.sh /etc/service/vergilius/run
COPY docker/init.d/01_env.sh /etc/init.d/
COPY docker/services/nginx.sh /etc/service/nginx/run
COPY docker/services/vergilius.sh /etc/service/vergilius/run

COPY consul/* /etc/consul/conf.d/
COPY nginx/conf.d/*.conf /etc/nginx/conf.d/
COPY nginx/nginx.conf /etc/nginx/nginx.conf
COPY docker/consul/* /etc/consul/conf.d/
COPY docker/nginx/conf.d/*.conf /etc/nginx/conf.d/
COPY docker/nginx/nginx.conf /etc/nginx/nginx.conf
RUN rm /etc/nginx/sites-enabled/* && mkdir -p /etc/nginx/sites-enabled/certs && \
mkdir -p /data/dummy_ca/domains/

ADD src /opt/vergilius
RUN cd /opt/vergilius/ && python setup.py install
COPY src /opt/vergilius
RUN cd /opt/vergilius/ && python3 setup.py install
WORKDIR /opt/vergilius/

EXPOSE 80 443
Expand Down
4 changes: 2 additions & 2 deletions circle.yml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
machine:
python:
version: 2.7
version: 3.5.2
services:
- docker
environment:
Expand All @@ -25,4 +25,4 @@ deployment:
dockerhub:
branch: master
commands:
- 'curl -H "Content-Type: application/json" --data "{\"source_type\": \"Branch\", \"source_name\": \"master\"}" -X POST https://registry.hub.docker.com/u/devopsftw/vergilius/trigger/ea3f932c-49b9-47e8-af0c-ec1d8615cda4/'
- 'curl -H "Content-Type: application/json" --data "{\"source_type\": \"Branch\", \"source_name\": \"master\"}" -X POST https://registry.hub.docker.com/u/devopsftw/vergilius/trigger/ea3f932c-49b9-47e8-af0c-ec1d8615cda4/'
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
7 changes: 5 additions & 2 deletions requirements.txt
Original file line number Diff line number Diff line change
@@ -1,7 +1,10 @@
zope.component==4.2.2
zope.event==4.1.0
zope.interface==4.1.3
python-consul==0.4.7
tornado==4.3
python-consul==0.7
tornado==4.4.2
funcsigs==1.0.0
mock==1.3.0
acme==0.9.3
cryptography==1.6
PyOpenSSL==16.2
39 changes: 23 additions & 16 deletions src/app.py
Original file line number Diff line number Diff line change
@@ -1,18 +1,19 @@
#!/usr/bin/python
#!/usr/bin/python3
import logging
import signal

import time
import tornado

import vergilius
from vergilius import logger
from vergilius.loop.nginx_reloader import NginxReloader
from vergilius.loop.service_watcher import ServiceWatcher
import tornado.ioloop
import vergilius.base
from vergilius.cert import AcmeCertificateProvider
from vergilius.loop import NginxReloader, ServiceWatcher
from vergilius import config

MAX_WAIT_SECONDS_BEFORE_SHUTDOWN = 10

logger.setLevel(logging.DEBUG)
logging.basicConfig(format='%(asctime)s %(levelname)s:%(name)s %(message)s')
logger = logging.getLogger(__name__)
logger.setLevel(config.LOG_LEVEL)


def shutdown():
Expand All @@ -35,30 +36,36 @@ def stop_loop():
stop_loop()


def sig_handler(sig, frame):
def sig_handler(sig, _):
logger.warning('Caught signal: %s', sig)
tornado.ioloop.IOLoop.instance().add_callback(shutdown)


def handle_future(f):
tornado.ioloop.IOLoop.current().stop()
if f.exception() != None:
if f.exception() is not None:
raise f.exception()


def main():
signal.signal(signal.SIGTERM, sig_handler)
signal.signal(signal.SIGINT, sig_handler)

vergilius.Vergilius.init()

consul_handler = ServiceWatcher().watch_services()
nginx_reloader = NginxReloader().nginx_reload()
app = App()
sw = ServiceWatcher(app)

io_loop = tornado.ioloop.IOLoop.current()
io_loop.add_future(consul_handler, handle_future)
io_loop.add_future(nginx_reloader, handle_future)
io_loop.add_future(sw.watch_services(), handle_future)
io_loop.add_future(app.nginx_reloader.reload(), handle_future)

io_loop.start()


class App(object):
def __init__(self):
self.session = vergilius.base.ConsulSession()
self.certificate_provider = AcmeCertificateProvider()
self.nginx_reloader = NginxReloader()

if __name__ == '__main__':
main()
7 changes: 5 additions & 2 deletions src/setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,14 @@
from setuptools import find_packages

install_requires = [
'python-consul',
'tornado',
'python-consul==0.7.0',
'tornado==4.4.2',
'setuptools>=1.0',
'zope.component',
'zope.interface',
'acme==0.9.3',
'cryptography==1.6',
'PyOpenSSL==16.2',
]

setup(
Expand Down
25 changes: 0 additions & 25 deletions src/vergilius/__init__.py
Original file line number Diff line number Diff line change
@@ -1,25 +0,0 @@
import logging
import os

from consul import Consul
from consul import tornado as consul_from_tornado
from tornado import template

import config
from components.dummy_certificate_provider import DummyCertificateProvider
from vergilius.models.identity import Identity

logger = logging.getLogger(__name__)
template_loader = template.Loader(os.path.join(os.path.dirname(os.path.abspath(__file__)), 'templates'))
certificate_provider = DummyCertificateProvider()

consul = Consul(host=config.CONSUL_HOST)
consul_tornado = consul_from_tornado.Consul(host=config.CONSUL_HOST)


class Vergilius(object):
identity = None

@classmethod
def init(cls):
cls.identity = Identity()
56 changes: 56 additions & 0 deletions src/vergilius/base.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
import logging
import consul
from consul.tornado import Consul as TornadoConsul

from tornado.ioloop import IOLoop
from tornado.locks import Event
import tornado.gen

from vergilius import config

logger = logging.getLogger(__name__)
logger.setLevel(logging.DEBUG)
tc = TornadoConsul(host=config.CONSUL_HOST)


class ConsulSession(object):
def __init__(self):
self._sid = None
self._waitSid = Event()
IOLoop.instance().spawn_callback(self.watch)
pass

@tornado.gen.coroutine
def watch(self):
while True:
tick = tornado.gen.sleep(5)
yield self.ensure_session()
yield tick

@tornado.gen.coroutine
def ensure_session(self):
if self._sid is None:
self._sid = yield self.create_session()
self._waitSid.set()
else:
try:
yield tc.session.renew(self._sid)
except consul.NotFound:
self._waitSid.clear()
logger.error('session not found, trying to recreate')
self._sid = yield self.create_session()
self._waitSid.set()
except consul.ConsulException as e:
logger.error('consul exception: %s' % e)
return True

@tornado.gen.coroutine
def create_session(self):
sid = yield tc.session.create('vergilius', ttl=10, behavior='delete', lock_delay=0)
logger.debug('session created: %s', sid)
return sid

@tornado.gen.coroutine
def get_sid(self):
yield self._waitSid.wait()
return self._sid
Loading