Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions .dockerignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
/.git
/node_modules
/.nyc_output
*~
4 changes: 4 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -37,5 +37,9 @@ jspm_packages
*.sublime-workspace
notes.txt

# Cruft from failed Docker builds
entrypoint.sh
package-min.json

#IntelliJ
.idea
18 changes: 17 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -896,7 +896,23 @@ Some significant non-features include:

Some of these could be worthwhile additions; please comment if you're interested in using or helping implement them!

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-*-*:*`.
## Testing

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 or do forensic work in an ephemeral container with its own Redis server, e.g.:

```bash
$ ./run-docker-script.sh

$ ./run-docker-script.sh npx ava --serial --fail-fast --verbose --no-color --timeout 30000

$ ./run-docker-script.sh npm run coverage

$ ./run-docker-script.sh bash

$ ./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
Expand Down
93 changes: 93 additions & 0 deletions docker-test.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,93 @@
#!/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]}")"


if [[ "${1:-}" == "-h" || "${1:-}" == "--help" ]] ; then
cat <<EOF
$SCRIPT -- Run standard Bee-Queue tests in a Docker container with an ephemeral Redis server
Usage: $SCRIPT [command [...args]]
The optional command and args specify what to run in the container (default: npm test).
You can use tools or run scripts from package.json, e.g.
./$SCRIPT npx ava --serial --fail-fast --verbose --no-color --timeout 30000
./$SCRIPT npm run coverage
If you want to work interactively in the container, run a shell, e.g.
./$SCRIPT bash
Notes:
- The very first time this script is used it takes a while for Docker to download the base
image and to populate its caches.
- You can ignore any Transparent Huge Pages warning from the Redis server.
EOF

exit 0
fi

image=bee-queue-test

cd $DIR

# Make ENTRYPOINT script for Docker
cat > entrypoint.sh <<"EOF"
#!/bin/sh
# Docker ENTRYPOINT target
# - start a background Redis
# - evalate user-provided arguments
set -eu
# 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 "$@"
EOF
chmod +x entrypoint.sh

# Make a minimal version of package.json to avoid unnecessary `npm ci` when rebuilding the image
node > package-min.json <<EOF
const {dependencies, devDependencies} = require('./package.json');
console.log(JSON.stringify({dependencies, devDependencies}));
EOF

# Build the image
docker build --tag $image --file - . <<EOF
FROM node:lts
RUN apt-get update && apt-get install --yes --no-install-recommends redis-server
WORKDIR /bee-queue
COPY package-lock.json ./
COPY package-min.json ./package.json
RUN npm --version && npm ci
ENTRYPOINT ["./entrypoint.sh"]
CMD "npm test"
COPY . ./
RUN rm package-min.json
EOF

# Clean up build cruft
rm entrypoint.sh package-min.json

docker run --init -it --rm $image "$@"