build-images.sh 2.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495
  1. #!/bin/bash
  2. set -o errexit
  3. set -o nounset
  4. set -o pipefail
  5. STARTTIME=$(date +%s)
  6. source_root=$(dirname "${0}")/..
  7. prefix="openshift/origin-ansible"
  8. version="latest"
  9. verbose=false
  10. options="-f images/installer/Dockerfile"
  11. help=false
  12. for args in "$@"
  13. do
  14. case $args in
  15. --prefix=*)
  16. prefix="${args#*=}"
  17. ;;
  18. --version=*)
  19. version="${args#*=}"
  20. ;;
  21. --no-cache)
  22. options="${options} --no-cache"
  23. ;;
  24. --verbose)
  25. verbose=true
  26. ;;
  27. --help)
  28. help=true
  29. ;;
  30. esac
  31. done
  32. # allow ENV to take precedent over switches
  33. prefix="${PREFIX:-$prefix}"
  34. version="${OS_TAG:-$version}"
  35. if [ "$help" = true ]; then
  36. echo "Builds the docker images for openshift-ansible"
  37. echo
  38. echo "Options: "
  39. echo " --prefix=PREFIX"
  40. echo " The prefix to use for the image names."
  41. echo " default: docker.io/openshift/origin-ansible"
  42. echo
  43. echo " --version=VERSION"
  44. echo " The version used to tag the image (can be a comma-separated list)"
  45. echo " default: latest"
  46. echo
  47. echo " --no-cache"
  48. echo " If set will perform the build without a cache."
  49. echo
  50. echo " --verbose"
  51. echo " Enables printing of the commands as they run."
  52. echo
  53. echo " --help"
  54. echo " Prints this help message"
  55. echo
  56. exit 0
  57. fi
  58. if [ "$verbose" = true ]; then
  59. set -x
  60. fi
  61. BUILD_STARTTIME=$(date +%s)
  62. comp_path=$source_root/
  63. # turn comma-separated versions into -t args for docker build
  64. IFS=',' read -r -a version_arr <<< "$version"
  65. docker_tags=()
  66. for tag in "${version_arr[@]}"; do
  67. docker_tags+=("-t" "${prefix}:${tag}")
  68. done
  69. echo
  70. echo
  71. echo "--- Building component '$comp_path' with docker tag(s) '$version' ---"
  72. docker build ${options} "${docker_tags[@]}" $comp_path
  73. BUILD_ENDTIME=$(date +%s); echo "--- ${version} took $(($BUILD_ENDTIME - $BUILD_STARTTIME)) seconds ---"
  74. echo
  75. echo
  76. echo
  77. echo
  78. echo "++ Active images"
  79. docker images | grep ${prefix} | sort
  80. echo
  81. ret=$?; ENDTIME=$(date +%s); echo "$0 took $(($ENDTIME - $STARTTIME)) seconds"; exit "$ret"