From 70e8b1569097f18b4f549651a5831bb4e8d085a5 Mon Sep 17 00:00:00 2001 From: Xavier-Do Date: Tue, 23 Aug 2022 14:53:27 +0200 Subject: [PATCH] [IMP] runbot: add websocket support --- runbot/common.py | 4 +++ runbot/models/build.py | 5 +++- runbot/models/build_config.py | 37 +++++++++++++++++--------- runbot/templates/nginx.xml | 8 ++++++ runbot/tests/test_build_config_step.py | 1 + 5 files changed, 41 insertions(+), 14 deletions(-) diff --git a/runbot/common.py b/runbot/common.py index dae520af..20292b96 100644 --- a/runbot/common.py +++ b/runbot/common.py @@ -42,6 +42,10 @@ def now(): return time.strftime(DEFAULT_SERVER_DATETIME_FORMAT) +def findall(filename, pattern): + return set(re.findall(pattern, open(filename).read())) + + def grep(filename, string): if os.path.isfile(filename): return find(filename, string) != -1 diff --git a/runbot/models/build.py b/runbot/models/build.py index 551ecce0..23b355d8 100644 --- a/runbot/models/build.py +++ b/runbot/models/build.py @@ -8,7 +8,7 @@ import subprocess import time import datetime import hashlib -from ..common import dt2time, fqdn, now, grep, local_pgadmin_cursor, s2human, dest_reg, os, list_local_dbs, pseudo_markdown, RunbotException +from ..common import dt2time, fqdn, now, grep, local_pgadmin_cursor, s2human, dest_reg, os, list_local_dbs, pseudo_markdown, RunbotException, findall from ..container import docker_stop, docker_state, Command, docker_run from ..fields import JsonDictField from odoo import models, fields, api @@ -1171,3 +1171,6 @@ class BuildResult(models.Model): commit = build_commit.commit_id if 'base_' not in build_commit.match_type and commit.repo_id in trigger.repo_ids: commit._github_status(build, trigger.ci_context, state, target_url, desc) + + def parse_config(self): + return set(findall(self._server("tools/config.py"), '--[\w-]+', )) diff --git a/runbot/models/build_config.py b/runbot/models/build_config.py index a55ee02d..f86ed9f9 100644 --- a/runbot/models/build_config.py +++ b/runbot/models/build_config.py @@ -343,13 +343,21 @@ class ConfigStep(models.Model): build._log('run', 'Start running build %s' % build.dest) # run server cmd = build._cmd(local_only=False) - if os.path.exists(build._get_server_commit()._source_path('addons/im_livechat')): + + available_options = build.parse_config() + + if "--workers" in available_options: cmd += ["--workers", "2"] + + if "--gevent-port" in available_options: + cmd += ["--gevent-port", "8070"] + + elif "--longpolling-port" in available_options: cmd += ["--longpolling-port", "8070"] + + if "--max-cron-threads" in available_options: cmd += ["--max-cron-threads", "1"] - else: - # not sure, to avoid old server to check other dbs - cmd += ["--max-cron-threads", "0"] + install_steps = [step.db_name for step in build.params_id.config_id.step_ids() if step.job_type == 'install_odoo'] db_name = build.params_id.config_data.get('db_name') or 'all' in install_steps and 'all' or install_steps[0] @@ -357,15 +365,16 @@ class ConfigStep(models.Model): cmd += ['-d', '%s-%s' % (build.dest, db_name)] icp = self.env['ir.config_parameter'].sudo() - if grep(build._server("tools/config.py"), "proxy-mode"): + if "--proxy-mode" in available_options: cmd += ["--proxy-mode"] - if grep(build._server("tools/config.py"), "db-filter"): + if "--db-filter" in available_options: cmd += ['--db-filter', '%d.*$'] - smtp_host = docker_get_gateway_ip() - if smtp_host: - cmd += ['--smtp', smtp_host] + if "--smtp" in available_options: + smtp_host = docker_get_gateway_ip() + if smtp_host: + cmd += ['--smtp', smtp_host] extra_params = self.extra_params or '' if extra_params: @@ -406,14 +415,16 @@ class ConfigStep(models.Model): if mods and '-i' not in extra_params: cmd += ['-i', mods] config_path = build._server("tools/config.py") + + available_options = build.parse_config() if self.test_enable: - if grep(config_path, "test-enable"): + if "--test-enable" in available_options: cmd.extend(['--test-enable']) else: build._log('test_all', 'Installing modules without testing', level='WARNING') test_tags_in_extra = '--test-tags' in extra_params if self.test_tags or test_tags_in_extra: - if grep(config_path, "test-tags"): + if "--test-tags" in available_options: if not test_tags_in_extra: test_tags = self.test_tags.replace(' ', '') if self.enable_auto_tags: @@ -429,10 +440,10 @@ class ConfigStep(models.Model): test_tags = ','.join(auto_tags) cmd.extend(['--test-tags', test_tags]) - if grep(config_path, "--screenshots"): + if "--screenshots" in available_options: cmd.add_config_tuple('screenshots', '/data/build/tests') - if grep(config_path, "--screencasts") and self.env['ir.config_parameter'].sudo().get_param('runbot.enable_screencast', False): + if "--screencasts" in available_options and self.env['ir.config_parameter'].sudo().get_param('runbot.enable_screencast', False): cmd.add_config_tuple('screencasts', '/data/build/tests') cmd.append('--stop-after-init') # install job should always finish diff --git a/runbot/templates/nginx.xml b/runbot/templates/nginx.xml index 8dadb519..cd90dfa8 100644 --- a/runbot/templates/nginx.xml +++ b/runbot/templates/nginx.xml @@ -55,6 +55,14 @@ server { server_name ~^(-[a-z0-9_]+)?\.$; location / { proxy_pass http://127.0.0.1:; } location /longpolling { proxy_pass http://127.0.0.1:; } + location /websocket { + proxy_pass http://127.0.0.1:; + proxy_set_header X-Forwarded-Host $host; + proxy_set_header X-Forwarded-Proto $real_scheme; + proxy_set_header Host $host; + proxy_set_header Upgrade $http_upgrade; + proxy_set_header Connection "Upgrade"; + } } server { diff --git a/runbot/tests/test_build_config_step.py b/runbot/tests/test_build_config_step.py index a167b524..9f927566 100644 --- a/runbot/tests/test_build_config_step.py +++ b/runbot/tests/test_build_config_step.py @@ -22,6 +22,7 @@ class TestBuildConfigStep(RunbotCase): 'params_id': self.base_params.copy({'commit_link_ids': [(0, 0, {'commit_id': server_commit.id})]}).id, }) self.start_patcher('find_patcher', 'odoo.addons.runbot.common.find', 0) + self.start_patcher('findall_patcher', 'odoo.addons.runbot.models.build.BuildResult.parse_config', {}) def test_config_step_create_results(self): """ Test child builds are taken into account"""