diff --git a/.circleci/config.yml b/.circleci/config.yml index 28e6a717..67d28966 100644 --- a/.circleci/config.yml +++ b/.circleci/config.yml @@ -6,6 +6,7 @@ workflows: - build - lint - faucet_docker + - test jobs: build: @@ -30,8 +31,53 @@ jobs: - ~/.cache/yarn - run: command: yarn build + test: + machine: + # We can't use a containerized environment since it requires remote docker to start custom containers. + # However, we can't access the remote docker's network from the primary container. This is a + # feature, as documented in https://circleci.com/docs/2.0/building-docker-images/#separation-of-environments + # As a consequence, we cannot use the circleci CLI for this job because "You cannot use the machine + # executor in local jobs." (https://circleci.com/docs/2.0/local-cli/#limitations-of-running-jobs-locally) + image: ubuntu-1604:201903-01 + steps: + - checkout + - run: # start early for less wait time below + command: ./scripts/cosm/start.sh + background: true - run: + # The images ubuntu-1604:201903-01 comes with preinstalled nvm, which does not work well with non-login shells + name: Uninstall nvm + command: rm -rf "$NVM_DIR" ~/.npm ~/.bower + - run: + name: Install nodejs and yarn + command: | + curl -sL https://deb.nodesource.com/setup_10.x | sudo -E bash - + curl -sS https://dl.yarnpkg.com/debian/pubkey.gpg | sudo apt-key add - + echo "deb https://dl.yarnpkg.com/debian/ stable main" | sudo tee /etc/apt/sources.list.d/yarn.list + sudo apt update && sudo apt install nodejs yarn + - run: + name: Version information + command: echo "node $(node --version)"; echo "yarn $(yarn --version)" + - restore_cache: + name: Restore Yarn Package Cache + keys: + - yarn-packages-{{ checksum "yarn.lock" }} + - run: + name: Install Dependencies + command: yarn install --frozen-lockfile + - save_cache: + name: Save Yarn Package Cache + key: yarn-packages-{{ checksum "yarn.lock" }} + paths: + - ~/.cache/yarn + - run: # wait until cosm scripts have fully started (this includes time for docker pull) + command: timeout 60 bash -c "until curl -s http://localhost:1317/node_info > /dev/null; do sleep 1; done" + - run: + environment: + COSMOS_ENABLED: 1 command: yarn test + - run: + command: ./scripts/cosm/stop.sh lint: docker: - image: circleci/node:10 diff --git a/scripts/cosm/env b/scripts/cosm/env index 544cf984..f2eb21ba 100644 --- a/scripts/cosm/env +++ b/scripts/cosm/env @@ -1,4 +1,4 @@ -# Choose from https://hub.docker.com/r/cosmwasm/wasmd/tags +# Choose from https://hub.docker.com/r/cosmwasm/wasmd-demo/tags REPOSITORY="cosmwasm/wasmd-demo" VERSION="latest" diff --git a/scripts/cosm/start.sh b/scripts/cosm/start.sh index 98f04ff8..3722d815 100755 --- a/scripts/cosm/start.sh +++ b/scripts/cosm/start.sh @@ -15,6 +15,10 @@ 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 \ @@ -30,12 +34,17 @@ docker run --rm \ echo "wasmd running and logging into $WASMD_LOGFILE" +# Debug chain start +sleep 3 +cat "$WASMD_LOGFILE" + sleep 10 if [ "$(docker inspect -f '{{.State.Running}}' "$CONTAINER_NAME")" != "true" ]; 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." + docker kill "$CONTAINER_NAME" exit 1 fi @@ -47,3 +56,7 @@ docker exec "$CONTAINER_NAME" \ > "$REST_SERVER_LOGFILE" & echo "rest server running on http://localhost:1317 and logging into $REST_SERVER_LOGFILE" + +# Debug rest server start +sleep 3 +cat "$REST_SERVER_LOGFILE"