build-static.sh 2.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364
  1. #!/bin/bash
  2. # SPDX-License-Identifier: GPL-3.0-or-later
  3. # shellcheck source=./packaging/installer/functions.sh
  4. . "$(dirname "$0")"/../installer/functions.sh || exit 1
  5. BUILDARCH="${1}"
  6. set -e
  7. platform="$("$(dirname "${0}")/uname2platform.sh" "${BUILDARCH}")"
  8. if [ -z "${platform}" ]; then
  9. exit 1
  10. fi
  11. if command -v docker > /dev/null 2>&1; then
  12. docker="docker"
  13. elif command -v podman > /dev/null 2>&1; then
  14. docker="podman"
  15. else
  16. echo "Could not find a usable OCI runtime, need either Docker or Podman."
  17. exit 1
  18. fi
  19. DOCKER_IMAGE_NAME="netdata/static-builder:v1"
  20. if [ "${BUILDARCH}" != "$(uname -m)" ] && [ -z "${SKIP_EMULATION}" ]; then
  21. if [ "$(uname -m)" = "x86_64" ]; then
  22. ${docker} run --rm --privileged multiarch/qemu-user-static --reset -p yes || exit 1
  23. else
  24. echo "Automatic cross-architecture builds are only supported on x86_64 hosts."
  25. exit 1
  26. fi
  27. fi
  28. if ${docker} inspect "${DOCKER_IMAGE_NAME}" > /dev/null 2>&1; then
  29. if ${docker} image inspect "${DOCKER_IMAGE_NAME}" | grep -q 'Variant'; then
  30. img_platform="$(${docker} image inspect "${DOCKER_IMAGE_NAME}" --format '{{.Os}}/{{.Architecture}}/{{.Variant}}')"
  31. else
  32. img_platform="$(${docker} image inspect "${DOCKER_IMAGE_NAME}" --format '{{.Os}}/{{.Architecture}}')"
  33. fi
  34. if [ "${img_platform}" != "${platform}" ]; then
  35. ${docker} image rm "${DOCKER_IMAGE_NAME}" || exit 1
  36. fi
  37. fi
  38. if ! ${docker} inspect "${DOCKER_IMAGE_NAME}" > /dev/null 2>&1; then
  39. ${docker} pull --platform "${platform}" "${DOCKER_IMAGE_NAME}"
  40. fi
  41. # Run the build script inside the container
  42. if [ -t 1 ]; then
  43. run ${docker} run --rm -e BUILDARCH="${BUILDARCH}" -a stdin -a stdout -a stderr -i -t -v "$(pwd)":/netdata:rw \
  44. --platform "${platform}" ${EXTRA_INSTALL_FLAGS:+-e EXTRA_INSTALL_FLAGS="${EXTRA_INSTALL_FLAGS}"} \
  45. "${DOCKER_IMAGE_NAME}" /bin/sh /netdata/packaging/makeself/build.sh "${@}"
  46. else
  47. run ${docker} run --rm -e BUILDARCH="${BUILDARCH}" -v "$(pwd)":/netdata:rw \
  48. -e GITHUB_ACTIONS="${GITHUB_ACTIONS}" --platform "${platform}" \
  49. ${EXTRA_INSTALL_FLAGS:+-e EXTRA_INSTALL_FLAGS="${EXTRA_INSTALL_FLAGS}"} \
  50. "${DOCKER_IMAGE_NAME}" /bin/sh /netdata/packaging/makeself/build.sh "${@}"
  51. fi