run-in-container.sh 728 B

12345678910111213141516171819202122
  1. #!/bin/bash
  2. set -e
  3. # NOT INTENDED TO BE USED AS A TEST "run.sh" DIRECTLY
  4. # SEE OTHER "run-*-in-container.sh" SCRIPTS FOR USAGE
  5. testDir="$1"
  6. shift
  7. image="$1"
  8. shift
  9. entrypoint="$1"
  10. shift
  11. # do some fancy footwork so that if testDir is /a/b/c, we mount /a/b and use c as the working directory (so relative symlinks work one level up)
  12. testDir="$(readlink -f "$testDir")"
  13. hostMount="$(dirname "$testDir")"
  14. containerMount="/tmp/test-dir"
  15. workdir="$containerMount/$(basename "$testDir")"
  16. # TODO should we be doing something fancy with $BASH_SOURCE instead so we can be arbitrarily deep and mount the top level always?
  17. exec docker run --rm -v "$hostMount":"$containerMount":ro -w "$workdir" --entrypoint "$entrypoint" "$image" "$@"