Skip to content

support for non-default docker host added#16477

Merged
AbrilRBS merged 2 commits into
conan-io:develop2from
davidsanfal:bug/16461
Jul 2, 2024
Merged

support for non-default docker host added#16477
AbrilRBS merged 2 commits into
conan-io:develop2from
davidsanfal:bug/16461

Conversation

@davidsanfal

@davidsanfal davidsanfal commented Jun 13, 2024

Copy link
Copy Markdown
Contributor

Changelog: Fix: Add support for non default docker hosts in conan runners
Docs: Omit

@davidsanfal davidsanfal requested review from AbrilRBS and jcar87 June 13, 2024 17:06
@davidsanfal davidsanfal linked an issue Jun 13, 2024 that may be closed by this pull request

@AbrilRBS AbrilRBS left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This works for me now :)

@AbrilRBS AbrilRBS added this to the 2.5.0 milestone Jun 14, 2024
Comment thread conan/internal/runner/docker.py Outdated
self.docker_client = docker.DockerClient(base_url=base_url, version='auto')
break
except:
continue

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If every try fails, we could have a pretty error for the user in that case

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In that case, we rise this exception:

raise ConanException("Docker Client failed to initialize."
                     "\n - Check if docker is installed and running"
                     "\n - Run 'pip install conan[runners]'")

@memsharded memsharded left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good to me if it works, just some potential readability minor issues.

Comment thread conan/internal/runner/docker.py Outdated
Comment on lines +71 to +77
docker_base_urls = [
os.environ.get('CONAN_RUNNER_DOCKER_HOST'),
os.environ.get('DOCKER_HOST'),
'unix:///var/run/docker.sock',
f'unix://{os.path.expanduser("~")}/.rd/docker.sock'
]
for base_url in docker_base_urls:

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sounds a bit hacky, some suggestions:

  • Add some comment explaining the why. Explain the different URLs a bit
  • Is it possible to unify the above docker.from_env() and this call in a single one? so trying to connect the docker client looks like less like a workaround hack?

@memsharded memsharded modified the milestones: 2.5.0, 2.6.0 Jul 1, 2024
Comment thread conan/internal/runner/docker.py Outdated
self.docker_api = self.docker_client.api
docker_base_urls = [
None, # Default docker configuration, let the python library detect the socket
os.environ.get('CONAN_RUNNER_DOCKER_HOST'), # Connect to socket defined in CONAN_RUNNER_DOCKER_HOST

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

But why CONAN_RUNNER_DOCKER_HOST? This is not something defined by Rancher or anyone else, I suggest removing and leaving DOCKER_HOST if that is a "standard" docker env-var.

Comment on lines +74 to +76
for base_url in docker_base_urls:
try:
self.docker_client = docker.DockerClient(base_url=base_url, version='auto')

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Some info message, maybe at least ConanOutput().verbose() of the things that are being tried would make sense.

@memsharded memsharded modified the milestones: 2.6.0, 2.5.0 Jul 2, 2024
@AbrilRBS

AbrilRBS commented Jul 2, 2024

Copy link
Copy Markdown
Member

Confirmed that I can now run ny own docker images from rancher without problems now :)

@AbrilRBS AbrilRBS merged commit 2db8976 into conan-io:develop2 Jul 2, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[bug] Docker runner issues with Docker Rancher

3 participants