build.sh 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127
  1. #!/bin/bash
  2. set -ex
  3. WORK_DIR=$(dirname $(readlink -f $0))
  4. HUE_SRC=$(realpath $WORK_DIR/../..)
  5. BUILD_DIR=$(realpath $HUE_SRC/../containerbuild$GBN)
  6. HUE_DIR=$WORK_DIR/hue
  7. APACHE_DIR=$WORK_DIR/huelb
  8. BASEHUE_DIR=$WORK_DIR/base/hue
  9. BASEHUELB_DIR=$WORK_DIR/base/huelb
  10. REGISTRY=${REGISTRY:-"docker.io/hortonworks"}
  11. HUEUSER="hive"
  12. compile_hue() {
  13. mkdir -p $BUILD_DIR
  14. cd $HUE_SRC
  15. PREFIX=$BUILD_DIR make install
  16. cd $BUILD_DIR/hue
  17. APPS=$(find apps -maxdepth 2 -name "src" -type d|cut -d"/" -f2|sort| sed 's/[^ ]* */apps\/&/g')
  18. ./build/env/bin/python tools/app_reg/app_reg.py --install $APPS --relative-paths
  19. bash tools/relocatable.sh
  20. }
  21. find_git_state() {
  22. cd $HUE_SRC
  23. export GBRANCH=$(git ls-remote --get-url)"/commits/"$(git rev-parse --abbrev-ref HEAD)
  24. export GSHA=$(git ls-remote --get-url)"/commit/"$(git rev-list --no-walk HEAD)
  25. export VERSION=$(grep "VERSION=" VERSION | cut -d"=" -f2 | cut -d'"' -f2)
  26. }
  27. subst_var() {
  28. file_name=$1
  29. if [[ -e $file_name ]]; then
  30. if [[ "$file_name" == *"_template" ]]; then
  31. out_name="${file_name::-9}.conf"
  32. fi
  33. fi
  34. envsubst < $file_name > $out_name
  35. }
  36. docker_hue_build() {
  37. export HUE_USER="hive"
  38. export HUE_CONF="/etc/hue"
  39. export HUE_HOME="/opt/${HUEUSER}"
  40. export HUE_CONF_DIR="${HUE_CONF}/conf"
  41. export HUE_LOG_DIR="/var/log/${HUEUSER}"
  42. export UUID_GEN=$(uuidgen | cut -d"-" -f5)
  43. cd $HUE_DIR
  44. cp -a $BUILD_DIR/hue $HUE_DIR
  45. rm -f $HUE_DIR/hue/desktop/conf/*
  46. for f in $(find $HUE_DIR/supervisor-files -name "*_template"); do
  47. subst_var $f
  48. done
  49. docker build -f $HUE_DIR/Dockerfile -t ${REGISTRY}/hue:$GBN \
  50. --build-arg GBN=$GBN \
  51. --build-arg GSHA="$GSHA" \
  52. --build-arg GBRANCH=$GBRANCH \
  53. --build-arg VERSION=$VERSION \
  54. --build-arg HUEUSER=$HUEUSER \
  55. .
  56. }
  57. docker_huelb_build() {
  58. export HUE_USER="hive"
  59. export HUE_CONF="/etc/hue"
  60. export HUE_HOME="/opt/${HUEUSER}"
  61. export HUE_CONF_DIR="${HUE_CONF}/conf"
  62. export HUE_LOG_DIR="/var/log/${HUEUSER}"
  63. cd $APACHE_DIR
  64. cp -a $BUILD_DIR/hue/build/static $APACHE_DIR
  65. for f in $(find $APACHE_DIR -name "*_template"); do
  66. subst_var $f
  67. done
  68. docker build -f $APACHE_DIR/Dockerfile -t ${REGISTRY}/huelb:$GBN \
  69. --build-arg GBN=$GBN \
  70. --build-arg GSHA="$GSHA" \
  71. --build-arg GBRANCH=$GBRANCH \
  72. --build-arg VERSION=$VERSION \
  73. --build-arg HUEUSER=$HUEUSER \
  74. .
  75. }
  76. build_huebase() {
  77. cd $BASEHUE_DIR
  78. docker build -f $BASEHUE_DIR/Dockerfile -t ${REGISTRY}/huebase_centos:7 .
  79. docker tag ${REGISTRY}/huebase_centos:7 huebase_centos:7
  80. docker push ${REGISTRY}/huebase_centos:7
  81. docker pull ${REGISTRY}/huebase_centos:7
  82. }
  83. build_huelbbase() {
  84. cd $BASEHUELB_DIR
  85. docker build -f $BASEHUELB_DIR/Dockerfile -t ${REGISTRY}/huelb_httpd:2.4 .
  86. docker tag ${REGISTRY}/huelb_httpd:2.4 huelb_httpd:2.4
  87. docker push ${REGISTRY}/huelb_httpd:2.4
  88. docker pull ${REGISTRY}/huelb_httpd:2.4
  89. }
  90. pull_base_images() {
  91. set +e
  92. docker pull ${REGISTRY}/huebase_centos:7
  93. if [[ $? != 0 ]]; then
  94. build_huebase
  95. fi
  96. docker tag ${REGISTRY}/huebase_centos:7 huebase_centos:7
  97. docker pull ${REGISTRY}/huelb_httpd:2.4
  98. if [[ $? != 0 ]]; then
  99. build_huelbbase
  100. fi
  101. docker tag ${REGISTRY}/huelb_httpd:2.4 huelb_httpd:2.4
  102. set -e
  103. }
  104. compile_hue
  105. find_git_state
  106. pull_base_images
  107. docker_hue_build
  108. docker_huelb_build