-
Notifications
You must be signed in to change notification settings - Fork 41
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Use gateway instead of 0.0.0.0 to allow docker in docker #8
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hey, sorry it took so long to get back to this -- I lost track of the github email in my inbox :(
@@ -6,6 +6,16 @@ | |||
from docker.errors import ImageNotFound | |||
import docker as docker_module | |||
|
|||
|
|||
def escape_env_var(varname): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can you either add a test with realistic examples (preferred) or a docstring explaining why this is necessary?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I will do both.
tox_docker.py
Outdated
@@ -54,6 +64,9 @@ def tox_runtest_pre(venv): | |||
conf._docker_containers.append(container) | |||
|
|||
container.reload() | |||
gateway_ip = "0.0.0.0" | |||
if conf.docker_use_gateway and container.attrs["NetworkSettings"]["Gateway"]: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is the gateway sometimes not available? I'd love for this to be the default way to do things, rather than an option, in order to keep the interface smaller, but if it's sometimes not possible, that's a bummer.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I will check if it is possible that the gateway is unavailable.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It seems to always be set. So I will remove the parameter docker_use_gateway
.
c476f66
to
d9b7022
Compare
@dcrosta It is ok, Thank for your answer :) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sorry this slipped off my radar again! I'll try to be more responsive.
|
||
class ToxDockerRegistryTest(unittest.TestCase): | ||
def test_it_sets_specific_env_vars(self): | ||
self.assertEqual("env-var-value", os.environ["ENV_VAR"]) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We don't need this test case replicated in the other test env.
def test_it_sets_automatic_env_vars(self): | ||
# the nginx image we use exposes port 80 | ||
self.assertIn("DOCKER_IO_LIBRARY_NGINX_HOST", os.environ) | ||
self.assertIn("DOCKER_IO_LIBRARY_NGINX_80_TCP", os.environ) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It's not clear to me that this should be what you have here vs. eg NGINX_80_TCP
. What's the use case for having multiple containers with the same name running (if they come from different regstries)?
@tox-dev/maintainers any opinions?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sorry for the delay, I miss the notification for your replies.
The aim is to replace all invalid characters in the environment variable name.
Without the fix, an image from docker.io/library/nginx:1.13-alpine
(or another private registry) will create an env var with the name DOCKER.IO_LIBRARY_NGINX_80_TCP
which is not valid for a environment var.
name.upper(), | ||
containerport.replace("/", "_").upper(), | ||
) | ||
envvar = escape_env_var("{}_HOST".format( |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Could you add documentation on this to README.md?
ec255c3
to
5810ea9
Compare
Since the commit for UDP check (63b80bf), my test fails and currently, I don't know why it works with the |
I want to use tox-docker inside docker (docker in docker). But using
0.0.0.0
orlocalhost
doestn't work in this case.That why I made this PR to add an option
docker_use_gateway
which use docker gateway ip to test connection with the container. I also add a new environment varXXX_HOST
to save the gateway ip.Finally, I replace
name.upper()
by a call toescape_env_var()
because when you use a private registry, the name with the URL is not correctly escaped. Example:my.registry.com/myimage
becameMY.REGISTRY.COM/MYIMAGE
instead ofMY_REGISTRY_COM_MYIMAGE
.To test the failure case:
docker run --rm -ti -v $(pwd):/src -w /src -v /var/run/docker.sock:/var/run/docker.sock -v /etc/passwd:/etc/passwd -v /etc/group:/etc/group docker sh -c 'apk add python py-pip ; pip install . ; tox'
In
tox.ini
, if you setdocker_use_gateway
toTrue
, the previous command will success.