Code Monkey home page Code Monkey logo

is_ready's Introduction

is_ready

is_ready is a self-contained program designed to wait until multiple addresses become accessible. Its purpose is to coordinate the startup of interconnected services, such as Docker containers that rely on one another. This tool does not rely on any external dependencies and can be executed as a standalone binary.

Table of Contents

Why

There are alternative solutions like wait-for-it and wait-for. The key differentiating factor of is_ready compared to alternative solutions is its ability to wait for the availability of multiple addresses, not only one. Finally, unlike other options, is_ready stands out as a self-contained binary, eliminating the need for any external dependencies.

Examples

$ is_ready --help

Usage: is_ready [OPTIONS] --addr <ADDRESS> -- <COMMAND>...

Arguments:
  <COMMAND>...

Options:
  -t, --timeout <TIMEOUT>  [default: 30]
  -a, --addr <ADDRESS>
  -q, --quiet              Suppress output
  -h, --help               Print help
  -V, --version            Print version


$ is_ready \
    --timeout 10 \
    --addr github.com:80 \
    --addr google.com:80 \
    -- echo "The addresses are available"

Connected to google.com:80 successfully
Connected to github.com:80 successfully
The addresses are available

Installation & Usage

is_ready is optimized for running in a Docker container, and it is ideal to wait for the availability of other services such as databases, caches, or other services.

Use inside Docker

Example using the Docker Image:

# Set the version you want to download
ARG IS_READY_VERSION=1.0.2
FROM ghcr.io/stavrospanakakis/is_ready:$IS_READY_VERSION AS is_ready

FROM alpine:3.19

RUN apk add --no-cache curl

# Download the binary
COPY --from=is_ready /is_ready /usr/local/bin/is_ready

...
...

Example using curl:

FROM alpine:3.19

RUN apk add --no-cache curl

# Set the version you want to download
ENV IS_READY_VERSION=v1.0.2

# Download the binary
RUN curl -L https://github.com/Stavrospanakakis/is_ready/releases/download/${IS_READY_VERSION}/is_ready_${IS_READY_VERSION}_x86_64-unknown-linux-musl.tar.gz | tar xzf - -C /usr/local/bin

...
...

Example Docker Compose:

version: '3'
services:
  mysql:
    image: mysql:8.0
  
  app:
    build: .
    command: is_ready --timeout 10 --addr mysql:3306 -- echo "MySQL is ready"

Use as a Docker container

is_ready can be also used as a Docker container using the ghcr.io/stavrospanakakis/is_ready image from GitHub Container Registry.

$ VERSION=1.0.2
$ docker run --rm ghcr.io/stavrospanakakis/is_ready:$VERSION --version
is_ready 1.0.2

License

MIT

is_ready's People

Contributors

dependabot[bot] avatar marcelom97 avatar stavrospanakakis avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar

is_ready's Issues

Test case - Quiet flag

Description

The following feature exists:

  • Use the --quiet flag in case the user might not need to output any status messages

This could be a good testing case that will check:

  • Use the --quiet flag
  • Check that no output message is printed

Panic when command does not exist

To Reproduce
Steps to reproduce the behavior:

  1. Run is_ready with a command that does not exist. For example:
is_ready --addr google.com:80 -- command_that_does_not_exist
  1. It will panic:
Connected to google.com:80 successfully
thread 'main' panicked at is_ready/src/lib.rs:73:10:
Failed to run the command.: Os { code: 2, kind: NotFound, message: "No such file or directory" }
note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace

Expected behavior
In this case, it should handle the error and return something more user friendly such as Command not found

Test case - Timeout flag

Description

The following feature exists:

  • Use the --timeout flag to specify the seconds of the timeout

This could be a good testing case that will check:

  • Specify an invalid address (e.g. invalidaddr:1234)
  • Use the --timeout flag
  • Check that is_ready waits for this amount of seconds before failing

Test case - Successful run

Description

The following feature exists:

  • Wait for 2 addresses that are valid (e.g. google.com:80, github.com:80)
  • Run a command after they are ready

This could be a good testing case that will check:

  • It will wait for 2 valid addresses that are ready
  • The command that was defined ran successfully

Test case - Unsuccessful run

Description

The following feature exists:

  • Wait for addresses that are not valid (e.g. invalidaddress:2412)
  • Return error message since the address is not ready after the timeout

This could be a good testing case that will check:

  • It will wait for the invalid addresses and since it is not ready, it will show a failure message after the timeout ends

Quiet flag (`--quiet`)

Description

There might be cases that the user might not need to output any status messages.

The --quiet or -q flag can be used for this purpose.

Before

$ is_ready \
    --timeout 10 \
    --addr github.com:80 \
    --addr google.com:80 \
    -- echo "The addresses are available"

Connected to google.com:80 successfully
Connected to github.com:80 successfully
The addresses are available

After

$ is_ready \
    --quiet \
    --timeout 10 \
    --addr github.com:80 \
    --addr google.com:80 \
    -- echo "The addresses are available"

The addresses are available

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.