fix disappearing build logs when deploying

This commit is contained in:
Michael Pöhn 2019-10-15 14:28:45 +02:00
parent 6d11da5e13
commit d665106813

View file

@ -3253,42 +3253,41 @@ def deploy_build_log_with_rsync(appid, vercode, log_content):
logging.warning(_('skip deploying full build logs: log content is empty')) logging.warning(_('skip deploying full build logs: log content is empty'))
return return
with tempfile.TemporaryDirectory() as tmpdir: # gzip compress log file
# gzip compress log file log_gz_path = os.path.join('repo',
log_gz_path = os.path.join( '{pkg}_{ver}.log.gz'.format(pkg=appid,
tmpdir, '{pkg}_{ver}.log.gz'.format(pkg=appid, ver=vercode))
ver=vercode)) with gzip.open(log_gz_path, 'wb') as f:
with gzip.open(log_gz_path, 'wb') as f: if isinstance(log_content, str):
if isinstance(log_content, str): f.write(bytes(log_content, 'utf-8'))
f.write(bytes(log_content, 'utf-8')) else:
else: f.write(log_content)
f.write(log_content)
# TODO: sign compressed log file, if a signing key is configured # TODO: sign compressed log file, if a signing key is configured
for webroot in config.get('serverwebroot', []): for webroot in config.get('serverwebroot', []):
dest_path = os.path.join(webroot, "repo") dest_path = os.path.join(webroot, "repo")
if not dest_path.endswith('/'): if not dest_path.endswith('/'):
dest_path += '/' # make sure rsync knows this is a directory dest_path += '/' # make sure rsync knows this is a directory
cmd = ['rsync', cmd = ['rsync',
'--archive', '--archive',
'--delete-after', '--delete-after',
'--safe-links'] '--safe-links']
if options.verbose: if options.verbose:
cmd += ['--verbose'] cmd += ['--verbose']
if options.quiet: if options.quiet:
cmd += ['--quiet'] cmd += ['--quiet']
if 'identity_file' in config: if 'identity_file' in config:
cmd += ['-e', 'ssh -oBatchMode=yes -oIdentitiesOnly=yes -i ' + config['identity_file']] cmd += ['-e', 'ssh -oBatchMode=yes -oIdentitiesOnly=yes -i ' + config['identity_file']]
cmd += [log_gz_path, dest_path] cmd += [log_gz_path, dest_path]
# TODO: also deploy signature file if present # TODO: also deploy signature file if present
retcode = subprocess.call(cmd) retcode = subprocess.call(cmd)
if retcode: if retcode:
logging.warning(_("failed deploying build logs to '{path}'").format(path=webroot)) logging.warning(_("failed deploying build logs to '{path}'").format(path=webroot))
else: else:
logging.info(_("deployed build logs to '{path}'").format(path=webroot)) logging.info(_("deployed build logs to '{path}'").format(path=webroot))
def get_per_app_repos(): def get_per_app_repos():
@ -3321,6 +3320,7 @@ def is_repo_file(filename):
return os.path.isfile(filename) \ return os.path.isfile(filename) \
and not filename.endswith(b'.asc') \ and not filename.endswith(b'.asc') \
and not filename.endswith(b'.sig') \ and not filename.endswith(b'.sig') \
and not filename.endswith(b'.log.gz') \
and os.path.basename(filename) not in [ and os.path.basename(filename) not in [
b'index.jar', b'index.jar',
b'index_unsigned.jar', b'index_unsigned.jar',