test-in-docker.sh 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172
  1. set -ex
  2. platform=${1:-linux/amd64}
  3. libc=${2:-musl}
  4. filePath=${3:-dist/ddns}
  5. volume=$(dirname $(realpath "$filePath"))
  6. file=$(basename "$filePath")
  7. MAP_CONF="${GITHUB_WORKSPACE}/tests/config:/config"
  8. if [ "$libc" = "glibc" ]; then
  9. container="ubuntu:19.04"
  10. else
  11. case $platform in
  12. linux/amd64)
  13. container="openwrt/rootfs:x86_64"
  14. ;;
  15. linux/386 | linux/i386)
  16. container="openwrt/rootfs:i386_pentium4"
  17. platform="linux/i386_pentium4"
  18. ;;
  19. linux/arm64)
  20. container="openwrt/rootfs:aarch64_generic"
  21. platform="linux/aarch64_generic"
  22. ;;
  23. linux/arm/v8)
  24. container="openwrt/rootfs:armsr-armv8"
  25. platform="linux/aarch64_generic"
  26. ;;
  27. linux/arm/v7)
  28. container="openwrt/rootfs:armsr-armv7"
  29. platform="linux/arm_cortex-a15_neon-vfpv4"
  30. ;;
  31. linux/arm/v6)
  32. # v6 不支持直接测试,需要qume仿真
  33. echo "::warn::untested platform '$platform' ($libc)"
  34. exit 0
  35. ;;
  36. *)
  37. container="alpine"
  38. ;;
  39. esac
  40. fi
  41. docker run --rm -v="$volume:/dist" --platform=$platform $container /dist/$file -h
  42. docker run --rm -v="$volume:/dist" --platform=$platform $container /dist/$file --version
  43. docker run --rm -v="$volume:/dist" --platform=$platform $container sh -c "/dist/$file || test -f config.json"
  44. docker run --rm -v="$volume:/dist" -v="$MAP_CONF" --platform=$platform $container /dist/$file -c /config/callback.json
  45. docker run --rm -v="$volume:/dist" -v="$MAP_CONF" --platform=$platform $container /dist/$file -c /config/debug.json
  46. docker run --rm -v="$volume:/dist" -v="$MAP_CONF" --platform=$platform $container /dist/$file -c /config/noip.json
  47. # Test task subcommand
  48. echo "Testing task subcommand..."
  49. docker run --rm -v="$volume:/dist" --platform=$platform $container /dist/$file task --help
  50. docker run --rm -v="$volume:/dist" --platform=$platform $container /dist/$file task --status
  51. # Test task functionality - auto-detect available scheduler
  52. echo "Testing task management with auto-detection..."
  53. TEST_SCRIPTS=$(dirname $(realpath "$0"))
  54. # Determine if privileged mode is needed for systemd support
  55. if [ "$libc" = "glibc" ]; then
  56. # Skip task test in glibc environment due to systemd requiring privileged container
  57. echo "Skipping task test in glibc environment (systemd requires privileged container)."
  58. else
  59. echo "Running task test cron..."
  60. docker run --rm -v="$volume:/dist" -v="$TEST_SCRIPTS:/scripts" \
  61. --platform=$platform $container /scripts/test-task-cron.sh /dist/$file
  62. fi
  63. # delete to avoid being reused
  64. docker image rm $container