2019-02-24 18:24:30 +07:00
|
|
|
#!/usr/bin/python3
|
|
|
|
import logging
|
2022-12-16 22:13:32 +07:00
|
|
|
import threading
|
2019-02-24 18:24:30 +07:00
|
|
|
|
2022-12-16 22:13:32 +07:00
|
|
|
from pathlib import Path
|
|
|
|
|
|
|
|
from tools import RunbotClient, run, docker_monitoring_loop
|
2022-07-07 21:23:01 +07:00
|
|
|
|
2019-02-24 18:24:30 +07:00
|
|
|
_logger = logging.getLogger(__name__)
|
|
|
|
|
2022-07-07 21:23:01 +07:00
|
|
|
|
2021-11-25 19:22:19 +07:00
|
|
|
class BuilderClient(RunbotClient):
|
2019-02-24 18:24:30 +07:00
|
|
|
|
2021-11-25 19:22:19 +07:00
|
|
|
def on_start(self):
|
2023-09-18 19:37:30 +07:00
|
|
|
builds_path = self.env['runbot.runbot']._path('build')
|
2022-12-16 22:13:32 +07:00
|
|
|
monitoring_thread = threading.Thread(target=docker_monitoring_loop, args=(builds_path,), daemon=True)
|
|
|
|
monitoring_thread.start()
|
|
|
|
|
2024-02-05 18:00:28 +07:00
|
|
|
if self.env['ir.config_parameter'].sudo().get_param('runbot.runbot_do_fetch'):
|
|
|
|
for repo in self.env['runbot.repo'].search([('mode', '!=', 'disabled')]):
|
|
|
|
repo._update(force=True)
|
2019-02-24 18:24:30 +07:00
|
|
|
|
2023-07-13 15:12:23 +07:00
|
|
|
self.last_docker_updates = None
|
2024-08-06 15:03:40 +07:00
|
|
|
|
2021-11-25 19:22:19 +07:00
|
|
|
def loop_turn(self):
|
2023-07-13 15:12:23 +07:00
|
|
|
icp = self.env['ir.config_parameter']
|
|
|
|
docker_registry_host_id = icp.get_param('runbot.docker_registry_host_id', default=False)
|
|
|
|
is_registry = docker_registry_host_id == str(self.host.id)
|
|
|
|
if is_registry:
|
2024-08-29 19:57:37 +07:00
|
|
|
self.env['runbot.runbot']._start_docker_registry()
|
2024-08-26 15:36:59 +07:00
|
|
|
last_docker_updates = self.env['runbot.dockerfile'].search([('to_build', '=', True)]).mapped('write_date')
|
2023-07-13 15:12:23 +07:00
|
|
|
if self.count == 1 or self.last_docker_updates != last_docker_updates:
|
|
|
|
self.last_docker_updates = last_docker_updates
|
|
|
|
self.host._docker_update_images()
|
|
|
|
self.env.cr.commit()
|
2024-07-18 18:59:58 +07:00
|
|
|
if self.count == 1: # cleanup at second iteration
|
2021-11-25 19:22:19 +07:00
|
|
|
self.env['runbot.runbot']._source_cleanup()
|
2023-07-13 15:12:23 +07:00
|
|
|
self.env.cr.commit()
|
2021-11-25 19:22:19 +07:00
|
|
|
self.env['runbot.build']._local_cleanup()
|
2023-07-13 15:12:23 +07:00
|
|
|
self.env.cr.commit()
|
2021-11-25 19:22:19 +07:00
|
|
|
self.env['runbot.runbot']._docker_cleanup()
|
2023-07-13 15:12:23 +07:00
|
|
|
self.env.cr.commit()
|
2023-09-18 19:37:30 +07:00
|
|
|
self.host._set_psql_conn_count()
|
2023-07-13 15:12:23 +07:00
|
|
|
self.env.cr.commit()
|
2022-06-15 21:29:33 +07:00
|
|
|
self.env['runbot.repo']._update_git_config()
|
2024-02-12 17:21:09 +07:00
|
|
|
self.env.cr.commit()
|
2022-06-15 21:29:33 +07:00
|
|
|
self.git_gc()
|
2024-02-12 17:21:09 +07:00
|
|
|
self.env.cr.commit()
|
2021-11-25 19:22:19 +07:00
|
|
|
return self.env['runbot.runbot']._scheduler_loop_turn(self.host)
|
2019-02-24 18:24:30 +07:00
|
|
|
|
2019-12-19 19:56:22 +07:00
|
|
|
|
2019-02-24 18:24:30 +07:00
|
|
|
if __name__ == '__main__':
|
2021-11-25 19:22:19 +07:00
|
|
|
run(BuilderClient)
|