Skip to content

Commit

Permalink
Fix config container name for Docker runner (#16243)
Browse files Browse the repository at this point in the history
fix docker container name usage

Signed-off-by: Uilian Ries <uilianries@gmail.com>
  • Loading branch information
uilianries authored May 13, 2024
1 parent 3232cf6 commit 4192b14
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 8 deletions.
4 changes: 2 additions & 2 deletions conan/internal/runner/docker.py
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ def __init__(self, conan_api, command, host_profile, build_profile, args, raw_ar
profile_list = set(self.args.profile_build + self.args.profile_host)
else:
profile_list = self.args.profile_host or self.args.profile_build

# Update the profile paths
for i, raw_arg in enumerate(raw_args):
for i, raw_profile in enumerate(profile_list):
Expand All @@ -111,7 +111,7 @@ def __init__(self, conan_api, command, host_profile, build_profile, args, raw_ar
if not (self.dockerfile or self.image):
raise ConanException("'dockerfile' or docker image name is needed")
self.image = self.image or 'conan-runner-default'
self.name = self.configfile.image or f'conan-runner-{host_profile.runner.get("suffix", "docker")}'
self.name = self.configfile.run.name or f'conan-runner-{host_profile.runner.get("suffix", "docker")}'
self.remove = str(host_profile.runner.get('remove', 'false')).lower() == 'true'
self.cache = str(host_profile.runner.get('cache', 'clean'))
self.container = None
Expand Down
16 changes: 10 additions & 6 deletions conans/test/integration/command/runner_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -141,7 +141,8 @@ def test_create_docker_runner_dockerfile_file_path():
client.save({"host": profile_host, "build": profile_build})
client.run("new cmake_lib -d name=pkg -d version=0.2")
client.run("create . -pr:h host -pr:b build")
print(client.out)

assert "Container conan-runner-docker running" in client.out
assert "Restore: pkg/0.2" in client.out
assert "Restore: pkg/0.2:8631cf963dbbb4d7a378a64a6fd1dc57558bc2fe" in client.out
assert "Restore: pkg/0.2:8631cf963dbbb4d7a378a64a6fd1dc57558bc2fe metadata" in client.out
Expand Down Expand Up @@ -249,7 +250,7 @@ def test_create_docker_runner_profile_abs_path():
cache=copy
remove=True
""")

client.save({"host": profile_host, "build": profile_build})
client.run("new cmake_lib -d name=pkg -d version=0.2")
client.run(f"create . -pr:h '{os.path.join(client.current_folder, 'host')}' -pr:b '{os.path.join(client.current_folder, 'build')}'")
Expand All @@ -272,6 +273,8 @@ def test_create_docker_runner_profile_abs_path_from_configfile():
build:
dockerfile: {dockerfile_path("Dockerfile_test")}
build_context: {conan_base_path()}
run:
name: my-custom-conan-runner-container
""")
client.save({"configfile.yaml": configfile})

Expand Down Expand Up @@ -301,11 +304,12 @@ def test_create_docker_runner_profile_abs_path_from_configfile():
cache=copy
remove=True
""")

client.save({"host": profile_host, "build": profile_build})
client.run("new cmake_lib -d name=pkg -d version=0.2")
client.run(f"create . -pr:h '{os.path.join(client.current_folder, 'host')}' -pr:b '{os.path.join(client.current_folder, 'build')}'")

assert "Container my-custom-conan-runner-container running" in client.out
assert "Restore: pkg/0.2" in client.out
assert "Restore: pkg/0.2:8631cf963dbbb4d7a378a64a6fd1dc57558bc2fe" in client.out
assert "Restore: pkg/0.2:8631cf963dbbb4d7a378a64a6fd1dc57558bc2fe metadata" in client.out
Expand Down Expand Up @@ -357,11 +361,11 @@ def test_create_docker_runner_profile_abs_path_from_configfile_with_args():
cache=copy
remove=True
""")

client.save({"host": profile_host, "build": profile_build})
client.run("new cmake_lib -d name=pkg -d version=0.2")
client.run(f"create . -pr:h '{os.path.join(client.current_folder, 'host')}' -pr:b '{os.path.join(client.current_folder, 'build')}'")
print(client.out)

assert "test/integration/command/dockerfiles/Dockerfile_args" in client.out
assert "Restore: pkg/0.2" in client.out
assert "Restore: pkg/0.2:8631cf963dbbb4d7a378a64a6fd1dc57558bc2fe" in client.out
Expand Down Expand Up @@ -434,4 +438,4 @@ def test_create_docker_runner_default_build_profile_error():
client.save({"host_clean": profile_host})
client.run("new cmake_lib -d name=pkg -d version=0.2")
with pytest.raises(Exception, match="ERROR: The default build profile '/root/.conan2/profiles/default' doesn't exist.") as exception:
client.run("create . -pr:h host_clean")
client.run("create . -pr:h host_clean")

0 comments on commit 4192b14

Please sign in to comment.