maxcnunes / waitforit

Wait until an address become available.
MIT License
172 stars 26 forks source link

Run additional args with exec #12

Closed balintant closed 7 years ago

balintant commented 7 years ago

Add possibility to run commands within waitforit.

$ waitforit -full-connection=tcp://google.com:80 -timeout=30 -debug printf "Hello,\nWorld\!\n"
2017/08/19 15:22:23 Waiting 30 seconds
2017/08/19 15:22:23 Dial address: google.com:80
2017/08/19 15:22:24 ping TCP: google.com:80
2017/08/19 15:22:24 Up: google.com:80
Hello,
World!
Usage:

  waitforit [options] [post-command]

The options are:

  -debug
        enable debug
  -file string
        path of json file to read configs from
  -full-connection string
        full connection
  -host string
        host to connect
  -port int
        port to connect (default 80)
  -timeout int
        time to wait until port become available (default 10)
  -v    show the current version
coveralls commented 7 years ago

Coverage Status

Coverage decreased (-7.7%) to 58.537% when pulling bc5e99471ca90597c827249b61cb20d02ee3da1c on balintant:post-commands into 5efe35917e033afadf95e46d18474ab49c291f61 on maxcnunes:master.

coveralls commented 7 years ago

Coverage Status

Coverage decreased (-7.7%) to 58.537% when pulling 64882e7b86ca611a9473cc7e81c86fb34b733eca on balintant:post-commands into 5efe35917e033afadf95e46d18474ab49c291f61 on maxcnunes:master.

maxcnunes commented 7 years ago

hi @balintant ,

First of all thanks for the PR!! But I'm confused if this feature is really worth. Seems you could achieve the same with:

waitforit -full-connection=http://google.com -timeout=20 -debug && echo "Google Works!"

If is possible to achieve the same with simple shell commands I think there is no really benefit to increase the codebase adding this feature.

balintant commented 7 years ago

hi @maxcnunes,

I think that must be true, but somehow it isn't. I wasted half my Saturday with that, and finally, I extended the code, so it works for me.

Other wait-for [1, 2] packages recommended by Docker also include the command args part. I think they also experienced the issue.
(Note, those packages are not good for me as running them on scratch is the main point here.)

I created an example that you can replicate the issue with: https://gist.github.com/balintant/5edac5302705b98dffe56c7fb1878729

maxcnunes commented 7 years ago

Humm. That probably would work by replacing:

    command: /waitforit -full-connection=tcp://db:3306 -debug && /app

With:

    command: sh -c "/waitforit -full-connection=tcp://db:3306 -debug && /app"

But because you are using a scratch image the sh isn't available. Since there is need to keep images the smallest possible then this feature makes sense. I will just try to change a bit your code to use the same approach used by the other tools by passing the additional args after -- command.

maxcnunes commented 7 years ago

Thanks @balintant!!

balintant commented 7 years ago

Lol, I didn't even think of && not works because scratch is running no sh. That's so natural already.

I will just try to change a bit your code to use the same approach used by the other tools by passing the additional args after -- command.

I wanted to do the same, but at last, I decided less code is more valuable here.

Thanks, @maxcnunes!