diff --git a/.dockerignore b/.dockerignore new file mode 100644 index 00000000..16ef8145 --- /dev/null +++ b/.dockerignore @@ -0,0 +1,2 @@ +/.git +/node_modules diff --git a/Dockerfile-docker-scripts b/Dockerfile-docker-scripts new file mode 100644 index 00000000..18c40f86 --- /dev/null +++ b/Dockerfile-docker-scripts @@ -0,0 +1,14 @@ +FROM node:lts-alpine + +RUN apk add bash redis + +WORKDIR /bee-queue +COPY package.json package-lock.json /bee-queue/ +RUN cd /bee-queue && npm --version && npm ci + +ENTRYPOINT ["/bee-queue/docker-scripts/entrypoint.sh"] + +COPY .eslintrc.json /bee-queue/ +COPY docker-scripts /bee-queue/docker-scripts/ +COPY test /bee-queue/test/ +COPY lib /bee-queue/lib/ diff --git a/README.md b/README.md index 485909d3..2f0b6006 100644 --- a/README.md +++ b/README.md @@ -857,6 +857,20 @@ Some of these could be worthwhile additions; please comment if you're interested You'll need a local redis server to run the tests. Note that running the tests may delete some keys in the form of `bq:test-*-*:*`. +Alternatively, if you have Docker available, you can run tests and do other dev forensics in a ephemeral container with its own Redis server, e.g.: +```bash +$ ./run-docker-script.sh + +$ ./run-docker-script.sh bash + +$ ./run-docker-script.sh npx ava --fail-fast --verbose + +$ ./run-docker-script.sh npm run ci + +$ ./run-docker-script.sh --help +``` + + [npm-image]: https://img.shields.io/npm/v/bee-queue.svg?style=flat [npm-url]: https://www.npmjs.com/package/bee-queue [travis-image]: https://img.shields.io/travis/bee-queue/bee-queue.svg?style=flat diff --git a/docker-scripts/default-docker-script.sh b/docker-scripts/default-docker-script.sh new file mode 100755 index 00000000..7118fddc --- /dev/null +++ b/docker-scripts/default-docker-script.sh @@ -0,0 +1,12 @@ +#!/bin/sh + +# Default script to run in bee-queue-docker container + +# We don't do `npm run ci` because we may not have credentials to publish to coveralls + +set -eux + +# This ordering supports quick iteration on new testing +npx ava +npm run eslint +npm run coverage diff --git a/docker-scripts/entrypoint.sh b/docker-scripts/entrypoint.sh new file mode 100755 index 00000000..e0501d4f --- /dev/null +++ b/docker-scripts/entrypoint.sh @@ -0,0 +1,12 @@ +#!/bin/sh + +# Docker ENTRYPOINT target +# - start a background Redis +# - evalate user-provided arguments + +# See: https://raw.githubusercontent.com/antirez/redis/5.0/redis.conf +# We don't use --daemonize because this is a dev configuration and we want to see warnings from Redis. +# If someone knows how to prevent the "Transparent Huge Page" warning on Docker for Mac, please advise. +/usr/bin/redis-server --tcp-backlog 128 --loglevel warning & + +eval "$@" diff --git a/run-docker-script.sh b/run-docker-script.sh new file mode 100755 index 00000000..531185dc --- /dev/null +++ b/run-docker-script.sh @@ -0,0 +1,55 @@ +#!/bin/bash + +# Strict, and loud failure +set -euo pipefail +trap 'rc=$?;set +ex;if [[ $rc -ne 0 ]];then trap - ERR EXIT;echo 1>&2;echo "*** fail *** : code $rc : $DIR/$SCRIPT $ARGS" 1>&2;echo 1>&2;exit $rc;fi' ERR EXIT +ARGS="$*" +DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)" +SCRIPT="$(basename "${BASH_SOURCE[0]}")" + +# A command or the name of a script to run in the container +# Note: scripts must be in ./docker-scripts/ in order to get copied into the Docker image +scriptName=${1:-docker-scripts/default-docker-script.sh} +shift || true + +if [ "$scriptName" = -h -o "$scriptName" = --help ] ; then + cat <