build.sh 2.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677
  1. #!/bin/bash
  2. # SPDX-License-Identifier: GPL-3.0-or-later
  3. # Author : Pawel Krupa (paulfantom)
  4. # Cross-arch docker build helper script
  5. # Needs docker in version >18.02 due to usage of manifests
  6. set -e
  7. REPOSITORY="${REPOSITORY:-netdata}"
  8. VERSION=$(git tag --points-at)
  9. if [ "${VERSION}" == "" ]; then
  10. VERSION="latest"
  11. fi
  12. declare -A ARCH_MAP
  13. ARCH_MAP=( ["i386"]="386" ["amd64"]="amd64" ["armhf"]="arm" ["aarch64"]="arm64")
  14. docker run --rm --privileged multiarch/qemu-user-static:register --reset
  15. if [ -f Dockerfile ]; then
  16. cd ../ || exit 1
  17. fi
  18. # Build images using multi-arch Dockerfile.
  19. for ARCH in i386 armhf aarch64 amd64; do
  20. docker build --build-arg ARCH="${ARCH}-v3.8" --tag "${REPOSITORY}:${VERSION}-${ARCH}" --file docker/Dockerfile ./ &
  21. done
  22. wait
  23. # Create temporary docker CLI config with experimental features enabled (manifests v2 need it)
  24. mkdir -p /tmp/docker
  25. echo '{"experimental":"enabled"}' > /tmp/docker/config.json
  26. # Login to docker hub to allow for futher operations
  27. if [ -z ${DOCKER_USERNAME+x} ] || [ -z ${DOCKER_PASSWORD+x} ]; then
  28. echo "No docker hub username or password specified. Exiting without pushing images to registry"
  29. exit 1
  30. fi
  31. echo "$DOCKER_PASSWORD" | docker --config /tmp/docker login -u "$DOCKER_USERNAME" --password-stdin
  32. # Push images to registry
  33. for ARCH in amd64 i386 armhf aarch64; do
  34. docker --config /tmp/docker push "${REPOSITORY}:${VERSION}-${ARCH}" &
  35. done
  36. wait
  37. # Recreate docker manifest
  38. docker --config /tmp/docker manifest create --amend \
  39. "${REPOSITORY}:${VERSION}" \
  40. "${REPOSITORY}:${VERSION}-i386" \
  41. "${REPOSITORY}:${VERSION}-armhf" \
  42. "${REPOSITORY}:${VERSION}-aarch64" \
  43. "${REPOSITORY}:${VERSION}-amd64"
  44. # Annotate manifest with CPU architecture information
  45. for ARCH in i386 armhf aarch64 amd64; do
  46. docker --config /tmp/docker manifest annotate "${REPOSITORY}:${VERSION}" "${REPOSITORY}:${VERSION}-${ARCH}" --os linux --arch "${ARCH_MAP[$ARCH]}"
  47. done
  48. # Push manifest to docker hub
  49. docker --config /tmp/docker manifest push -p "${REPOSITORY}:${VERSION}"
  50. # Show current manifest (debugging purpose only)
  51. docker --config /tmp/docker manifest inspect "${REPOSITORY}:${VERSION}"
  52. # Push netdata images to firehol organization
  53. # TODO: Remove it after we decide to deprecate firehol/netdata docker repo
  54. if [ "$REPOSITORY" != "netdata" ]; then
  55. echo "$OLD_DOCKER_PASSWORD" | docker login -u "$OLD_DOCKER_USERNAME" --password-stdin
  56. for ARCH in amd64 i386 armhf aarch64; do
  57. docker tag "${REPOSITORY}:${VERSION}-${ARCH}" "firehol/netdata:${ARCH}"
  58. docker push "firehol/netdata:${ARCH}"
  59. done
  60. docker tag "${REPOSITORY}:latest-amd64" "firehol/netdata:latest"
  61. docker push "firehol/netdata:latest"
  62. fi