Skip to content
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

Allow dockerize to wait for network dependencies before main command #23

Merged
merged 1 commit into from Jan 25, 2016

Conversation

Projects
None yet
4 participants
@mefellows
Copy link
Contributor

mefellows commented Jan 25, 2016

It is common when using tools like Docker Compose to depend on services in other linked containers, however oftentimes relying on links is not enough - whilst the container itself may have started, the service(s) within it may not yet be ready - resulting in shell script hacks to work around race conditions.

This PR gives dockerize the ability to wait for services on a specified protocol (tcp, tcp4, tcp6, http, and https) before starting the main application:

dockerize -wait tcp://db:5432 -wait http://web:80 -timeout 10s somecommand

Note the timeout is optional and defaults to 10s.

I've found this to be particularly useful when using Docker Compose as a test harness, where one of the containers needs to test another. Instead of netcating my way around the problem, I can just wrap the command using dockerize.

I also fixed a few minor grammatical/spelling mistakes.

Related links:

go func() {
defer wg.Done()
for {
_, err := http.Get(u.String())

This comment has been minimized.

@jwilder

jwilder Jan 25, 2016

Owner

Seems like this should check to make sure a 200 response is returned. What if a 404 or 500 is returned by the dependency?

You an also specify a timeout using a custom http.Client and/or Transport.

This comment has been minimized.

@mefellows

mefellows Jan 25, 2016

Author Contributor

Good point, I originally interpreted the err to mean non-20x. This is fixed.

This comment has been minimized.

@mefellows

mefellows Jan 25, 2016

Author Contributor

RE: timeout. I did consider this, but felt the added complexity wasn't going to give us much given we check the timeout of the entire set of dependencies anyway. Let me know if you would prefer it the other way.

@mefellows mefellows force-pushed the mefellows:wait-for-dependencies branch from afc2db9 to 0ab5bf8 Jan 25, 2016

@thaJeztah

This comment has been minimized.

Copy link

thaJeztah commented Jan 25, 2016

ping @jwilder looks like this PR has been updated; ptal 👍

jwilder added a commit that referenced this pull request Jan 25, 2016

Merge pull request #23 from mefellows/wait-for-dependencies
Allow dockerize to wait for network dependencies before main command

@jwilder jwilder merged commit a2e1043 into jwilder:master Jan 25, 2016

@mefellows mefellows deleted the mefellows:wait-for-dependencies branch Jan 25, 2016

@mefellows

This comment has been minimized.

Copy link
Contributor Author

mefellows commented Jan 25, 2016

Thanks! 🎉

@jwilder

This comment has been minimized.

Copy link
Owner

jwilder commented Jan 25, 2016

Thanks @mefellows! Nice feature idea.

@mefellows

This comment has been minimized.

Copy link
Contributor Author

mefellows commented Jan 25, 2016

No worries at all - do I need to do anything to get this 'released' or will you look after that in due course?

@jwilder

This comment has been minimized.

Copy link
Owner

jwilder commented Jan 25, 2016

@mefellows I just created a new v0.1.0 release.

@mefellows

This comment has been minimized.

Copy link
Contributor Author

mefellows commented Jan 25, 2016

Awesome, thanks!

@markriggins

This comment has been minimized.

Copy link

markriggins commented on 0ab5bf8 Mar 30, 2016

nice work! I'm using this now, so thankyou

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.