Skip to content

Commit

Permalink
Merge pull request #26 from makerdao/add-wait-for-it
Browse files Browse the repository at this point in the history
Fix wait-for-it on alpine image
  • Loading branch information
rmulhol authored Jan 17, 2020
2 parents c8c4572 + b8e46ba commit 851c288
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 8 deletions.
2 changes: 2 additions & 0 deletions dockerfiles/header_sync/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -20,10 +20,12 @@ FROM golang:alpine
WORKDIR /app

# add certificates for node requests via https
# bash for wait-for-it.sh
RUN apk update \
&& apk upgrade \
&& apk add --no-cache \
ca-certificates \
bash \
&& update-ca-certificates 2>/dev/null || true

# setup environment
Expand Down
22 changes: 14 additions & 8 deletions dockerfiles/wait-for-it.sh
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
#!/usr/bin/env bash
# Use this script from docker-compose.yml to wait for postgres before calling startup_script.sh
# Use this script to test if a given TCP host/port are available

WAITFORIT_cmdname=${0##*/}

Expand Down Expand Up @@ -140,17 +140,23 @@ WAITFORIT_TIMEOUT=${WAITFORIT_TIMEOUT:-15}
WAITFORIT_STRICT=${WAITFORIT_STRICT:-0}
WAITFORIT_CHILD=${WAITFORIT_CHILD:-0}
WAITFORIT_QUIET=${WAITFORIT_QUIET:-0}

# check to see if timeout is from busybox?
WAITFORIT_ISBUSY=0
WAITFORIT_BUSYTIMEFLAG=""
WAITFORIT_TIMEOUT_PATH=$(type -p timeout)
WAITFORIT_TIMEOUT_PATH=$(realpath $WAITFORIT_TIMEOUT_PATH 2>/dev/null || readlink -f $WAITFORIT_TIMEOUT_PATH)

# check to see if we're using busybox?
if [[ $WAITFORIT_TIMEOUT_PATH =~ "busybox" ]]; then
WAITFORIT_ISBUSY=1
WAITFORIT_BUSYTIMEFLAG="-t"
WAITFORIT_ISBUSY=1
fi

else
WAITFORIT_ISBUSY=0
WAITFORIT_BUSYTIMEFLAG=""
# see if timeout.c args have been updated in busybox v1.30.0 or newer
# note: this requires the use of bash on Alpine
if [[ $WAITFORIT_ISBUSY && $(busybox | head -1) =~ ^.*v([[:digit:]]+)\.([[:digit:]]+)\..+$ ]]; then
if [[ ${BASH_REMATCH[1]} -le 1 && ${BASH_REMATCH[2]} -lt 30 ]]; then
# using pre 1.30.0 version with `-t SEC` arg
WAITFORIT_BUSYTIMEFLAG="-t"
fi
fi

if [[ $WAITFORIT_CHILD -gt 0 ]]; then
Expand Down

0 comments on commit 851c288

Please sign in to comment.