-
-
Notifications
You must be signed in to change notification settings - Fork 68
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
feat: network option #534
base: master
Are you sure you want to change the base?
feat: network option #534
Conversation
Codecov Report
@@ Coverage Diff @@
## master #534 +/- ##
==========================================
- Coverage 85.97% 85.62% -0.36%
==========================================
Files 48 48
Lines 2267 2309 +42
==========================================
+ Hits 1949 1977 +28
- Misses 165 172 +7
- Partials 153 160 +7
Continue to review full report at Codecov.
|
Hi @mathnogueira and thank you for contribution, this looks great! I will properly review the change this weekend. So far I only noticed that the test you added is basically a smoke test, and I wonder can the test be improved to actually confirm that the containers can communicate one with the other over the shared network? I'm thinking about extending https://github.com/orlangure/gnomock-test-image to support this case. If you have time until then, feel free to explore this direction. If not, no problem, I'll think about something later😼 |
Sure, I'll improve the testing on this PR |
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.
Thank you again for your contribution, I think this is a really cool and useful feature!
I have two thoughts I'd like to discuss with you a bit further.
- As I wrote before, it seems that the networking configuration can and should be tested beyond "smoke tests". For that I released a new version of gnomock-test-image, which can be configured with a network-local URL i.e
http://container
(no domain - use exact container name). This address will be opened on every/request
call, returning the target status code. It should be used to confirm that the two containers sharing the same network can communicate using their internal names. If you need help writing such test, please let me know. - I think we need a way to clean up unused networks. I don't think this is a blocker for this PR, but it definitely have to be considered. What are your thoughts?
} | ||
|
||
if len(existingNetworks) > 0 { | ||
return existingNetworks[0].ID, nil |
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.
Since only the first ID is returned, I suggest to drop the slice, and just return whatever ID is found on line 376 instead of maintaining a list of existingNetwork
.
Thanks for patching the docker image. It will be very helpful to test this feature. I'll take a look at this this weekend. |
I am facing the same issue, I am using clickhouse from gnomock, but also I am using the dockertest to run kafka, but I am not able to run the test end to end because of the network issue, any idea how to resolve this @orlangure ? |
Hi @MotazBellah, thanks for reporting. It's been a while here since @mathnogueira last appeared in the comments. We still have 2 remaining points here to take care of: testing, and network cleanup (for networks created by gnomock). Would you like to complete the work? Also, will it help if you run all your services via gnomock, so they don't have to share a network with other libraries? We do have a kafka preset that runs in a single container without network configuration. |
@orlangure but also even if I use the kafka from gnomock, both (clickHouse and Kafka) will run on separate containers and the network issue would still there ? or am i missing something ? 🤔 |
@MotazBellah, maybe you can work around the network issue by passing mapped host address:port to the container that needs to access the other one. That way the container that issues requests will go out to the host by its IP address and access the mapped port on the host just like your other code would. Of course using a shared network in this case would be better, but if the work isn't complete, you can try this solution as well. |
Context
gnomock works great when you have to run a couple of independent containers to test your application, but as soon as you require communication between those containers, things get tricky. I've tried a couple of approaches but couldn't manage to make a container communicate with another.
Solution
This PR adds a new option
gnomock.WithNetwork("network name")
that allows a user to define which network the containers should run on. This allows communication between containers using the container name as its hostname.Example
How it works
If
options.Network
is provided, check if there is an existing network with that name, if yes, use the existing network. Otherwise, create a new one and use it.