2014-11-11 23:23:15 +00:00
|
|
|
import logging
|
2014-11-25 21:36:21 +00:00
|
|
|
import os
|
2014-11-26 16:28:29 +00:00
|
|
|
import features
|
2014-12-01 19:41:46 +00:00
|
|
|
import time
|
2014-11-11 23:23:15 +00:00
|
|
|
|
|
|
|
from app import app, userfiles as user_files, build_logs, dockerfile_build_queue
|
|
|
|
|
|
|
|
from buildman.manager.enterprise import EnterpriseManager
|
2014-12-16 18:41:30 +00:00
|
|
|
from buildman.manager.ephemeral import EphemeralBuilderManager
|
2014-11-11 23:23:15 +00:00
|
|
|
from buildman.server import BuilderServer
|
|
|
|
|
2014-11-25 21:36:21 +00:00
|
|
|
from trollius import SSLContext
|
|
|
|
|
2014-11-30 22:48:02 +00:00
|
|
|
logger = logging.getLogger(__name__)
|
2014-11-11 23:23:15 +00:00
|
|
|
|
2014-11-25 21:14:44 +00:00
|
|
|
BUILD_MANAGERS = {
|
2014-12-16 18:41:30 +00:00
|
|
|
'enterprise': EnterpriseManager,
|
|
|
|
'ephemeral': EphemeralBuilderManager,
|
2014-11-25 21:14:44 +00:00
|
|
|
}
|
|
|
|
|
2014-12-01 19:41:46 +00:00
|
|
|
EXTERNALLY_MANAGED = 'external'
|
|
|
|
|
2015-01-05 20:09:03 +00:00
|
|
|
DEFAULT_WEBSOCKET_PORT = 8787
|
|
|
|
DEFAULT_CONTROLLER_PORT = 8686
|
|
|
|
|
2015-01-23 16:29:15 +00:00
|
|
|
LOG_FORMAT = "%(asctime)s [%(process)d] [%(levelname)s] [%(name)s] %(message)s"
|
|
|
|
|
2014-11-25 21:14:44 +00:00
|
|
|
def run_build_manager():
|
2014-11-26 16:28:29 +00:00
|
|
|
if not features.BUILD_SUPPORT:
|
2014-11-30 22:48:02 +00:00
|
|
|
logger.debug('Building is disabled. Please enable the feature flag')
|
2015-01-26 19:13:55 +00:00
|
|
|
while True:
|
|
|
|
time.sleep(1000)
|
2014-11-26 16:28:29 +00:00
|
|
|
return
|
|
|
|
|
2014-11-25 21:14:44 +00:00
|
|
|
build_manager_config = app.config.get('BUILD_MANAGER')
|
|
|
|
if build_manager_config is None:
|
|
|
|
return
|
2014-11-11 23:23:15 +00:00
|
|
|
|
2014-12-01 19:41:46 +00:00
|
|
|
# If the build system is externally managed, then we just sleep this process.
|
|
|
|
if build_manager_config[0] == EXTERNALLY_MANAGED:
|
|
|
|
logger.debug('Builds are externally managed.')
|
|
|
|
while True:
|
|
|
|
time.sleep(1000)
|
|
|
|
return
|
|
|
|
|
2014-11-30 22:48:02 +00:00
|
|
|
logger.debug('Asking to start build manager with lifecycle "%s"', build_manager_config[0])
|
2014-11-25 21:14:44 +00:00
|
|
|
manager_klass = BUILD_MANAGERS.get(build_manager_config[0])
|
|
|
|
if manager_klass is None:
|
|
|
|
return
|
2014-11-11 23:23:15 +00:00
|
|
|
|
2014-12-31 16:33:56 +00:00
|
|
|
manager_hostname = os.environ.get('BUILDMAN_HOSTNAME',
|
|
|
|
app.config.get('BUILDMAN_HOSTNAME',
|
|
|
|
app.config['SERVER_HOSTNAME']))
|
2015-01-05 20:09:03 +00:00
|
|
|
websocket_port = int(os.environ.get('BUILDMAN_WEBSOCKET_PORT',
|
|
|
|
app.config.get('BUILDMAN_WEBSOCKET_PORT',
|
|
|
|
DEFAULT_WEBSOCKET_PORT)))
|
|
|
|
controller_port = int(os.environ.get('BUILDMAN_CONTROLLER_PORT',
|
|
|
|
app.config.get('BUILDMAN_CONTROLLER_PORT',
|
|
|
|
DEFAULT_CONTROLLER_PORT)))
|
|
|
|
|
2014-12-31 16:33:56 +00:00
|
|
|
logger.debug('Will pass buildman hostname %s to builders for websocket connection',
|
|
|
|
manager_hostname)
|
2014-12-16 18:41:30 +00:00
|
|
|
|
2014-11-30 22:48:02 +00:00
|
|
|
logger.debug('Starting build manager with lifecycle "%s"', build_manager_config[0])
|
2014-11-25 21:36:21 +00:00
|
|
|
ssl_context = None
|
2014-11-25 23:08:18 +00:00
|
|
|
if os.environ.get('SSL_CONFIG'):
|
2014-11-30 22:48:02 +00:00
|
|
|
logger.debug('Loading SSL cert and key')
|
2014-11-25 21:36:21 +00:00
|
|
|
ssl_context = SSLContext()
|
2014-12-16 18:19:35 +00:00
|
|
|
ssl_context.load_cert_chain(os.path.join(os.environ.get('SSL_CONFIG'), 'ssl.cert'),
|
|
|
|
os.path.join(os.environ.get('SSL_CONFIG'), 'ssl.key'))
|
2014-11-25 21:36:21 +00:00
|
|
|
|
2014-11-11 23:23:15 +00:00
|
|
|
server = BuilderServer(app.config['SERVER_HOSTNAME'], dockerfile_build_queue, build_logs,
|
2014-12-31 16:33:56 +00:00
|
|
|
user_files, manager_klass, build_manager_config[1], manager_hostname)
|
2015-01-05 20:09:03 +00:00
|
|
|
server.run('0.0.0.0', websocket_port, controller_port, ssl=ssl_context)
|
2014-11-25 21:14:44 +00:00
|
|
|
|
|
|
|
if __name__ == '__main__':
|
2015-01-23 16:29:15 +00:00
|
|
|
logging.basicConfig(level=logging.DEBUG, format=LOG_FORMAT)
|
2015-01-26 20:27:39 +00:00
|
|
|
logging.getLogger('peewee').setLevel(logging.WARN)
|
2014-11-25 21:14:44 +00:00
|
|
|
run_build_manager()
|