mirror of
https://github.com/odoo/runbot.git
synced 2025-03-16 07:55:45 +07:00
[FIX] runbot: clean running dockers with done builds
In different situations, a docker container may stay alive even if the build global_state is done. This can lead to a build failure when a build wants to go in running state and tries to expose the same ports as the left over build.
This commit is contained in:
parent
5b12f37c74
commit
5ff9cc2382
@ -19,6 +19,7 @@ from odoo.tools.misc import DEFAULT_SERVER_DATETIME_FORMAT
|
||||
|
||||
_logger = logging.getLogger(__name__)
|
||||
|
||||
dest_reg = re.compile(r'^\d{5,}-.{1,32}-[\da-f]{6}(.*)*$')
|
||||
|
||||
class Commit():
|
||||
def __init__(self, repo, sha):
|
||||
|
@ -135,6 +135,13 @@ def docker_get_gateway_ip():
|
||||
except KeyError:
|
||||
return None
|
||||
|
||||
def docker_ps():
|
||||
"""Return a list of running containers names"""
|
||||
docker_ps = subprocess.run(['docker', 'ps', '--format', '{{.Names}}'], stderr=subprocess.DEVNULL, stdout=subprocess.PIPE)
|
||||
if docker_ps.returncode !=0:
|
||||
return []
|
||||
return docker_ps.stdout.decode().strip().split('\n')
|
||||
|
||||
def build(args):
|
||||
"""Build container from CLI"""
|
||||
_logger.info('Building the base image container')
|
||||
|
@ -9,7 +9,7 @@ import shutil
|
||||
import subprocess
|
||||
import time
|
||||
import datetime
|
||||
from ..common import dt2time, fqdn, now, grep, uniq_list, local_pgadmin_cursor, s2human, Commit
|
||||
from ..common import dt2time, fqdn, now, grep, uniq_list, local_pgadmin_cursor, s2human, Commit, dest_reg
|
||||
from ..container import docker_build, docker_stop, docker_is_running, Command
|
||||
from odoo.addons.runbot.models.repo import HashMissingException, ArchiveFailException
|
||||
from odoo import models, fields, api
|
||||
@ -461,7 +461,6 @@ class runbot_build(models.Model):
|
||||
def cleanup(dest_list, func, max_days, label):
|
||||
dest_by_builds_ids = defaultdict(list)
|
||||
ignored = set()
|
||||
dest_reg = re.compile(r'^\d{5,}-.{1,32}-[\da-f]{6}(.*)*$')
|
||||
for dest in dest_list:
|
||||
try:
|
||||
if not dest_reg.match(dest):
|
||||
|
@ -18,7 +18,7 @@ from odoo.tools.misc import DEFAULT_SERVER_DATETIME_FORMAT
|
||||
from odoo import models, fields, api, registry
|
||||
from odoo.modules.module import get_module_resource
|
||||
from odoo.tools import config
|
||||
from ..common import fqdn, dt2time, Commit
|
||||
from ..common import fqdn, dt2time, Commit, dest_reg
|
||||
from psycopg2.extensions import TransactionRollbackError
|
||||
_logger = logging.getLogger(__name__)
|
||||
|
||||
@ -542,6 +542,15 @@ class runbot_repo(models.Model):
|
||||
"""
|
||||
if hostname != fqdn():
|
||||
return 'Not for me'
|
||||
|
||||
# docker cleanup
|
||||
containers = {int(dc.split('-', 1)[0]):dc for dc in docker_ps() if dest_reg.match(dc)}
|
||||
if containers:
|
||||
candidates = env['runbot.build'].search([('id', 'in', list(containers.keys())), ('local_state', '=', 'done')])
|
||||
for c in candidates:
|
||||
_logger.info('container %s found running with build state done', containers[c.id])
|
||||
docker_stop(containers[c.id])
|
||||
|
||||
start_time = time.time()
|
||||
timeout = self._get_cron_period()
|
||||
icp = self.env['ir.config_parameter']
|
||||
|
Loading…
Reference in New Issue
Block a user