build-static.sh 2.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465
  1. #!/usr/bin/env 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. case ${BUILDARCH} in
  8. x86_64) platform=linux/amd64 ;;
  9. armv7l) platform=linux/arm/v7 ;;
  10. aarch64) platform=linux/arm64/v8 ;;
  11. ppc64le) platform=linux/ppc64le ;;
  12. *)
  13. echo "Unknown target architecture '${BUILDARCH}'."
  14. exit 1
  15. ;;
  16. esac
  17. DOCKER_CONTAINER_NAME="netdata-package-${BUILDARCH}-static-alpine315"
  18. if [ "${BUILDARCH}" != "$(uname -m)" ] && [ "$(uname -m)" = 'x86_64' ] && [ -z "${SKIP_EMULATION}" ]; then
  19. docker run --rm --privileged multiarch/qemu-user-static --reset -p yes || exit 1
  20. fi
  21. if ! docker inspect "${DOCKER_CONTAINER_NAME}" > /dev/null 2>&1; then
  22. # To run interactively:
  23. # docker run -it netdata-package-x86_64-static /bin/sh
  24. # (add -v host-dir:guest-dir:rw arguments to mount volumes)
  25. #
  26. # To remove images in order to re-create:
  27. # docker rm -v $(sudo docker ps -a -q -f status=exited)
  28. # docker rmi netdata-package-x86_64-static
  29. #
  30. # This command maps the current directory to
  31. # /usr/src/netdata.git
  32. # inside the container and runs the script install-alpine-packages.sh
  33. # (also inside the container)
  34. #
  35. if docker inspect alpine:3.15 > /dev/null 2>&1; then
  36. run docker image remove alpine:3.15
  37. run docker pull --platform=${platform} alpine:3.15
  38. fi
  39. run docker run --platform=${platform} -v "$(pwd)":/netdata:rw alpine:3.15 \
  40. /bin/sh /netdata/packaging/makeself/install-alpine-packages.sh
  41. # save the changes made permanently
  42. id=$(docker ps -l -q)
  43. run docker commit "${id}" "${DOCKER_CONTAINER_NAME}"
  44. fi
  45. # Run the build script inside the container
  46. if [ -t 1 ]; then
  47. run docker run -e BUILDARCH="${BUILDARCH}" -a stdin -a stdout -a stderr -i -t -v "$(pwd)":/netdata:rw \
  48. "${DOCKER_CONTAINER_NAME}" \
  49. /bin/sh /netdata/packaging/makeself/build.sh "${@}"
  50. else
  51. run docker run -e BUILDARCH="${BUILDARCH}" -v "$(pwd)":/netdata:rw \
  52. -e GITHUB_ACTIONS="${GITHUB_ACTIONS}" "${DOCKER_CONTAINER_NAME}" \
  53. /bin/sh /netdata/packaging/makeself/build.sh "${@}"
  54. fi