build-test.sh 2.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172
  1. #!/bin/bash
  2. # Docker build wrapper, for testing manually the docker build process
  3. # TODO: This script should consume build.sh after setting up required parameters
  4. #
  5. # Copyright: SPDX-License-Identifier: GPL-3.0-or-later
  6. #
  7. # Author : Chris Akritidis (chris@netdata.cloud)
  8. # Author : Pavlos Emm. Katsoulakis (paul@netdata.cloud)
  9. printhelp() {
  10. echo "Usage: packaging/docker/build-test.sh -r <REPOSITORY> -v <VERSION> -u <DOCKER_USERNAME> -p <DOCKER_PWD> [-s]
  11. -s skip build, just push the image
  12. Builds an amd64 image and pushes it to the docker hub repository REPOSITORY"
  13. }
  14. set -e
  15. if [ ! -f .gitignore ]; then
  16. echo "Run as ./packaging/docker/$(basename "$0") from top level directory of git repository"
  17. exit 1
  18. fi
  19. DOBUILD=1
  20. while getopts :r:v:u:p:s option
  21. do
  22. case "$option" in
  23. r)
  24. REPOSITORY=$OPTARG
  25. ;;
  26. v)
  27. VERSION=$OPTARG
  28. ;;
  29. u)
  30. DOCKER_USERNAME=$OPTARG
  31. ;;
  32. p)
  33. DOCKER_PWD=$OPTARG
  34. ;;
  35. s)
  36. DOBUILD=0
  37. ;;
  38. *)
  39. printhelp
  40. exit 1
  41. ;;
  42. esac
  43. done
  44. if [ -n "${REPOSITORY}" ] && [ -n "${VERSION}" ] && [ -n "${DOCKER_USERNAME}" ] && [ -n "${DOCKER_PWD}" ] ; then
  45. if [ $DOBUILD -eq 1 ] ; then
  46. echo "Building ${VERSION} of ${REPOSITORY} container"
  47. docker run --rm --privileged multiarch/qemu-user-static:register --reset
  48. # Build images using multi-arch Dockerfile.
  49. eval docker build --build-arg ARCH="amd64" --tag "${REPOSITORY}:${VERSION}" --file packaging/docker/Dockerfile ./
  50. # Create temporary docker CLI config with experimental features enabled (manifests v2 need it)
  51. mkdir -p /tmp/docker
  52. #echo '{"experimental":"enabled"}' > /tmp/docker/config.json
  53. fi
  54. # Login to docker hub to allow futher operations
  55. echo "Logging into docker"
  56. echo "$DOCKER_PWD" | docker --config /tmp/docker login -u "$DOCKER_USERNAME" --password-stdin
  57. echo "Pushing ${REPOSITORY}:${VERSION}"
  58. docker --config /tmp/docker push "${REPOSITORY}:${VERSION}"
  59. else
  60. echo "Missing parameter. REPOSITORY=${REPOSITORY} VERSION=${VERSION} DOCKER_USERNAME=${DOCKER_USERNAME} DOCKER_PWD=${DOCKER_PWD}"
  61. printhelp
  62. exit 1
  63. fi