build-test.sh 1.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374
  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}" ]; then
  45. if [ $DOBUILD -eq 1 ] ; then
  46. echo "Building ${VERSION:-latest} 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:-latest}" --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. if [ -n "${DOCKER_USERNAME}" ] && [ -n "${DOCKER_PWD}" ] ; then
  55. # Login to docker hub to allow futher operations
  56. echo "Logging into docker"
  57. echo "$DOCKER_PWD" | docker --config /tmp/docker login -u "$DOCKER_USERNAME" --password-stdin
  58. echo "Pushing ${REPOSITORY}:${VERSION}"
  59. docker --config /tmp/docker push "${REPOSITORY}:${VERSION}"
  60. fi
  61. else
  62. echo "Missing parameter. REPOSITORY=${REPOSITORY}"
  63. printhelp
  64. exit 1
  65. fi