build.sh 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161
  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. HUEBASE_VERSION=huebase_centos:7.6
  11. HUELBBASE_VERSION=huelb_httpd:2.4.7.6
  12. HUEUSER="hive"
  13. if [ -z "$REGISTRY" ]; then
  14. REGISTRY=${REGISTRY:-"docker.io/hortonworks"}
  15. BASEOS_URL=${REGISTRY:-"docker.io/centos:centos7"}
  16. else
  17. if [[ $REGISTRY == *cdh ]]; then
  18. BASEOS_URL=$(echo $(echo $REGISTRY | cut -d '/' -f 1)/cloudera_base/centos:7.6.1810)
  19. fi
  20. fi
  21. compile_hue() {
  22. mkdir -p $BUILD_DIR
  23. cd $HUE_SRC
  24. PREFIX=$BUILD_DIR make install
  25. cd $BUILD_DIR/hue
  26. APPS=$(find apps -maxdepth 2 -name "src" -type d|cut -d"/" -f2|sort| sed 's/[^ ]* */apps\/&/g')
  27. ./build/env/bin/python tools/app_reg/app_reg.py --install $APPS --relative-paths
  28. bash tools/relocatable.sh
  29. }
  30. find_git_state() {
  31. cd $HUE_SRC
  32. export GBRANCH=$(git ls-remote --get-url)"/commits/"$(git rev-parse --abbrev-ref HEAD)
  33. export GSHA=$(git ls-remote --get-url)"/commit/"$(git rev-list --no-walk HEAD)
  34. export VERSION=$(grep "VERSION=" VERSION | cut -d"=" -f2 | cut -d'"' -f2)
  35. }
  36. subst_var() {
  37. file_name=$1
  38. if [[ -e $file_name ]]; then
  39. if [[ "$file_name" == *"_template" ]]; then
  40. out_name="${file_name::-9}.conf"
  41. fi
  42. fi
  43. eval "cat <<EOF
  44. $(<$file_name)
  45. EOF
  46. " | tee $out_name 2> /dev/null
  47. }
  48. docker_hue_build() {
  49. export HUE_USER="hive"
  50. export HUE_CONF="/etc/hue"
  51. export HUE_HOME="/opt/${HUEUSER}"
  52. export HUE_CONF_DIR="${HUE_CONF}/conf"
  53. export HUE_LOG_DIR="/var/log/${HUEUSER}"
  54. export UUID_GEN=$(uuidgen | cut -d"-" -f5)
  55. cd $HUE_DIR
  56. cp -a $BUILD_DIR/hue $HUE_DIR
  57. rm -f $HUE_DIR/hue/desktop/conf/*
  58. for f in $(find $HUE_DIR/supervisor-files -name "*_template"); do
  59. subst_var $f
  60. done
  61. sed -i -e "s#\${HUEBASE_VERSION}#${HUEBASE_VERSION}#g" $HUE_DIR/Dockerfile
  62. docker build -f $HUE_DIR/Dockerfile -t ${REGISTRY}/hue:$GBN \
  63. --build-arg GBN=$GBN \
  64. --build-arg GSHA="$GSHA" \
  65. --build-arg GBRANCH=$GBRANCH \
  66. --build-arg VERSION=$VERSION \
  67. --build-arg HUEUSER=$HUEUSER \
  68. --build-arg HUE_CONF=$HUE_CONF \
  69. .
  70. }
  71. docker_huelb_build() {
  72. export HUE_USER="hive"
  73. export HUE_CONF="/etc/hue"
  74. export HUE_HOME="/opt/${HUEUSER}"
  75. export HUE_CONF_DIR="${HUE_CONF}/conf"
  76. export HUE_LOG_DIR="/var/log/${HUEUSER}"
  77. cd $APACHE_DIR
  78. cp -a $BUILD_DIR/hue/build/static $APACHE_DIR
  79. for f in $(find $APACHE_DIR -name "*_template"); do
  80. subst_var $f
  81. done
  82. sed -i -e "s#\${HUELBBASE_VERSION}#${HUELBBASE_VERSION}#g" $APACHE_DIR/Dockerfile
  83. docker build -f $APACHE_DIR/Dockerfile -t ${REGISTRY}/huelb:$GBN \
  84. --build-arg GBN=$GBN \
  85. --build-arg GSHA="$GSHA" \
  86. --build-arg GBRANCH=$GBRANCH \
  87. --build-arg VERSION=$VERSION \
  88. --build-arg HUEUSER=$HUEUSER \
  89. --build-arg HUE_CONF=$HUE_CONF \
  90. .
  91. }
  92. build_huebase() {
  93. cd $BASEHUE_DIR
  94. docker build -f $BASEHUE_DIR/Dockerfile -t ${REGISTRY}/$HUEBASE_VERSION .
  95. docker tag ${REGISTRY}/$HUEBASE_VERSION $HUEBASE_VERSION
  96. docker push ${REGISTRY}/$HUEBASE_VERSION
  97. docker pull ${REGISTRY}/$HUEBASE_VERSION
  98. }
  99. build_huelbbase() {
  100. cd $BASEHUELB_DIR
  101. docker build -f $BASEHUELB_DIR/Dockerfile -t ${REGISTRY}/$HUELBBASE_VERSION .
  102. docker tag ${REGISTRY}/$HUELBBASE_VERSION $HUELBBASE_VERSION
  103. docker push ${REGISTRY}/$HUELBBASE_VERSION
  104. docker pull ${REGISTRY}/$HUELBBASE_VERSION
  105. }
  106. pull_hueos() {
  107. docker pull ${BASEOS_URL}
  108. FROMOS_URL=$(echo "$BASEOS_URL as base-centos-jdk")
  109. sed -i -e "s#\${BASEOS_URL}#${FROMOS_URL}#g" $BASEHUE_DIR/Dockerfile
  110. }
  111. pull_huelbos() {
  112. docker pull ${BASEOS_URL}
  113. FROMOS_URL=$(echo "$BASEOS_URL as base-centos-jdk")
  114. sed -i -e "s#\${BASEOS_URL}#${FROMOS_URL}#g" $BASEHUELB_DIR/Dockerfile
  115. }
  116. pull_base_images() {
  117. set +e
  118. docker pull ${REGISTRY}/$HUEBASE_VERSION
  119. if [[ $? != 0 ]]; then
  120. pull_hueos
  121. build_huebase
  122. fi
  123. docker tag ${REGISTRY}/$HUEBASE_VERSION $HUEBASE_VERSION
  124. docker pull ${REGISTRY}/$HUELBBASE_VERSION
  125. if [[ $? != 0 ]]; then
  126. pull_huelbos
  127. build_huelbbase
  128. fi
  129. docker tag ${REGISTRY}/$HUELBBASE_VERSION $HUELBBASE_VERSION
  130. set -e
  131. }
  132. compile_hue
  133. find_git_state
  134. pull_base_images
  135. docker_hue_build
  136. docker_huelb_build