build.sh 2.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172
  1. #!/usr/bin/env bash
  2. #
  3. #
  4. # Copyright: SPDX-License-Identifier: GPL-3.0-or-later
  5. #
  6. # Author : Pawel Krupa (paulfantom)
  7. # Author : Pavlos Emm. Katsoulakis (paul@netdata.cloud)
  8. set -e
  9. if [ "${BASH_VERSINFO[0]}" -lt "4" ]; then
  10. echo "This mechanism currently can only run on BASH version 4 and above"
  11. exit 1
  12. fi
  13. VERSION="$1"
  14. declare -A ARCH_MAP
  15. ARCH_MAP=(["i386"]="386" ["amd64"]="amd64" ["armhf"]="arm" ["aarch64"]="arm64")
  16. DEVEL_ARCHS=(amd64)
  17. ARCHS="${!ARCH_MAP[@]}"
  18. if [ -z ${REPOSITORY} ]; then
  19. REPOSITORY="${TRAVIS_REPO_SLUG}"
  20. if [ -z ${REPOSITORY} ]; then
  21. echo "REPOSITORY not set, build cannot proceed"
  22. exit 1
  23. else
  24. echo "REPOSITORY was not detected, attempted to use TRAVIS_REPO_SLUG setting: ${TRAVIS_REPO_SLUG}"
  25. fi
  26. fi
  27. # When development mode is set, build on DEVEL_ARCHS
  28. if [ ! -z ${DEVEL+x} ]; then
  29. declare -a ARCHS=(${DEVEL_ARCHS[@]})
  30. fi
  31. # Ensure there is a version, the most appropriate one
  32. if [ "${VERSION}" == "" ]; then
  33. VERSION=$(git tag --points-at)
  34. if [ "${VERSION}" == "" ]; then
  35. VERSION="latest"
  36. fi
  37. fi
  38. # If we are not in netdata git repo, at the top level directory, fail
  39. TOP_LEVEL=$(basename "$(git rev-parse --show-toplevel)")
  40. CWD=$(git rev-parse --show-cdup)
  41. if [ ! -z $CWD ] || [ ! "${TOP_LEVEL}" == "netdata" ]; then
  42. echo "Run as ./packaging/docker/$(basename "$0") from top level directory of netdata git repository"
  43. echo "Docker build process aborted"
  44. exit 1
  45. fi
  46. echo "Docker image build in progress.."
  47. echo "Version : ${VERSION}"
  48. echo "Repository : ${REPOSITORY}"
  49. echo "Architectures : ${ARCHS[*]}"
  50. docker run --rm --privileged multiarch/qemu-user-static:register --reset
  51. # Build images using multi-arch Dockerfile.
  52. for ARCH in ${ARCHS[@]}; do
  53. TAG="${REPOSITORY}:${VERSION}-${ARCH}"
  54. echo "Building tag ${TAG}.."
  55. eval docker build --no-cache \
  56. --build-arg ARCH="${ARCH}" \
  57. --tag "${TAG}" \
  58. --file packaging/docker/Dockerfile ./
  59. echo "..Done!"
  60. done
  61. echo "Docker build process completed!"