-
Notifications
You must be signed in to change notification settings - Fork 222
feat(tests): Add docker-test.sh for running tests in a Docker container #239
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Closed
+118
−1
Closed
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
69eed72
feat(testing): Add docker-test.sh for running tests in a Docker conta…
hughsw f89ef54
chore(docker/testing): PR feedback: Improve docker-test.sh help logic…
hughsw a8c9d0f
chore(test/docker): Tweak Redis mentions in usage message for docker-…
hughsw f64c3f9
Merge branch 'master' into docker-test-in-one-script
compwright File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,4 @@ | ||
| /.git | ||
| /node_modules | ||
| /.nyc_output | ||
| *~ |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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 "$@" | ||
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.