Coder Social home page Coder Social logo

zchip / wait-for Goto Github PK

View Code? Open in Web Editor NEW

This project forked from eficode/wait-for

0.0 0.0 0.0 484 KB

./wait-for is a script to wait for another service to become available.

Home Page: https://raw.githubusercontent.com/eficode/wait-for/master/wait-for

License: MIT License

Shell 95.53% Dockerfile 4.47%

wait-for's Introduction


wait-for

Wait for another service to become available
GitHub release (latest by date) Script file size
Example usage · Submit a PR

./wait-for is a script designed to synchronize services like docker containers. It is sh and alpine compatible. It was inspired by vishnubob/wait-for-it, but the core has been rewritten at Eficode by dsuni and mrako.

When using this tool, you only need to pick the wait-for file as part of your project.

Usage

Download the wait-for file, either the latest from master or for a specific version check out the Releases-page.

With the file locally on your file system, you can directly invoke it.

./wait-for host:port|url [-t timeout] [-- command args]
  -q | --quiet                        Do not output any status messages
  -t TIMEOUT | --timeout=timeout      Timeout in seconds, zero for no timeout
  -- COMMAND ARGS                     Execute command with args after the test finishes

Alternatively, you could download the script and pipe it into sh:

$ wget -qO- https://raw.githubusercontent.com/eficode/wait-for/v2.1.3/wait-for | sh -s -- google.com:80 -- echo success

Note: When using the latter option, make sure to pin the version by commit hash. Future releases could introduce non-backwards compatible changes and leaves you vulnerable to malicious users modifying this script in the future (as has e.g. happened with Codecov).

Examples

To check if www.eficode.com is available:

$ ./wait-for www.eficode.com:80 -- echo "Eficode site is up"
Eficode site is up

To wait for database container to become available:

version: '3'

services:
  db:
    image: postgres:9.4

  backend:
    build: backend
    command: sh -c './wait-for db:5432 -- npm start'
    depends_on:
      - db

To check if https://www.eficode.com is available over HTTPS:

$ ./wait-for https://www.eficode.com -- echo "Eficode is accessible over HTTPS"
Eficode is accessible over HTTPS

To wait for your API service to become available:

version: '3'

services:
  api:
    image: nginx

  tests:
    build: .
    command: sh -c './wait-for http://api -- echo "The api is up! Let's use it"'
    depends_on:
      - api

Testing

Ironically testing is done using bats, which on the other hand is depending on bash.

docker build -t wait-for .
docker run --rm -t wait-for

Contributing

When creating PRs, please style your commit messages according to conventional commit, you can use a tool like commitizen to guide you. We will automatically infer the changelog from your commits. Alternatively, we can squash all commits when merging and update the commit message.

This project strongly prefers maintaining backwards compatibility, therefore some obvious "fixes" might not be accepted.

Also, please include or update the test cases whenever possible by extending wait-for.bats.

Note

Make sure netcat is installed in your Dockerfile before running the command if you test over plain TCP.

RUN apt-get -q update && apt-get -qy install netcat

https://stackoverflow.com/questions/44663180/docker-why-does-wait-for-always-time-out

If you are connecting over HTTP, then you will need to have wget available.

wait-for's People

Contributors

addono avatar and avatar chanjarster avatar crhg avatar danmichaelo avatar dependabot[bot] avatar jeremycraigmartinez avatar kharianne avatar mrako avatar sd-yip avatar semantic-release-bot avatar sztheory avatar tljm avatar

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.