build.sh 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126
  1. #!/bin/bash
  2. set -euo pipefail
  3. IFS=$'\n\t'
  4. export PLATFORM=$1
  5. export ZT_ISA=$2
  6. export VERSION=$3
  7. export EVENT=$4
  8. case $PLATFORM in
  9. sid)
  10. export PKGFMT=none
  11. ;;
  12. el*|fc*|amzn*)
  13. export PKGFMT=rpm
  14. ;;
  15. *)
  16. export PKGFMT=deb
  17. esac
  18. #
  19. # Allow user to drop in custom Dockerfile for PLATFORM
  20. #
  21. if [ -f "ci/Dockerfile.${PLATFORM}" ]; then
  22. export DOCKERFILE="ci/Dockerfile.${PLATFORM}"
  23. else
  24. export DOCKERFILE="ci/Dockerfile.${PKGFMT}"
  25. fi
  26. #
  27. # Rust sometimes gets confused about where it's running.
  28. # Normally, the build images will have Rust pre-baked.
  29. # Pass RUST_TRIPLET for convenience when using a custom Dockerfile
  30. #
  31. case $ZT_ISA in
  32. 386)
  33. export DOCKER_ARCH=386
  34. export RUST_TRIPLET=i686-unknown-linux-gnu
  35. ;;
  36. amd64)
  37. export DOCKER_ARCH=amd64
  38. export RUST_TRIPLET=x86_64-unknown-linux-gnu
  39. ;;
  40. armv7)
  41. export DOCKER_ARCH=arm/v7
  42. export RUST_TRIPLET=armv7-unknown-linux-gnueabihf
  43. ;;
  44. arm64)
  45. export DOCKER_ARCH=arm64/v8
  46. export RUST_TRIPLET=aarch64-unknown-linux-gnu
  47. ;;
  48. riscv64)
  49. export DOCKER_ARCH=riscv64
  50. export RUST_TRIPLET=riscv64gc-unknown-linux-gnu
  51. ;;
  52. ppc64le)
  53. export DOCKER_ARCH=ppc64le
  54. export RUST_TRIPLET=powerpc64le-unknown-linux-gnu
  55. ;;
  56. mips64le)
  57. export DOCKER_ARCH=mips64le
  58. export RUST_TRIPLET=mips64el-unknown-linux-gnuabi64
  59. ;;
  60. s390x)
  61. export DOCKER_ARCH=s390x
  62. export RUST_TRIPLET=s390x-unknown-linux-gnu
  63. ;;
  64. *)
  65. echo "ERROR: could not determine architecture settings. PLEASE FIX ME"
  66. exit 1
  67. ;;
  68. esac
  69. #
  70. # Print debug info
  71. #
  72. echo "#~~~~~~~~~~~~~~~~~~~~"
  73. echo "$0 variables:"
  74. echo "nproc: $(nproc)"
  75. echo "ZT_ISA: ${ZT_ISA}"
  76. echo "DOCKER_ARCH: ${DOCKER_ARCH}"
  77. echo "RUST_TRIPLET: ${RUST_TRIPLET}"
  78. echo "VERSION: ${VERSION}"
  79. echo "EVENT: ${EVENT}"
  80. echo "PKGFMT: ${PKGFMT}"
  81. echo "PWD: ${PWD}"
  82. echo "DOCKERFILE: ${DOCKERFILE}"
  83. echo "#~~~~~~~~~~~~~~~~~~~~"
  84. #
  85. # Munge RPM and Deb
  86. #
  87. if [ ${PKGFMT} != "none" ] && [ ${EVENT} != "tag" ]; then
  88. make munge_rpm zerotier-one.spec VERSION=${VERSION}
  89. make munge_deb debian/changelog VERSION=${VERSION}
  90. fi
  91. #
  92. # Assemble buildx arguments
  93. #
  94. build_args=(
  95. --no-cache
  96. --build-arg PLATFORM=${PLATFORM}
  97. --build-arg RUST_TRIPLET=${RUST_TRIPLET}
  98. --build-arg DOCKER_ARCH=${DOCKER_ARCH}
  99. --platform linux/${DOCKER_ARCH}
  100. -f ${DOCKERFILE}
  101. -t build
  102. .
  103. )
  104. if [ ${PKGFMT} != "none" ]; then
  105. build_args+=("--output type=local,dest=.")
  106. build_args+=("--target export")
  107. fi
  108. #
  109. # Do build
  110. #
  111. docker buildx build ${build_args[@]}