wait-for-it icon indicating copy to clipboard operation
wait-for-it copied to clipboard

not working on alpine 3.10 with bash installed

Open JoshuaC215 opened this issue 6 years ago • 17 comments

we use wait-for-it.sh heavily in CI for docker integration testing in golang. Recently a job broke due to wait-for-it.sh error. I believe the issue may have to do with something changing in timeout from alpine3.9 (works) to alpine 3.10 (not working). In both cases we were installing bash with apk.

Repro (note in vi I am copying wait-for-it from current master)

$ docker run -it --rm golang:1.12-alpine
/go # vi wait-for-it.sh
/go # chmod +x wait-for-it.sh 
/go # apk update && apk add --no-cache bash
fetch http://dl-cdn.alpinelinux.org/alpine/v3.10/main/x86_64/APKINDEX.tar.gz
fetch http://dl-cdn.alpinelinux.org/alpine/v3.10/community/x86_64/APKINDEX.tar.gz
v3.10.1-11-g89d0862481 [http://dl-cdn.alpinelinux.org/alpine/v3.10/main]
v3.10.1-12-ga885fe876c [http://dl-cdn.alpinelinux.org/alpine/v3.10/community]
OK: 10327 distinct packages available
fetch http://dl-cdn.alpinelinux.org/alpine/v3.10/main/x86_64/APKINDEX.tar.gz
fetch http://dl-cdn.alpinelinux.org/alpine/v3.10/community/x86_64/APKINDEX.tar.gz
(1/5) Installing ncurses-terminfo-base (6.1_p20190518-r0)
(2/5) Installing ncurses-terminfo (6.1_p20190518-r0)
(3/5) Installing ncurses-libs (6.1_p20190518-r0)
(4/5) Installing readline (8.0.0-r0)
(5/5) Installing bash (5.0.0-r0)
Executing bash-5.0.0-r0.post-install
Executing busybox-1.30.1-r2.trigger
OK: 15 MiB in 20 packages
/go # ./wait-for-it.sh docker:5432
timeout: unrecognized option: t
BusyBox v1.30.1 (2019-06-12 17:51:55 UTC) multi-call binary.

Usage: timeout [-s SIG] SECS PROG ARGS

Runs PROG. Sends SIG to it if it is not gone in SECS seconds.
Default SIG: TERM.
wait-for-it.sh: timeout occurred after waiting 15 seconds for docker:5432

Workaround: I was able to work around this issue by installing coreutils as well which updates timeout (continuing from example above)

/go # apk update && apk add --no-cache coreutils
fetch http://dl-cdn.alpinelinux.org/alpine/v3.10/main/x86_64/APKINDEX.tar.gz
fetch http://dl-cdn.alpinelinux.org/alpine/v3.10/community/x86_64/APKINDEX.tar.gz
v3.10.1-11-g89d0862481 [http://dl-cdn.alpinelinux.org/alpine/v3.10/main]
v3.10.1-12-ga885fe876c [http://dl-cdn.alpinelinux.org/alpine/v3.10/community]
OK: 10327 distinct packages available
fetch http://dl-cdn.alpinelinux.org/alpine/v3.10/main/x86_64/APKINDEX.tar.gz
fetch http://dl-cdn.alpinelinux.org/alpine/v3.10/community/x86_64/APKINDEX.tar.gz
(1/3) Installing libacl (2.2.52-r6)
(2/3) Installing libattr (2.4.48-r0)
(3/3) Installing coreutils (8.31-r0)
Executing busybox-1.30.1-r2.trigger
OK: 16 MiB in 23 packages
/go # ./wait-for-it.sh -t 15 docker:5432
wait-for-it2.sh: waiting 15 seconds for docker:5432
wait-for-it2.sh: timeout occurred after waiting 15 seconds for docker:5432

JoshuaC215 avatar Jul 21 '19 23:07 JoshuaC215

I can confirm the issue, we are getting the same problem.

arthens avatar Jul 24 '19 16:07 arthens

https://github.com/vishnubob/wait-for-it/pull/68

fr05t1k avatar Aug 09 '19 10:08 fr05t1k

This breaking change in BusyBox ("timeout: fix arguments to match coreutils") seems to be the reason, I just ran into the same issue after our build image was updated to alpine:3.10

tillkuhn avatar Sep 18 '19 09:09 tillkuhn

Thanks for the workaround @JoshKCarroll Works well by installing coreutils :wink:

TZK- avatar Sep 20 '19 08:09 TZK-

  • I needs wait-for-it sh script changing
  • maybe it is bad if statement judge busybox

how to resolve ?

  • change if statement
  • ah maybe it is bad method...
  • if help include some text then enable -t option
/ # timeout --help 2>&1 | grep '\-t SECS'
Usage: timeout [-t SECS] [-s SIG] PROG ARGS

or Specify ENV and run script

WAITFORIT_BUSYTIMEFLAG="-t" wait-for-it.sh

and use it in wait-for-it.sh script without if else match in busybox.

YumaInaura avatar Oct 14 '19 01:10 YumaInaura

  • A Trouble log I found
  • probably same trouble as other people

e.g A docker image xueshanf/awscli

  • WAITFORIT_TIMEOUT_PATH has /bin/busybox
  • But timeout command does not have -t SEC option
  • Is this a trouble of only xueshanf/awscli image?
$ docker run -it --entrypoint= xueshanf/awscli bash
bash-5.0# WAITFORIT_TIMEOUT_PATH=$(type -p timeout)
bash-5.0# WAITFORIT_TIMEOUT_PATH=$(realpath $WAITFORIT_TIMEOUT_PATH 2>/dev/null || readlink -f $WAITFORIT_TIMEOUT_PATH)
bash-5.0# echo $WAITFORIT_TIMEOUT_PATH
/bin/busybox
bash-5.0# timeout
BusyBox v1.30.1 (2019-06-12 17:51:55 UTC) multi-call binary.

Usage: timeout [-s SIG] SECS PROG ARGS

Runs PROG. Sends SIG to it if it is not gone in SECS seconds.
Default SIG: TERM.
bash-5.0#

trouble

  • it happens trouble in if statement in script
# check to see if timeout is from busybox?
WAITFORIT_TIMEOUT_PATH=$(type -p timeout)
WAITFORIT_TIMEOUT_PATH=$(realpath $WAITFORIT_TIMEOUT_PATH 2>/dev/null || readlink -f $WAITFORIT_TIMEOUT_PATH)
if [[ $WAITFORIT_TIMEOUT_PATH =~ "busybox" ]]; then
        WAITFORIT_ISBUSY=1
        WAITFORIT_BUSYTIMEFLAG="-t"

else
        WAITFORIT_ISBUSY=0
        WAITFORIT_BUSYTIMEFLAG=""
fi

YumaInaura avatar Oct 14 '19 01:10 YumaInaura

directly change wait-for-it.sh

# check to see if timeout is from busybox?
WAITFORIT_TIMEOUT_PATH=$(type -p timeout)
WAITFORIT_TIMEOUT_PATH=$(realpath $WAITFORIT_TIMEOUT_PATH 2>/dev/null || readlink -f $WAITFORIT_TIMEOUT_PATH)
if [[ $WAITFORIT_TIMEOUT_PATH =~ "busybox" ]]; then
        WAITFORIT_ISBUSY=1
        WAITFORIT_BUSYTIMEFLAG="-t"

else
        WAITFORIT_ISBUSY=0
        WAITFORIT_BUSYTIMEFLAG=""
fi

+ if [[ ! -z "${WAITFORIT_NO_BUSYTIMEFLAG}" ]]; then
+         WAITFORIT_BUSYTIMEFLAG=""
+ fi

WAITFORIT_NO_BUSYTIMEFLAG=1 wait-for-it.sh

YumaInaura avatar Oct 14 '19 01:10 YumaInaura

Hopefully #81 solves this for you guys. The script still requires the use of bash on Alpine, but it should detect newer versions of BusyBox and deal with the updated flags appropriately.

iturgeon avatar Nov 04 '19 17:11 iturgeon

Ran into this issue and confirming @JoshKCarroll's workaround (installing coreutils) works. The maintainer @vishnubob seems to have abandoned this project...no responses to issues, last commit over a year ago, and there are 25 pull requests...2 of which try to fix this problem.

we're on our own!

riptusk331 avatar Nov 20 '19 15:11 riptusk331

I think you are right @riptusk331 . Is there a popular fork of this repo?

Stratus3D avatar Nov 20 '19 16:11 Stratus3D

Ah, I opened another PR that fixes the issue (but doesn't preserve backwards compat, so @iturgeon's is better) because I didn't read existing issues closely enough first.

robertp-indeed avatar Nov 21 '19 18:11 robertp-indeed

@douglas-gibbons , @vishnubob - Any chance one of the PRs that patch this issue can be merged? Has this repo been abandoned? If so, would someone else here be able to take over maintenance?

Thanks!

xtrasimplicity avatar Jan 30 '20 03:01 xtrasimplicity

Anyone have a dockerfile for alpine. Would love to try this using a docker run.

Cheers!

pascalandy avatar Dec 16 '20 05:12 pascalandy

@pascalandy used in the project https://github.com/gioamato/stateless-wordpress

The implementation is inside NGINX Dockerfile: https://github.com/gioamato/stateless-wordpress/blob/master/nginx/Dockerfile

gioamato avatar Dec 16 '20 11:12 gioamato

Thanks @gioamato. If I understood:

a Dockerfile for alpine

# inspiration
FROM alpine:3.12

COPY wait-for-it.sh /usr/local/bin/wait-for-it

RUN set -eux &&\
  apk --update add --no-cache bash coreutils &&\
  chmod +x /usr/local/bin/wait-for-it

pascalandy avatar Dec 16 '20 14:12 pascalandy

@pascalandy exactly. I suggest you to install dependencies first and then copy wait-for-it as the last thing. Doing so you will not invalidate docker build layers if you update wait-for-it script (Ref.: https://docs.docker.com/develop/develop-images/dockerfile_best-practices)

gioamato avatar Dec 16 '20 15:12 gioamato

Got it about the layer :-p

pascalandy avatar Dec 16 '20 16:12 pascalandy