Skip to content

Commit

Permalink
Merge pull request #155 from shanejbrown/fix-pull-test
Browse files Browse the repository at this point in the history
Only pull docker daemon proxy image in tests
  • Loading branch information
shanejbrown authored Aug 21, 2024
2 parents 510dd2a + 9d0881c commit 9f5462e
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 20 deletions.
32 changes: 15 additions & 17 deletions buildrunner/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -138,7 +138,7 @@ def __init__(
tmp_files=self.tmp_files,
global_config_overrides=global_config_overrides,
)
buildrunner_config = BuildRunnerConfig.get_instance()
self.buildrunner_config = BuildRunnerConfig.get_instance()

# cleanup local cache
if self.cleanup_cache:
Expand All @@ -148,7 +148,7 @@ def __init__(
missing_steps = [
step
for step in steps_to_run
if step not in buildrunner_config.run_config.steps
if step not in self.buildrunner_config.run_config.steps
]
if missing_steps:
raise BuildRunnerConfigurationError(
Expand Down Expand Up @@ -276,13 +276,12 @@ def get_source_image(self):
source_archive_path: "source.tar",
SOURCE_DOCKERFILE: "Dockerfile",
}
buildrunner_config = BuildRunnerConfig.get_instance()
if buildrunner_config.run_config.use_legacy_builder:
if self.buildrunner_config.run_config.use_legacy_builder:
image = legacy_builder.build_image(
temp_dir=buildrunner_config.global_config.temp_dir,
temp_dir=self.buildrunner_config.global_config.temp_dir,
inject=inject,
timeout=self.docker_timeout,
docker_registry=buildrunner_config.global_config.docker_registry,
docker_registry=self.buildrunner_config.global_config.docker_registry,
nocache=True,
pull=False,
)
Expand Down Expand Up @@ -359,29 +358,28 @@ def run(self): # pylint: disable=too-many-statements,too-many-branches,too-many
self.exit_code = None

exit_explanation = None
buildrunner_config = BuildRunnerConfig.get_instance()
try: # pylint: disable=too-many-nested-blocks
with MultiplatformImageBuilder(
docker_registry=buildrunner_config.global_config.docker_registry,
build_registry=buildrunner_config.global_config.build_registry,
temp_dir=buildrunner_config.global_config.temp_dir,
platform_builders=buildrunner_config.global_config.platform_builders,
cache_builders=buildrunner_config.global_config.docker_build_cache.builders,
cache_from=buildrunner_config.global_config.docker_build_cache.from_config,
cache_to=buildrunner_config.global_config.docker_build_cache.to_config,
docker_registry=self.buildrunner_config.global_config.docker_registry,
build_registry=self.buildrunner_config.global_config.build_registry,
temp_dir=self.buildrunner_config.global_config.temp_dir,
platform_builders=self.buildrunner_config.global_config.platform_builders,
cache_builders=self.buildrunner_config.global_config.docker_build_cache.builders,
cache_from=self.buildrunner_config.global_config.docker_build_cache.from_config,
cache_to=self.buildrunner_config.global_config.docker_build_cache.to_config,
) as multi_platform:
self.get_source_archive_path()
# run each step
for (
step_name,
step_config,
) in buildrunner_config.run_config.steps.items():
) in self.buildrunner_config.run_config.steps.items():
# Reset the cache_from and cache_to for each step to the global values
multi_platform.set_cache_from(
buildrunner_config.global_config.docker_build_cache.from_config
self.buildrunner_config.global_config.docker_build_cache.from_config
)
multi_platform.set_cache_to(
buildrunner_config.global_config.docker_build_cache.to_config
self.buildrunner_config.global_config.docker_build_cache.to_config
)

if not self.steps_to_run or step_name in self.steps_to_run:
Expand Down
6 changes: 3 additions & 3 deletions buildrunner/docker/daemon.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@

from buildrunner.docker import DOCKER_DEFAULT_DOCKERD_URL

DAEMON_IMAGE_NAME = "busybox:latest"


class DockerDaemonProxy:
"""
Expand Down Expand Up @@ -74,10 +76,8 @@ def start(self):
self._env["DOCKER_HOST"] = "unix:///dockerdaemon/docker.sock"

# create and start the Docker container
image_name = f"{self.docker_registry}/busybox:latest"
self.docker_client.pull(image_name)
self._daemon_container = self.docker_client.create_container(
image_name,
f"{self.docker_registry}/{DAEMON_IMAGE_NAME}",
command="/bin/sh",
volumes=_volumes,
host_config=self.docker_client.create_host_config(binds=_binds),
Expand Down
10 changes: 10 additions & 0 deletions tests/test_runner.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@
sys.path.insert(0, os.path.realpath(os.path.join(os.path.dirname(__file__), "..")))

import buildrunner.config.loader # noqa: E402
from buildrunner.docker.daemon import DAEMON_IMAGE_NAME # noqa: E402
from buildrunner import docker as buildrunner_docker # noqa: E402
from buildrunner import ( # noqa: E402
cli,
__version__,
Expand All @@ -30,6 +32,14 @@ def run_tests(argv, master_config_file=None, global_config_files=None):

try:
build_runner = cli.initialize_br(args)

# Pull Docker daemon proxy
image_name = f"{build_runner.buildrunner_config.global_config.docker_registry}/{DAEMON_IMAGE_NAME}"
docker_client = buildrunner_docker.new_client(
timeout=build_runner.docker_timeout
)
docker_client.pull(image_name)

build_runner.run()
if build_runner.exit_code:
return build_runner.exit_code
Expand Down

0 comments on commit 9f5462e

Please sign in to comment.