Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[IMP] runbot: better https support #709

Open
wants to merge 1 commit into
base: 17.0
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
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: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# Odoo Runbot Repository

This repository contains the source code of Odoo testing bot [runbot.odoo.com](http://runbot.odoo.com/runbot) and related addons.
This repository contains the source code of Odoo testing bot [runbot.odoo.com](https://runbot.odoo.com/runbot) and related addons.

------------------

Expand Down
2 changes: 1 addition & 1 deletion runbot/__manifest__.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
'summary': "Runbot",
'description': "Runbot for Odoo 15.0",
'author': "Odoo SA",
'website': "http://runbot.odoo.com",
'website': "https://runbot.odoo.com",
'category': 'Website',
'version': '5.2',
'application': True,
Expand Down
18 changes: 6 additions & 12 deletions runbot/models/build.py
Original file line number Diff line number Diff line change
Expand Up @@ -163,12 +163,12 @@ class BuildResult(models.Model):

requested_action = fields.Selection([('wake_up', 'To wake up'), ('deathrow', 'To kill')], string='Action requested', index=True)
# web infos
host = fields.Char('Host')
host = fields.Char('Host name')
keep_host = fields.Boolean('Keep host on rebuild and for children')
host_id = fields.Many2one('runbot.host', 'Host', compute='_compute_host_id')

port = fields.Integer('Port')
dest = fields.Char(compute='_compute_dest', type='char', string='Dest', readonly=1, store=True)
domain = fields.Char(compute='_compute_domain', type='char', string='URL')
# logs and stats
log_ids = fields.One2many('ir.logging', 'build_id', string='Logs')
error_log_ids = fields.One2many('ir.logging', 'build_id', domain=[('level', 'in', ['WARNING', 'ERROR', 'CRITICAL'])], string='Error Logs')
Expand Down Expand Up @@ -207,8 +207,8 @@ class BuildResult(models.Model):

parent_id = fields.Many2one('runbot.build', 'Parent Build', index=True)
parent_path = fields.Char('Parent path', index=True)
top_parent = fields.Many2one('runbot.build', compute='_compute_top_parent')
ancestors = fields.Many2many('runbot.build', compute='_compute_ancestors')
top_parent = fields.Many2one('runbot.build', compute='_compute_top_parent')
ancestors = fields.Many2many('runbot.build', compute='_compute_ancestors')
# should we add a has children stored boolean?
children_ids = fields.One2many('runbot.build', 'parent_id')

Expand Down Expand Up @@ -392,11 +392,6 @@ def _compute_dest(self):
nickname = re.sub(r'_|/|\.', '-', nickname)
build.dest = ("%05d-%s" % (build.id or 0, nickname[:32])).lower()

@api.depends('port', 'dest', 'host')
def _compute_domain(self):
for build in self:
build.domain = "%s.%s" % (build.dest, build.host)

@api.depends_context('batch')
def _compute_build_url(self):
batch = self.env.context.get('batch')
Expand Down Expand Up @@ -738,7 +733,6 @@ def _schedule(self):
build._github_status()
build._run_job()


def _run_job(self):
# run job
for build in self:
Expand Down Expand Up @@ -794,8 +788,8 @@ def _path(self, *l, **kw):
root = self.env['runbot.runbot']._root()
return os.path.join(root, 'build', build.dest, *l)

def http_log_url(self):
return 'http://%s/runbot/static/build/%s/logs/' % (self.host, self.dest)
def http_log_url(self, logs='logs'):
return f'{self.host_id.url()}/runbot/static/build/{self.dest}/{logs}/'

def _server(self, *path):
"""Return the absolute path to the direcory containing the server file, adding optional *path"""
Expand Down
17 changes: 8 additions & 9 deletions runbot/models/build_config.py
Original file line number Diff line number Diff line change
Expand Up @@ -271,8 +271,7 @@ def _run(self, build):
build.write({'job_start': now(), 'job_end': False}) # state, ...
log_link = ''
if self._has_log():
log_url = f'http://{build.host}'
url = f"{log_url}/runbot/static/build/{build.dest}/logs/{self.name}.txt"
url = f"{build.http_log_url}{self.name}.txt"
log_link = f'[@icon-file-text]({url})'
build._log('run', 'Starting step **%s** from config **%s** %s' % (self.name, build.params_id.config_id.name, log_link), log_type='markdown', level='SEPARATOR')
self._run_step(build, log_path)
Expand Down Expand Up @@ -742,8 +741,8 @@ def _run_restore(self, build, log_path):
dump_build = params.dump_db.build_id or build.parent_id
assert download_db_suffix and dump_build
download_db_name = '%s-%s' % (dump_build.dest, download_db_suffix)
zip_name = '%s.zip' % download_db_name
dump_url = '%s%s' % (dump_build.http_log_url(), zip_name)
zip_name = f'{download_db_name}.zip'
dump_url = f'{dump_build.http_log_url()}{zip_name}'
build._log('test-migration', 'Restoring dump [%s](%s) from build [%s](%s)' % (zip_name, dump_url, dump_build.id, dump_build.build_url), log_type='markdown')
restore_suffix = self.restore_rename_db_suffix or params.dump_db.db_suffix or suffix
assert restore_suffix
Expand Down Expand Up @@ -855,19 +854,19 @@ def log_end(self, build):
if self.job_type == 'install_odoo':
kwargs['message'] += ' $$fa-download$$'
db_suffix = build.params_id.config_data.get('db_name') or self.db_name
kwargs['path'] = '%s%s-%s.zip' % (build.http_log_url(), build.dest, db_suffix)
kwargs['path'] = f'{build.http_log_url()}{build.dest}-{db_suffix}.zip'
kwargs['log_type'] = 'link'
build._log('', **kwargs)

if self.coverage:
xml_url = '%scoverage.xml' % build.http_log_url()
html_url = 'http://%s/runbot/static/build/%s/coverage/index.html' % (build.host, build.dest)
xml_url = f'{build.http_log_url()}coverage.xml'
html_url = f'{build.http_log_url("coverage")}index.html'
message = 'Coverage report: [xml @icon-download](%s), [html @icon-eye](%s)' % (xml_url, html_url)
build._log('end_job', message, log_type='markdown')

if self.flamegraph:
dat_url = '%sflame_%s.%s' % (build.http_log_url(), self.name, 'log.gz')
svg_url = '%sflame_%s.%s' % (build.http_log_url(), self.name, 'svg')
dat_url = f'{build.http_log_url()}flame_{self.name,}.log.gz'
svg_url = f'{build.http_log_url()}flame_{self.name,}.svg'
message = 'Flamegraph report: [data @icon-download](%s), [svg @icon-eye](%s)' % (dat_url, svg_url)
build._log('end_job', message, log_type='markdown')

Expand Down
25 changes: 23 additions & 2 deletions runbot/models/host.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
from collections import defaultdict

from odoo import models, fields, api
from odoo.tools import config
from odoo.tools import config, ormcache
from ..common import fqdn, local_pgadmin_cursor, os, list_local_dbs, local_pg_cursor
from ..container import docker_build

Expand Down Expand Up @@ -36,6 +36,8 @@ class Host(models.Model):
last_exception = fields.Char('Last exception')
exception_count = fields.Integer('Exception count')
psql_conn_count = fields.Integer('SQL connections count', default=0)
url = fields.Char('Host base url', compute="_compute_url")
https_enable = fields.Boolean('Use https', default=True)

def _compute_nb(self):
groups = self.env['runbot.build'].read_group(
Expand Down Expand Up @@ -141,9 +143,22 @@ def _docker_build_dockerfile(self, dockerfile, workdir):
def _get_work_path(self):
return os.path.abspath(os.path.join(os.path.dirname(__file__), '../static'))

@ormcache()
def _cache(self):
{host.name: host.id for host in self.search([])}

@api.model
def _get_current(self):
name = self._get_current_name()
return self._get_host(self._get_current_name())

@api.model
def _get_host(self, name):
if not name:
return self.browse()
host = self._cache().get(name)
if host:
return host
self.clear_caches()
return self.search([('name', '=', name)]) or self.create({'name': name})

@api.model
Expand Down Expand Up @@ -244,3 +259,9 @@ def process_logs(self, build_ids=None):
logs_db_name = self.env['ir.config_parameter'].get_param('runbot.logdb_name')
with local_pg_cursor(logs_db_name) as local_cr:
local_cr.execute("DELETE FROM ir_logging WHERE id in %s", [tuple(local_log_ids)])

def url(self, subdomain=''):
if subdomain:
subdomain = f'{subdomain}.'
protocol = 'https' if self.https_enable else 'http'
return f'{protocol}://{subdomain}{self.name}'
11 changes: 5 additions & 6 deletions runbot/templates/utils.xml
Original file line number Diff line number Diff line change
Expand Up @@ -201,7 +201,7 @@
<span t-else="" t-attf-class="btn btn-default disabled slot_name">
<span t-esc="slot.trigger_id.name"/>
</span>
<a t-if="bu.local_state == 'running' and bu.database_ids" t-attf-href="http://{{sorted(bu.mapped('database_ids.name'))[0]}}.{{bu.host}}" class="fa fa-sign-in btn btn-info"/>
<a t-if="bu.local_state == 'running' and bu.database_ids" t-att-href="bu.host_id.url(sorted(bu.mapped('database_ids.name'))[0])" class="fa fa-sign-in btn btn-info"/>
<a t-if="bu.static_run" t-att-href="bu.static_run" class="fa fa-sign-in btn btn-info"/>
<t t-if="bu" t-call="runbot.build_menu"/>
<a t-if="not bu" groups="base.group_user" class="btn btn-default" title="Create build" t-attf-href="/runbot/batch/slot/{{slot.id}}/build">
Expand All @@ -213,7 +213,7 @@
<template id="runbot.build_button">
<div t-attf-class="pull-right">
<div t-attf-class="btn-group {{klass}}">
<a t-if="bu.local_state == 'running' and bu.database_ids" t-attf-href="http://{{sorted(bu.mapped('database_ids.name'))[0]}}.{{bu.host}}" class="btn btn-info" title="Sign in on this build" aria-label="Sign in on this build">
<a t-if="bu.local_state == 'running' and bu.database_ids" t-attf-href="bu.host_id.url(sorted(bu.mapped('database_ids.name'))[0])" class="btn btn-info" title="Sign in on this build" aria-label="Sign in on this build">
<i class="fa fa-sign-in"/>
</a>
<a t-if="bu.static_run" t-att-href="bu.static_run" class="btn btn-info" title="View result" aria-label="View result">
Expand Down Expand Up @@ -265,12 +265,12 @@
</a>
<t t-if="bu.local_state=='running'">
<t t-foreach="bu.database_ids.sorted('name')[1:]" t-as="db">
<a class="dropdown-item" t-attf-href="http://{{db.name}}.{{bu.host}}/">
<a class="dropdown-item" t-att-href="bu.host_id.url(db.name)">
<i class="fa fa-sign-in"/>
Connect <t t-esc="db.db_suffix"></t>
</a>
</t>
<a class="dropdown-item" t-attf-href="http://{{bu.domain}}/web/database/selector">
<a class="dropdown-item" t-attf-href="{{bu.host_id.url(bu.dest)}}/web/database/selector">
<i class="fa fa-sign-in"/>
Database selector
</a>
Expand Down Expand Up @@ -310,9 +310,8 @@
</t>
</t>
<div t-if="bu.global_state not in ('testing', 'waiting', 'pending')" groups="base.group_user" class="dropdown-divider"/>
<t t-set="log_url" t-value="'http://%s' % bu.host if bu.host != fqdn else ''"/>
<t t-if="bu.host" t-foreach="bu.log_list.split(',') if bu.log_list else []" t-as="log_name">
<a class="dropdown-item" t-attf-href="{{log_url}}/runbot/static/build/#{bu.dest}/logs/#{log_name}.txt">
<a class="dropdown-item" t-attf-href="{{bu.http_log_url}}{{log_name}}.txt">
<i class="fa fa-file-text-o"/>
Full
<t t-esc="log_name"/>
Expand Down
1 change: 1 addition & 0 deletions runbot/views/host_views.xml
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
<field name="last_success" readonly='1'/>
<field name="assigned_only"/>
<field name="nb_worker"/>
<field name="https_enable"/>
<field name="last_exception" readonly='1'/>
<field name="exception_count" readonly='1'/>
</group>
Expand Down