Skip to content

Commit

Permalink
Update README.
Browse files Browse the repository at this point in the history
  • Loading branch information
patrickdappollonio committed Jan 21, 2022
1 parent eef2bf1 commit 95ffcea
Show file tree
Hide file tree
Showing 3 changed files with 68 additions and 2 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
dist/
2 changes: 0 additions & 2 deletions .goreleaser.yml
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,6 @@ dockers:
- image_templates:
- "ghcr.io/patrickdappollonio/wait-for:{{ .Tag }}"
- "ghcr.io/patrickdappollonio/wait-for:latest"
extra_files:
- 'html/'
changelog:
sort: asc
filters:
Expand Down
67 changes: 67 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
# `wait-for`

A tiny Go application with zero dependencies. Given a number of TCP `host:port` pairs, the app will wait until either all are available or a timeout is reached.

Kudos to @vishnubob for the [original implementation in Bash](https://github.com/vishnubob/wait-for-it).

### Usage

The easiest way is to provide a list of `host:port` pairs and configure a timeout:

```bash
wait-for \
--host "google.com:443" \
--host "mysql.example.com:3306" \
--timeout 10s
```

This will ping both `google.com` on port `443` and `mysql.example.com` on port `3306`. If they both start accepting connections within 10 seconds, the app will exit with a `0` exit code. If either one does not start accepting connections within 10 seconds, the app will exit with a `1` exit code, which will allow you to catch the error in CI/CD environments.

All the parameters accepted by the application are shown in the help section, as shown below.

```
wait-for allows you to wait for a TCP resource to respond to requests.
It does this by performing a TCP connection to the specified host and port. If there's
no resource behind it and the connection cannot be established, the request is retried
until either the timeout is reached or the resource becomes available.
By default, the standard timeout is 10 seconds.
For documentation, visit: https://github.com/patrickdappollonio/wait-for.
Usage:
wait-for [flags]
Flags:
-e, --every duration time to wait between each request attempt against the host (default 1s)
-h, --help help for wait-for
-s, --host strings hosts to connect to in the format "host:port"
-t, --timeout duration maximum time to wait for the endpoints to respond before giving up (default 10s)
-v, --verbose enable verbose output -- will print every time a request is made
--version version for wait-for
```

### Usage with Kubernetes

Simply use this tool as an `initContainer` before your application runs, and validate whether your databases or any TCP-accessible resource (such as websites, too) are up and running, or fail early with proper knowledge of the situation.

In the example above, before we run the `nginx` container, we use `initContainers` to ensure that `google.com` responds on port `443`, `mysql.example.com` responds on port `3306` -- since it's the default port for MySQL -- and we also enable the verbose mode, which allows you to see the output of each probe against these hosts.

```yaml
apiVersion: v1
kind: Pod
metadata:
name: init-container-demo
spec:
initContainers:
- name: wait-for
image: ghcr.io/patrickdappollonio/wait-for:latest
args:
- --host="google.com:443"
- --host="mysql.example.com:3306"
- --verbose
containers:
- name: nginx-container
image: nginx
```

0 comments on commit 95ffcea

Please sign in to comment.