buildx.sh 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117
  1. #!/usr/bin/env bash
  2. ## This script helps to run docker buildx to build cross-arch/platform packages (linux only)
  3. ## It mounts (not copy) host directory to a cross-arch/platform builder container
  4. ## Make sure the source dir (specified by --src_dir option) is clean before running this script
  5. ## NOTE: it requires $USER in docker group
  6. ## i.e. will not work if docker command has to be executed with sudo
  7. ## example:
  8. ## ./scripts/buildx.sh --profile emqx --pkgtype tgz --arch arm64 --builder ghcr.io/emqx/emqx-builder/4.4-4:24.1.5-3-debian10
  9. set -euo pipefail
  10. set -x
  11. help() {
  12. echo
  13. echo "-h|--help: To display this usage information"
  14. echo "--profile <PROFILE>: EMQ X profile to build, e.g. emqx, emqx-edge"
  15. echo "--pkgtype tgz|pkg|elixirpkg: Specify which package to build, tgz for .tar.gz,"
  16. echo " pkg and elixirpkg for .rpm or .deb"
  17. echo "--arch amd64|arm64: Target arch to build the EMQ X package for"
  18. echo "--src_dir <SRC_DIR>: EMQ X source ode in this dir, default to PWD"
  19. echo "--builder <BUILDER>: Builder image to pull"
  20. echo " E.g. ghcr.io/emqx/emqx-builder/4.4-4:24.1.5-3-debian10"
  21. echo "--otp <OTP_VSN>: OTP version being used in the builder"
  22. echo "--elixir <ELIXIR_VSN>: Elixir version being used in the builder"
  23. echo "--system <SYSTEM>: OS used in the builder image"
  24. }
  25. while [ "$#" -gt 0 ]; do
  26. case $1 in
  27. -h|--help)
  28. help
  29. exit 0
  30. ;;
  31. --src_dir)
  32. SRC_DIR="$2"
  33. shift 2
  34. ;;
  35. --profile)
  36. PROFILE="$2"
  37. shift 2
  38. ;;
  39. --pkgtype)
  40. PKGTYPE="$2"
  41. shift 2
  42. ;;
  43. --builder)
  44. BUILDER="$2"
  45. shift 2
  46. ;;
  47. --arch)
  48. ARCH="$2"
  49. shift 2
  50. ;;
  51. --otp)
  52. OTP_VSN="$2"
  53. shift 2
  54. ;;
  55. --elixir)
  56. ELIXIR_VSN="$2"
  57. shift 2
  58. ;;
  59. --system)
  60. SYSTEM="$2"
  61. shift 2
  62. ;;
  63. *)
  64. echo "WARN: Unknown arg (ignored): $1"
  65. shift
  66. continue
  67. ;;
  68. esac
  69. done
  70. if [ -z "${PROFILE:-}" ] ||
  71. [ -z "${PKGTYPE:-}" ] ||
  72. [ -z "${BUILDER:-}" ] ||
  73. [ -z "${ARCH:-}" ] ||
  74. [ -z "${OTP_VSN:-}" ] ||
  75. [ -z "${ELIXIR_VSN:-}" ] ||
  76. [ -z "${SYSTEM:-}" ]; then
  77. help
  78. exit 1
  79. fi
  80. case "$PKGTYPE" in
  81. tgz|pkg|elixirpkg)
  82. true
  83. ;;
  84. *)
  85. echo "Bad --pkgtype option, should be zip or pkg"
  86. exit 1
  87. ;;
  88. esac
  89. cd "${SRC_DIR:-.}"
  90. PKG_VSN="${PKG_VSN:-$(./pkg-vsn.sh "$PROFILE")}"
  91. if [ "$PKGTYPE" = "elixirpkg" ]
  92. then
  93. PKG_NAME="${PROFILE}-${PKG_VSN}-otp${OTP_VSN}-elixir${ELIXIR_VSN}-${SYSTEM}-${ARCH}"
  94. else
  95. PKG_NAME="${PROFILE}-${PKG_VSN}-otp${OTP_VSN}-${SYSTEM}-${ARCH}"
  96. fi
  97. docker info
  98. docker run --rm --privileged tonistiigi/binfmt:latest --install "${ARCH}"
  99. docker run -i --rm \
  100. -v "$(pwd)":/emqx \
  101. --workdir /emqx \
  102. --platform="linux/$ARCH" \
  103. -e EMQX_NAME="$PROFILE" \
  104. "$BUILDER" \
  105. bash -euc "make ${PROFILE}-${PKGTYPE} && .ci/build_packages/tests.sh $PKG_NAME $PKGTYPE"