From dd7664328c3e3f673fef8521140769f6d8c720df Mon Sep 17 00:00:00 2001 From: Jake Moshenko Date: Mon, 5 Jan 2015 15:09:03 -0500 Subject: [PATCH] Make the build manager ports configurable. --- buildman/builder.py | 12 +++++++++++- buildman/server.py | 17 +++++++---------- 2 files changed, 18 insertions(+), 11 deletions(-) diff --git a/buildman/builder.py b/buildman/builder.py index e1c7a852b..467ac2f6d 100644 --- a/buildman/builder.py +++ b/buildman/builder.py @@ -20,6 +20,9 @@ BUILD_MANAGERS = { EXTERNALLY_MANAGED = 'external' +DEFAULT_WEBSOCKET_PORT = 8787 +DEFAULT_CONTROLLER_PORT = 8686 + def run_build_manager(): if not features.BUILD_SUPPORT: logger.debug('Building is disabled. Please enable the feature flag') @@ -44,6 +47,13 @@ def run_build_manager(): manager_hostname = os.environ.get('BUILDMAN_HOSTNAME', app.config.get('BUILDMAN_HOSTNAME', app.config['SERVER_HOSTNAME'])) + 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))) + logger.debug('Will pass buildman hostname %s to builders for websocket connection', manager_hostname) @@ -57,7 +67,7 @@ def run_build_manager(): server = BuilderServer(app.config['SERVER_HOSTNAME'], dockerfile_build_queue, build_logs, user_files, manager_klass, build_manager_config[1], manager_hostname) - server.run('0.0.0.0', ssl=ssl_context) + server.run('0.0.0.0', websocket_port, controller_port, ssl=ssl_context) if __name__ == '__main__': logging.basicConfig(level=logging.DEBUG) diff --git a/buildman/server.py b/buildman/server.py index e1175f718..369f90313 100644 --- a/buildman/server.py +++ b/buildman/server.py @@ -21,9 +21,6 @@ TIMEOUT_PERIOD_MINUTES = 20 JOB_TIMEOUT_SECONDS = 300 MINIMUM_JOB_EXTENSION = timedelta(minutes=2) -WEBSOCKET_PORT = 8787 -CONTROLLER_PORT = 8686 - HEARTBEAT_PERIOD_SEC = 30 class BuildJobResult(object): @@ -73,16 +70,16 @@ class BuilderServer(object): self._controller_app = controller_app - def run(self, host, ssl=None): + def run(self, host, websocket_port, controller_port, ssl=None): logger.debug('Initializing the lifecycle manager') self._lifecycle_manager.initialize(self._lifecycle_manager_config) logger.debug('Initializing all members of the event loop') loop = trollius.get_event_loop() - trollius.Task(self._initialize(loop, host, ssl)) + trollius.Task(self._initialize(loop, host, websocket_port, controller_port, ssl)) - logger.debug('Starting server on port %s, with controller on port %s', WEBSOCKET_PORT, - CONTROLLER_PORT) + logger.debug('Starting server on port %s, with controller on port %s', websocket_port, + controller_port) try: loop.run_forever() except KeyboardInterrupt: @@ -169,7 +166,7 @@ class BuilderServer(object): yield From(trollius.sleep(WORK_CHECK_TIMEOUT)) @trollius.coroutine - def _initialize(self, loop, host, ssl=None): + def _initialize(self, loop, host, websocket_port, controller_port, ssl=None): self._loop = loop # Create the WAMP server. @@ -177,8 +174,8 @@ class BuilderServer(object): transport_factory.setProtocolOptions(failByDrop=True) # Initialize the controller server and the WAMP server - create_wsgi_server(self._controller_app, loop=loop, host=host, port=CONTROLLER_PORT, ssl=ssl) - yield From(loop.create_server(transport_factory, host, WEBSOCKET_PORT, ssl=ssl)) + create_wsgi_server(self._controller_app, loop=loop, host=host, port=controller_port, ssl=ssl) + yield From(loop.create_server(transport_factory, host, websocket_port, ssl=ssl)) # Initialize the work queue checker. yield From(self._work_checker())