Coder Social home page Coder Social logo

safouene1 / wait-for Goto Github PK

View Code? Open in Web Editor NEW

This project forked from dnnrly/wait-for

1.0 1.0 0.0 98 KB

Super simple tool to help with orchestration of commands on the CLI by waiting on networking resources.

License: Apache License 2.0

Shell 0.06% Go 77.01% Makefile 4.28% Dockerfile 0.55% Gherkin 18.09%

wait-for's Introduction

wait-for

This is a CLI tool that waits for an event before continuing. Simples. But it does it cross platform and as a single dependency that can be downloaded into your container or environment.

Typically, you would use this to wait on another resource (such as an HTTP resource) to become available before continuing - or timeout and exit with an error.

At the moment, you can wait for a few different kinds of thing. They are:

  • HTTP or HTTPS success response or any expected response following regular expressions
  • TCP or GRPC connection
  • DNS IP resolve address change

GitHub release (latest SemVer) GitHub Workflow Status codecov report card Go Reference

GitHub watchers GitHub stars Twitter URL

Installing wait-for

Using the go command:

go install github.com/dnnrly/wait-for/cmd/wait-for@latest

If you don't have Go installed (in a Docker container, for example) then you can take advantage of the pre-built versions. Check out the releases and check out the links for direct downloads. You can download and unpack a release like so:

wget https://github.com/dnnrly/wait-for/releases/download/v0.0.5/wait-for_0.0.5_linux_386.tar.gz
gunzip wait-for_0.0.5_linux_386.tar.gz
tar -xfv wait-for_0.0.5_linux_386.tar

In your Dockerfile, you can do this:

ADD https://github.com/dnnrly/wait-for/releases/download/v0.0.1/wait-for_0.0.5_linux_386.tar.gz wait-for.tar.gz
RUN gunzip wait-for.tar.gz && tar -xf wait-for.tar

Feel free to choose from any of the other releases though.

Using wait-for

Waiting for arbitrary HTTP services

$ wait-for http://your-service-here:8080/health https://another-service/

Waiting for HTTP services with expected response status

$ wait-for -status=[0-2]{3} http://your-service-here:8080/health 

Waiting for gRPC services

$ wait-for grpc-server:8092 other-grpc-server:9091

Waiting for DNS changes

$ wait-for dns:google.com

This will wait for the list of IP addresses bound to that DNS name to be updated, regardless of order. You can use this to wait for a DNS update such as failover or other similar operations.

Preconfiguring services to connect to

$ wait-for preconfigured-service

By default, wait-for will look for a file in the current directory called .wait-for.yml. In this, you can define the names of services that you would like to wait on.

wait-for:
  preconfigured-service:
    type: http
    target: http://the-service:8080/health?reload=true
    interval: 5s
    timeout: 60s
    http-client-timeout: 3s
  another-service:
    type: http
    target: https://another-one
  grpcService:
    type: grpc
    target: localhost:9092
  snmp-service:
    type: tcp
    target: snmp-trap-dns:514
  dns-thing:
    type: dns
    target: your.r53-entry.com

Using wait-for in Docker Compose

You can use wait-for to do some of the orchestration for you in your compose file. A good example would be something like this:

version: '3'
services:
  web:
    build: .
    ports:
      - "8080"
    command: sh -c 'wait-for tcp:db:5432 && ./your-api
    depends_on:
      - db
  db:
    image: "postgres:13-alpine"
    command: "-c log_statement=all"
    environment:
      POSTGRES_DB: weallvote-api
      POSTGRES_USER: ${POSTGRES_USER:-postgres}
      POSTGRES_PASSWORD: ${POSTGRES_PASSWORD:-postgres}

Developing wait-for

Building the tool

To build the tool so that you can run it locally, you can use the following command.

$ make build

Unit tests

You can run the tests as the build system would, using the following command:

$ make test

You can also run the Go tests in the 'usual' way with the following command:

$ go test ./...

Acceptance tests

There is a suite of GoDog tests that check that the built tooling works as expected.

$ make acceptance-test

Depending on how your system is set up, it might not be possible for you to open up the necessary ports to run the acceptance tests. To get around this you can run those same tests in Docker

$ make acceptance-test-docker

wait-for's People

Contributors

dnnrly avatar safouene1 avatar kkupreeva avatar ahdekkers avatar

Stargazers

Amin Boulouma avatar

Watchers

 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.