Skip to content

Commit 29aaad8

Browse files
committed
[IMP] runbot: create database inside docker
To allow to run postgress in docker we cannot make any maintenance on database from outside the docker anymore, meaning that the database creations needs to be done in the docker.
1 parent 340f4fa commit 29aaad8

3 files changed

Lines changed: 5 additions & 15 deletions

File tree

runbot/models/build.py

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1206,15 +1206,6 @@ def _local_pg_dropdb(self, dbname):
12061206
host_name = self.env['runbot.host']._get_current_name()
12071207
self.env['runbot.runbot']._warning(f'Host {host_name}: {msg}')
12081208

1209-
def _local_pg_createdb(self, dbname):
1210-
icp = self.env['ir.config_parameter']
1211-
db_template = icp.get_param('runbot.runbot_db_template', default='template0')
1212-
self._local_pg_dropdb(dbname)
1213-
_logger.info("createdb %s", dbname)
1214-
with local_pgadmin_cursor() as local_cr:
1215-
local_cr.execute(sql.SQL("""CREATE DATABASE {} TEMPLATE %s LC_COLLATE 'C' ENCODING 'unicode'""").format(sql.Identifier(dbname)), (db_template,))
1216-
self.env['runbot.database'].create({'name': dbname, 'build_id': self.id})
1217-
12181209
def _log(self, func, message, *args, level='INFO', log_type='runbot', path='runbot'):
12191210
def truncate(message, maxlenght=300000):
12201211
if len(message) > maxlenght:

runbot/models/build_config.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -428,8 +428,8 @@ class ConfigStep(models.Model):
428428
dockerfile_id = fields.Many2one('runbot.dockerfile', string='Dockerfile')
429429
dockerfile_variant = fields.Char('Docker Variant')
430430
# install_odoo
431-
create_db = fields.Boolean('Create Db', default=True, tracking=True) # future
432-
custom_db_name = fields.Char('Custom Db Name', tracking=True) # future
431+
create_db = fields.Boolean('Create Db', default=True, tracking=True) # TODO remove
432+
custom_db_name = fields.Char('Custom Db Name', tracking=True)
433433
install_modules = fields.Char('Modules to install', help="List of module patterns to install, use * to install all available modules, prefix the pattern with dash to remove the module.", default='', tracking=True)
434434
db_name = fields.Char('Db Name', compute='_compute_db_name', inverse='_inverse_db_name', tracking=True)
435435
cpu_limit = fields.Integer('Cpu limit', default=3600, tracking=True)
@@ -777,8 +777,6 @@ def _run_install_odoo(self, build, config_data=None):
777777
db_suffix = config_data.get('db_name') or (build.params_id.dump_db.db_suffix if not self.create_db else False) or self._get_db_name(build)
778778
db_suffix = re.sub(r'[^a-z0-9\-_]', '_', db_suffix.lower())
779779
db_name = '%s-%s' % (build.dest, db_suffix)
780-
if modules_to_install and self.create_db:
781-
build._local_pg_createdb(db_name)
782780
cmd += ['-d', db_name]
783781

784782
# Demo data behavior changed in 18.1 -> demo data became opt-in instead of opt-out
@@ -1167,7 +1165,8 @@ def _run_restore(self, build, config_data=None):
11671165
target_suffix = config_data.get('target_suffix', self.restore_rename_db_suffix or download_db_suffix)
11681166
restore_db_name = '%s-%s' % (build.dest, target_suffix)
11691167

1170-
build._local_pg_createdb(restore_db_name)
1168+
icp = self.env['ir.config_parameter']
1169+
db_template = icp.get_param('runbot.runbot_db_template', default='template0')
11711170
cmd = ' && '.join([
11721171
'mkdir /data/build/restore',
11731172
'cd /data/build/restore',
@@ -1177,6 +1176,7 @@ def _run_restore(self, build, config_data=None):
11771176
'mkdir -p /data/build/datadir/filestore/%s' % restore_db_name,
11781177
'mv filestore/* /data/build/datadir/filestore/%s' % restore_db_name,
11791178
'echo "### restoring db"',
1179+
'createdb %s -T %s' % (restore_db_name, db_template),
11801180
'psql -q %s < dump.sql' % (restore_db_name),
11811181
'echo "### performing an analyze"',
11821182
'psql -q -d %s -c "ANALYZE;"' % restore_db_name,

runbot/tests/common.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -227,7 +227,6 @@ def mock_git(repo, cmd, quiet=False, input_data=None, raw=False):
227227
self.start_patcher('set_psql_conn_count', 'odoo.addons.runbot.models.host.Host._set_psql_conn_count', None)
228228
self.start_patcher('reload_nginx', 'odoo.addons.runbot.models.runbot.Runbot._reload_nginx', None)
229229
self.start_patcher('update_commits_infos', 'odoo.addons.runbot.models.batch.Batch._update_commits_infos', None)
230-
self.start_patcher('_local_pg_createdb', 'odoo.addons.runbot.models.build.BuildResult._local_pg_createdb', True)
231230
self.start_patcher('getmtime', 'odoo.addons.runbot.common.os.path.getmtime', datetime.datetime.now().timestamp())
232231
self.start_patcher('file_exist', 'odoo.tools.misc.os.path.exists', True)
233232
self.start_patcher('_get_py_version', 'odoo.addons.runbot.models.build.BuildResult._get_py_version', 3)

0 commit comments

Comments
 (0)