Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add retries on creating archive tar #161

Merged
merged 1 commit into from
Sep 12, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 14 additions & 4 deletions buildrunner/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@

import requests

from retry import retry
from vcsinfo import detect_vcs, VCSUnsupported, VCSMissingRevision

from buildrunner import docker, loggers
Expand Down Expand Up @@ -226,6 +227,14 @@ def add_artifact(self, artifact_file, properties):
"""
self.artifacts[artifact_file] = properties

@retry(exceptions=FileNotFoundError, tries=3, delay=1)
def _create_archive_tarfile(self, dir_to_add, _fileobj, filter_func):
"""
Create the tarfile with retries
"""
with tarfile.open(mode="w", fileobj=_fileobj) as tfile:
tfile.add(dir_to_add, arcname="", filter=filter_func)

def get_source_archive_path(self):
"""
Create the source archive for use in remote builds or to build the
Expand All @@ -238,9 +247,9 @@ def get_source_archive_path(self):
with open(buildignore, "r", encoding="utf-8") as _file:
excludes = _file.read().splitlines()

def _exclude_working_dir(tarinfo):
def _filter_results_and_excludes(tarinfo):
"""
Filter to exclude results dir from source archive.
Filter to exclude results dir and listed excludes from source archive.
"""
if tarinfo.name == os.path.basename(self.build_results_dir):
return None
Expand All @@ -257,8 +266,9 @@ def _exclude_working_dir(tarinfo):
delete=False,
dir=BuildRunnerConfig.get_instance().global_config.temp_dir,
)
with tarfile.open(mode="w", fileobj=_fileobj) as tfile:
tfile.add(self.build_dir, arcname="", filter=_exclude_working_dir)
self._create_archive_tarfile(
self.build_dir, _fileobj, _filter_results_and_excludes
)
self._source_archive = _fileobj.name
finally:
if _fileobj:
Expand Down
Loading