runbot/runbot_cla/runbot.py

44 lines
1.5 KiB
Python
Raw Normal View History

# -*- encoding: utf-8 -*-
import glob
import io
import logging
import re
from odoo import models
_logger = logging.getLogger(__name__)
class runbot_build(models.Model):
_inherit = "runbot.build"
[REF] runbot: use Docker containers for builds When building Odoo, the instance is started on the same host as the runbot. It means that all the required python packages have to be installed on each runbot hosts with the same versions. Also there is no real separation between builds. Finally, from a security point of view, arbitrary code could be executed on the runbot host. With this commit, the runbot uses Docker containers to build Odoo. During the tests, Odoo http ports are not exposed to the outside, meaning that nobody could interact with that instance. The Docker image used for containers is valid for Odoo branches 10.0, 11.0, 12.0 and master. When building, right before starting the Odoo tests, the tested branch's requirements.txt is now taken into account to adapt the container. On a runbot host, the "docker ps -a" command can be used to have the list of the current builds. The containers are named using the build dest field and the current running job. For example: 123456-12-0-123456_job_30_run Prerequisites: Docker have to be installed on the runbot hosts and the user that runs the runbot should be able to use Docker. Typically, the runbot user have to be added to the docker unix group. On the first build, the Docker image will be built from scratch. It can last several minutes locking the runbot cron during this time. It means that on a multi-runbot configuration, this process will be repeated for each runbot and during this time there will be no builds. To avoid such a situation, the Docker image can be built from the command line. The container.py file can be started like this: python3 container.py build /tmp/build_dir The /tmp/build_dir directory will be created to store the Dockerfile. When the process is done, the "docker images" command should show an image tagged runbot_tests in the odoo repository. At that time, the runbot instance can be started, it will use this image for the builds. Api change: The 'job_*' methods signature has changed, the lock_path is not needed anymore. Docker image informations: Currently, the Docker image is built based on Ubuntu bionic to benefit of the python 3.6 version. Chrome and phantomjs are both installed. The latest wkhtmltopdf (0.12.5) is installed as recommended on our wiki: https://github.com/odoo/odoo/wiki/Wkhtmltopdf
2018-10-29 22:16:12 +07:00
def _job_05_check_cla(self, build, log_path):
cla_glob = glob.glob(build._path("doc/cla/*/*.md"))
if cla_glob:
description = "%s Odoo CLA signature check" % build.author
mo = re.search('[^ <@]+@[^ @>]+', build.author_email or '')
state = "failure"
if mo:
email = mo.group(0).lower()
if re.match('.*@(odoo|openerp|tinyerp)\.com$', email):
state = "success"
else:
try:
cla = ''.join(io.open(f,encoding='utf-8').read() for f in cla_glob)
if cla.lower().find(email) != -1:
state = "success"
except UnicodeDecodeError:
description = 'Invalid CLA encoding (must be utf-8)'
_logger.info('CLA build:%s email:%s result:%s', build.dest, email, state)
status = {
"state": state,
2015-02-17 23:23:52 +07:00
"target_url": "https://www.odoo.com/sign-cla",
"description": description,
"context": "legal/cla"
}
2015-02-09 09:56:19 +07:00
build._log('check_cla', 'CLA %s' % state)
build._github_status_notify_all(status)
# 0 is myself, -1 is everybody else, -2 nothing
return -2