Awesome
<!-- PROJECT LOGO --> <br /> <p align="center"> <!-- <a href="https://github.com/roerohan/wait-for-it"> <img src="https://project-logo.png" alt="Logo" width="80"> </a> --> <h1 align="center">wait-for-it</h1> <p align="center"> A Golang package to wait on the availability of a TCP host and port. <br /> <a href="https://github.com/roerohan/wait-for-it"><strong>Explore the docs »</strong></a> <br /> <br /> <a href="https://github.com/roerohan/wait-for-it">View Demo</a> · <a href="https://github.com/roerohan/wait-for-it/issues">Report Bug</a> · <a href="https://github.com/roerohan/wait-for-it/issues">Request Feature</a> </p> </p> <!-- TABLE OF CONTENTS -->Table of Contents
<!-- ABOUT THE PROJECT -->About The Project
<img src="./assets/wait-for-it.png" alt="wait-for-it" width="800">This package is adapted from vishnubob/wait-for-it, a popular project used to wait for TCP connections until a service is up. This is commonly used in docker-compose
files to make one service wait for another, for example, to make a web server wait for a mysql
database.
Since vishnubob/wait-for-it is a bash script, it does not work directly with minimal containers like scratch, which are commonly used to run binaries.
With the help of this package, you can generate a binary, which can run inside minimal Docker containers and wait for a TCP connection such as a mysql
database. You can find an example here: csivitu/bl0b.
Built With
<!-- GETTING STARTED -->Getting Started
A amd64
(64-bit) executables for linux
, darwin
, and windows
are available in the GitHub releases.
If you want to build a binary for a different Operating System / Architecture, you can follow the procedure below.
Prerequisites
The only prerequisite is golang
which you can get here.
- go
Installation
- Get the package using
go install
.
go install github.com/roerohan/wait-for-it
Alternatively, you can follow these steps:
- Clone the repository.
git clone https://github.com/roerohan/wait-for-it
- Build a go binary from source.
cd wait-for-it
go build -o ./bin/wait-for-it
- Use the binary inside the bin folder.
./bin/wait-for-it google.com:80 -- echo "It works\!"
<!-- USAGE EXAMPLES -->
Usage
The usage is similar to vishnubob/wait-for-it.
Use wait-for-it -h
to display the following list.
Usage of wait-for-it:
-q Quiet, don't output any status messages
-s Only execute subcommand if the test succeeds
-t int
Timeout in seconds, zero for no timeout (default 15)
-w host:port
Services to be waiting for, in the form host:port
You can run any executable after passing --
, like in the examples below.
Examples:
- Waiting for multiple services in parallel.
wait-for-it -w google.com:80 -w localhost:27017 -t 30 -- echo "Waiting for 30 seconds for google.com:80 and localhost:27017"
- Strict mode will not execute the subcommand only if TCP connection was successful.
$ wait-for-it -w abcd:80 -s -t 5 -- echo "Done\!"
wait-for-it: waiting 5 seconds for abcd:80
wait-for-it: timeout occured after waiting for 5 seconds
wait-for-it: strict mode, refusing to execute subprocess
<!-- ROADMAP -->
Roadmap
See the open issues for a list of proposed features (and known issues).
<!-- CONTRIBUTING -->Contributing
Contributions are what make the open source community such an amazing place to be learn, inspire, and create. Any contributions you make are greatly appreciated.
- Fork the Project
- Create your Feature Branch (
git checkout -b feature/AmazingFeature
) - Commit your Changes (
git commit -m 'feat: Add some AmazingFeature'
) - Push to the Branch (
git push origin feature/AmazingFeature
) - Open a Pull Request
You are requested to follow the contribution guidelines specified in CONTRIBUTING.md while contributing to the project :smile:.
<!-- LICENSE -->License
Distributed under the MIT License. See LICENSE
for more information.