run.sh 1.0 KB

1234567891011121314151617181920212223242526272829
  1. #!/usr/bin/env bash
  2. set -Eeuo pipefail
  3. image="$1"
  4. # test that we can override the CMD with echo
  5. # https://github.com/docker-library/official-images/blob/d28cb89e79417cac50c2a8ae163a9b3b79167f79/README.md#consistency
  6. hello="world-$RANDOM-$RANDOM"
  7. cmd=( echo "Hello $hello" )
  8. case "$image" in
  9. *windowsservercore* | *nanoserver*)
  10. cmd=( cmd /Q /S /C "${cmd[*]}" )
  11. ;;
  12. esac
  13. # test first with --entrypoint to verify that we even have echo (tests for single-binary images FROM scratch, essentially)
  14. if ! testOutput="$(docker run --rm --entrypoint "${cmd[0]}" "$image" "${cmd[@]:1}" 2>/dev/null)"; then
  15. echo >&2 'image does not appear to contain "echo" -- assuming single-binary image'
  16. exit
  17. fi
  18. testOutput="$(tr -d '\r' <<<"$testOutput")" # Windows gives us \r\n ... :D
  19. [ "$testOutput" = "Hello $hello" ]
  20. # now test with normal command to verify the default entrypoint is OK
  21. output="$(docker run --rm "$image" "${cmd[@]}")"
  22. output="$(tr -d '\r' <<<"$output")" # Windows gives us \r\n ... :D
  23. [ "$output" = "Hello $hello" ]