diff --git a/.circleci/config.yml b/.circleci/config.yml index 3776c694..19f0d010 100644 --- a/.circleci/config.yml +++ b/.circleci/config.yml @@ -70,7 +70,8 @@ jobs: key: yarn-packages-{{ checksum "yarn.lock" }} paths: - ~/.cache/yarn - - run: # wait until cosm scripts have fully started (this includes time for docker pull) + - run: + name: Wait for blockchain and REST server to be ready (started in background) command: timeout 60 bash -c "until curl -s http://localhost:1317/node_info > /dev/null; do sleep 1; done" - run: environment: diff --git a/scripts/cosm/start.sh b/scripts/cosm/start.sh index 3722d815..2c0b285f 100755 --- a/scripts/cosm/start.sh +++ b/scripts/cosm/start.sh @@ -15,10 +15,6 @@ echo "Using temporary dir $TMP_DIR" WASMD_LOGFILE="$TMP_DIR/wasmd.log" REST_SERVER_LOGFILE="$TMP_DIR/rest-server.log" -# pull the newest copy of the docker image -# this is important as the sleep timeout below will fail on first run (downloading entire docker stack usually > 10s) -docker pull "$REPOSITORY:$VERSION" - # This starts up wasmd docker volume rm -f wasmd_data docker run --rm \ @@ -35,12 +31,10 @@ docker run --rm \ echo "wasmd running and logging into $WASMD_LOGFILE" # Debug chain start -sleep 3 -cat "$WASMD_LOGFILE" +# sleep 3 && cat "$WASMD_LOGFILE" -sleep 10 - -if [ "$(docker inspect -f '{{.State.Running}}' "$CONTAINER_NAME")" != "true" ]; then +# Use a large timeout because of potentially long image download in `docker run` +if ! timeout 120 bash -c "until docker inspect -f '{{.State.Running}}' '$CONTAINER_NAME' &> /dev/null; do sleep 0.5; done"; then echo "Container named '$CONTAINER_NAME' not running. We cannot continue." \ "This can happen when 'docker run' needs too long to download and start." \ "It might be worth retrying this step once the image is in the local docker cache." @@ -57,6 +51,10 @@ docker exec "$CONTAINER_NAME" \ echo "rest server running on http://localhost:1317 and logging into $REST_SERVER_LOGFILE" +# Give REST server some time to come alive. No idea why this helps. Needed for CI. +if [ -n "${CI:-}" ]; then + sleep 0.5 +fi + # Debug rest server start -sleep 3 -cat "$REST_SERVER_LOGFILE" +# sleep 3 && cat "$REST_SERVER_LOGFILE"