buildx.sh 2.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485
  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. help() {
  11. echo
  12. echo "-h|--help: To display this usage information"
  13. echo "--profile <PROFILE>: EMQ X profile to build, e.g. emqx, emqx-edge"
  14. echo "--pkgtype tgz|pkg: Specify which package to build, tgz for .tar.gz"
  15. echo " and pkg for .rpm or .deb"
  16. echo "--arch amd64|arm64: Target arch to build the EMQ X package for"
  17. echo "--src_dir <SRC_DIR>: EMQ X source ode in this dir, default to PWD"
  18. echo "--builder <BUILDER>: Builder image to pull"
  19. echo " E.g. ghcr.io/emqx/emqx-builder/4.4-4:24.1.5-3-debian10"
  20. }
  21. while [ "$#" -gt 0 ]; do
  22. case $1 in
  23. -h|--help)
  24. help
  25. exit 0
  26. ;;
  27. --src_dir)
  28. SRC_DIR="$2"
  29. shift 2
  30. ;;
  31. --profile)
  32. PROFILE="$2"
  33. shift 2
  34. ;;
  35. --pkgtype)
  36. PKGTYPE="$2"
  37. shift 2
  38. ;;
  39. --builder)
  40. BUILDER="$2"
  41. shift 2
  42. ;;
  43. --arch)
  44. ARCH="$2"
  45. shift 2
  46. ;;
  47. *)
  48. echo "WARN: Unknown arg (ignored): $1"
  49. shift
  50. continue
  51. ;;
  52. esac
  53. done
  54. if [ -z "${PROFILE:-}" ] || [ -z "${PKGTYPE:-}" ] || [ -z "${BUILDER:-}" ] || [ -z "${ARCH:-}" ]; then
  55. help
  56. exit 1
  57. fi
  58. if [ "$PKGTYPE" != 'tgz' ] && [ "$PKGTYPE" != 'pkg' ]; then
  59. echo "Bad --pkgtype option, should be tgz or pkg"
  60. exit 1
  61. fi
  62. cd "${SRC_DIR:-.}"
  63. PKG_VSN="${PKG_VSN:-$(./pkg-vsn.sh)}"
  64. OTP_VSN_SYSTEM=$(echo "$BUILDER" | cut -d ':' -f2)
  65. PKG_NAME="${PROFILE}-${PKG_VSN}-otp${OTP_VSN_SYSTEM}-${ARCH}"
  66. docker info
  67. docker run --rm --privileged tonistiigi/binfmt:latest --install "${ARCH}"
  68. docker run -i --rm \
  69. -v "$(pwd)":/emqx \
  70. --workdir /emqx \
  71. --platform="linux/$ARCH" \
  72. -e EMQX_NAME="$PROFILE" \
  73. "$BUILDER" \
  74. bash -euc "make ${PROFILE}-${PKGTYPE} && .ci/build_packages/tests.sh $PKG_NAME $PKGTYPE"