Skip to content

Commit

Permalink
Fix single platform builds to use .dockerignore
Browse files Browse the repository at this point in the history
  • Loading branch information
shanejbrown committed Jun 25, 2024
1 parent 9c083d6 commit 3d447dc
Showing 1 changed file with 43 additions and 24 deletions.
67 changes: 43 additions & 24 deletions buildrunner/docker/builder.py
Original file line number Diff line number Diff line change
Expand Up @@ -93,34 +93,53 @@ def build(
cache_from = []
if buildargs is None:
buildargs = {}
# create our own tar file, injecting the appropriate paths
# pylint: disable=consider-using-with
_fileobj = tempfile.NamedTemporaryFile(dir=self.temp_dir)
with tarfile.open(mode="w", fileobj=_fileobj) as tfile:
if self.path:
tfile.add(self.path, arcname=".")
if self.inject:
for to_inject, dest in self.inject.items():
tfile.add(to_inject, arcname=dest)
if self.dockerfile:
tfile.add(self.dockerfile, arcname="./Dockerfile")
_fileobj.seek(0)

# Always add default registry to build args
buildargs["DOCKER_REGISTRY"] = self.docker_registry
stream = None

stream = self.docker_client.build(
path=None,
nocache=nocache,
cache_from=cache_from,
custom_context=True,
fileobj=_fileobj,
rm=rm,
pull=pull,
buildargs=self._sanitize_buildargs(buildargs),
platform=platform,
target=target,
)
# create our own tar file, injecting the appropriate paths
# pylint: disable=consider-using-with
if self.inject or not self.path:
logger.info(
"[Warning] When injecting files into the build context the .dockerignore is not used."
)

_fileobj = tempfile.NamedTemporaryFile(dir=self.temp_dir)
with tarfile.open(mode="w", fileobj=_fileobj) as tfile:
if self.path:
tfile.add(self.path, arcname=".")
if self.inject:
for to_inject, dest in self.inject.items():
tfile.add(to_inject, arcname=dest)
if self.dockerfile:
tfile.add(self.dockerfile, arcname="./Dockerfile")
_fileobj.seek(0)

stream = self.docker_client.build(
path=None,
nocache=nocache,
cache_from=cache_from,
custom_context=True,
fileobj=_fileobj,
rm=rm,
pull=pull,
buildargs=self._sanitize_buildargs(buildargs),
platform=platform,
target=target,
)
else:
stream = self.docker_client.build(
path=self.path,
nocache=nocache,
cache_from=cache_from,
rm=rm,
pull=pull,
buildargs=self._sanitize_buildargs(buildargs),
platform=platform,
target=target,
dockerfile=self.dockerfile,
)

# monitor output for logs and status
exit_code = 0
Expand Down

0 comments on commit 3d447dc

Please sign in to comment.