screenshotter.sh 1.1 KB

1234567891011121314151617181920212223242526272829303132333435363738
  1. #!/bin/bash
  2. # This script does a one-shot creation of screenshots, creating needed
  3. # docker containers and removing them afterwards. During development,
  4. # it might be desirable to avoid the overhead for starting and
  5. # stopping the containers. Developers are encouraged to manage
  6. # suitable containers themselves, calling the screenshotter.js script
  7. # directly.
  8. cleanup() {
  9. [[ "${container}" ]] \
  10. && docker stop "${container}" >/dev/null \
  11. && docker rm "${container}" >/dev/null
  12. container=
  13. }
  14. container=
  15. trap cleanup EXIT
  16. status=0
  17. for browserTag in firefox:2.48.2 chrome:2.48.2; do
  18. browser=${browserTag%:*}
  19. image=selenium/standalone-${browserTag}
  20. echo "Starting container for ${image}"
  21. container=$(docker run -d -P ${image})
  22. [[ ${container} ]] || continue
  23. echo "Container ${container:0:12} started, creating screenshots..."
  24. if node "$(dirname "$0")"/screenshotter.js \
  25. --browser="${browser}" --container="${container}" "$@"; then
  26. res=Done
  27. else
  28. res=Failed
  29. status=1
  30. fi
  31. echo "${res} taking screenshots, stopping and removing ${container:0:12}"
  32. cleanup
  33. done
  34. exit ${status}