Skip to content

Commit

Permalink
Merge pull request #161 from shanejbrown/fix-missing-file
Browse files Browse the repository at this point in the history
Add retries on creating archive tar
  • Loading branch information
shanejbrown authored Sep 12, 2024
2 parents c10a57a + 7c2914b commit d636fdd
Showing 1 changed file with 14 additions and 4 deletions.
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

0 comments on commit d636fdd

Please sign in to comment.