Coder Social home page Coder Social logo

pg-wait's Introduction

pg-wait

Install:

go install github.com/partyzanex/pg-wait/cmd/[email protected]

Usage:

$ pg-wait -h
Usage of ~/go/bin/pg-wait:
  -d, --dsn string         postgres URL
  -t, --timeout duration   timeout (default 10s)
  -v, --verbose            verbose errors
pflag: help requested

$ pg-wait --dsn="postgresql://postgres:postgres@localhost:5432/mydatabase?sslmode=disable" -t 5s -v 
2021/04/11 00:10:18 try tcp connection: dial tcp [::1]:5432: connectex: No connection could be made because the target machine actively refused it.
2021/04/11 00:10:21 try tcp connection: dial tcp [::1]:5432: connectex: No connection could be made because the target machine actively refused it.
2021/04/11 00:10:26 exit by timeout
exit status 1

$ pg-wait --dsn="postgresql://postgres:postgres@localhost:5432/mydatabase?sslmode=disable" -t 5s -v
2021/04/11 00:13:52 success!

Usage via docker-compose:

Dockerfile:

FROM golang:1.17-alpine as builder

WORKDIR /go/src/pg-wait

ENV GOPATH /go
ENV PG_WAIT_VERSION v0.1.0

RUN go mod init fake && go install github.com/partyzanex/pg-wait/cmd/pg-wait@${PG_WAIT_VERSION}


FROM alpine:3.14

COPY --from=builder /go/bin/pg-wait /usr/local/bin

docker-compose.yml:

version: '3.5'

services:
  postgres:
    image: postgres:12-alpine
    environment:
      POSTGRES_USER: "test"
      POSTGRES_PASSWORD: "test"
      POSTGRES_DB: "test"
    networks:
      - example

  pg-wait:
    build:
      dockerfile: Dockerfile
      context: .
    command: sh -c "pg-wait --dsn=\"postgresql://test:test@postgres:5432/test?sslmode=disable\" --verbose --timeout=10s"
    depends_on:
      - postgres
    networks:
      - example

networks:
  example:
    name: example_net

Run:

$ docker-compose up --build
...
Creating example_postgres_1 ... done
Creating example_pg-wait_1  ... done
Attaching to example_postgres_1, example_pg-wait_1
pg-wait_1   | 2021/04/10 21:48:16 try tcp connection: dial tcp 172.22.0.2:5432: connect: connection refused
postgres_1  | The files belonging to this database system will be owned by user "postgres".
...
postgres_1  | 2021-04-10 21:48:17.772 UTC [1] LOG:  database system is ready to accept connections
pg-wait_1   | 2021/04/10 21:48:18 success!
example_pg-wait_1 exited with code 0

pg-wait's People

Contributors

partyzanex avatar

Watchers

James Cloos avatar  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.