Browse Source

HUE-9092 [core] Fix Hue ProgrammingError at /hue/accounts/login when opening first time when db connectivity is down

(cherry picked from commit 20b605853568e99aa94e3bda7b3bd506e2e5fa2c)
Prakash Ranade 6 years ago
parent
commit
fe52c11488

+ 3 - 1
tools/container/base/hue/Dockerfile

@@ -1,4 +1,4 @@
-FROM centos:7
+FROM ${BASEOS_URL}
 
 
 LABEL description="Hue Project https://github.com/cloudera/hue"
 LABEL description="Hue Project https://github.com/cloudera/hue"
 
 
@@ -43,6 +43,8 @@ RUN set -eux; \
         ncurses-devel \
         ncurses-devel \
         openldap-devel \
         openldap-devel \
         openssl-devel \
         openssl-devel \
+        postgresql \
+        postgresql-libs \
         python-devel \
         python-devel \
         python-setuptools \
         python-setuptools \
         readline-devel \
         readline-devel \

+ 1 - 1
tools/container/base/huelb/Dockerfile

@@ -1,4 +1,4 @@
-FROM centos:7
+FROM ${BASEOS_URL}
 
 
 LABEL description="Hue Project https://github.com/cloudera/hue"
 LABEL description="Hue Project https://github.com/cloudera/hue"
 
 

+ 42 - 13
tools/container/build.sh

@@ -9,9 +9,19 @@ HUE_DIR=$WORK_DIR/hue
 APACHE_DIR=$WORK_DIR/huelb
 APACHE_DIR=$WORK_DIR/huelb
 BASEHUE_DIR=$WORK_DIR/base/hue
 BASEHUE_DIR=$WORK_DIR/base/hue
 BASEHUELB_DIR=$WORK_DIR/base/huelb
 BASEHUELB_DIR=$WORK_DIR/base/huelb
-REGISTRY=${REGISTRY:-"docker.io/hortonworks"}
+HUEBASE_VERSION=huebase_centos:7.6
+HUELBBASE_VERSION=huelb_httpd:2.4.7.6
 HUEUSER="hive"
 HUEUSER="hive"
 
 
+if [ -z "$REGISTRY" ]; then
+  REGISTRY=${REGISTRY:-"docker.io/hortonworks"}
+  BASEOS_URL=${REGISTRY:-"docker.io/centos:centos7"}
+else
+  if [[ $REGISTRY == *cdh ]]; then
+    BASEOS_URL=$(echo $(echo $REGISTRY | cut -d '/' -f 1)/cloudera_base/centos:7.6.1810)
+  fi
+fi
+
 compile_hue() {
 compile_hue() {
   mkdir -p $BUILD_DIR
   mkdir -p $BUILD_DIR
   cd $HUE_SRC
   cd $HUE_SRC
@@ -95,33 +105,52 @@ docker_huelb_build() {
 
 
 build_huebase() {
 build_huebase() {
   cd $BASEHUE_DIR
   cd $BASEHUE_DIR
-  docker build -f $BASEHUE_DIR/Dockerfile -t ${REGISTRY}/huebase_centos:7 .
-  docker tag ${REGISTRY}/huebase_centos:7 huebase_centos:7
-  docker push ${REGISTRY}/huebase_centos:7
-  docker pull ${REGISTRY}/huebase_centos:7
+  docker build -f $BASEHUE_DIR/Dockerfile -t ${REGISTRY}/$HUEBASE_VERSION .
+  docker tag ${REGISTRY}/$HUEBASE_VERSION $HUEBASE_VERSION
+  docker push ${REGISTRY}/$HUEBASE_VERSION
+  docker pull ${REGISTRY}/$HUEBASE_VERSION
 }
 }
 
 
 build_huelbbase() {
 build_huelbbase() {
   cd $BASEHUELB_DIR
   cd $BASEHUELB_DIR
-  docker build -f $BASEHUELB_DIR/Dockerfile -t ${REGISTRY}/huelb_httpd:2.4 .
-  docker tag ${REGISTRY}/huelb_httpd:2.4 huelb_httpd:2.4
-  docker push ${REGISTRY}/huelb_httpd:2.4
-  docker pull ${REGISTRY}/huelb_httpd:2.4
+  docker build -f $BASEHUELB_DIR/Dockerfile -t ${REGISTRY}/$HUELBBASE_VERSION .
+  docker tag ${REGISTRY}/$HUELBBASE_VERSION $HUELBBASE_VERSION
+  docker push ${REGISTRY}/$HUELBBASE_VERSION
+  docker pull ${REGISTRY}/$HUELBBASE_VERSION
+}
+
+pull_hueos() {
+  docker pull ${BASEOS_URL}
+
+  FROMOS_URL=$(echo "$BASEOS_URL as base-centos-jdk")
+  sed -i -e "s#\${BASEOS_URL}#${FROMOS_URL}#g" $BASEHUE_DIR/Dockerfile
+}
+
+pull_huelbos() {
+  docker pull ${BASEOS_URL}
+
+  FROMOS_URL=$(echo "$BASEOS_URL as base-centos-jdk")
+  sed -i -e "s#\${BASEOS_URL}#${FROMOS_URL}#g" $BASEHUELB_DIR/Dockerfile
 }
 }
 
 
 pull_base_images() {
 pull_base_images() {
   set +e
   set +e
-  docker pull ${REGISTRY}/huebase_centos:7
+
+  docker pull ${REGISTRY}/$HUEBASE_VERSION
   if [[ $? != 0 ]]; then
   if [[ $? != 0 ]]; then
+    pull_hueos
+    sed -i -e "s#\${HUEBASE_VERSION}#${HUEBASE_VERSION}#g" $BASEHUE_DIR/Dockerfile
     build_huebase
     build_huebase
   fi
   fi
-  docker tag ${REGISTRY}/huebase_centos:7 huebase_centos:7
+  docker tag ${REGISTRY}/$HUEBASE_VERSION $HUEBASE_VERSION
 
 
-  docker pull ${REGISTRY}/huelb_httpd:2.4
+  docker pull ${REGISTRY}/$HUELBBASE_VERSION
   if [[ $? != 0 ]]; then
   if [[ $? != 0 ]]; then
+    pull_huelbos
+    sed -i -e "s#\${HUELBBASE_VERSION}#${HUELBBASE_VERSION}#g" $BASEHUELB_DIR/Dockerfile
     build_huelbbase
     build_huelbbase
   fi
   fi
-  docker tag ${REGISTRY}/huelb_httpd:2.4 huelb_httpd:2.4
+  docker tag ${REGISTRY}/$HUELBBASE_VERSION $HUELBBASE_VERSION
   set -e
   set -e
 }
 }
 
 

+ 1 - 1
tools/container/hue/Dockerfile

@@ -1,4 +1,4 @@
-FROM huebase_centos:7
+FROM ${HUEBASE_VERSION}
 
 
 LABEL description="Hue Project https://github.com/cloudera/hue"
 LABEL description="Hue Project https://github.com/cloudera/hue"
 
 

+ 35 - 2
tools/container/hue/hue.sh

@@ -10,11 +10,45 @@ export DESKTOP_LOG_DIR="/var/log/hive"
 export PYTHON_EGG_CACHE=$HUE_CONF_DIR/.python-eggs
 export PYTHON_EGG_CACHE=$HUE_CONF_DIR/.python-eggs
 export SERVER_SOFTWARE="apache"
 export SERVER_SOFTWARE="apache"
 
 
-function prepare_hue_start() {
+function prepare_huedb() {
   $HUE_BIN/hue syncdb --noinput
   $HUE_BIN/hue syncdb --noinput
+  $HUE_BIN/hue makemigrations --noinput --merge
   $HUE_BIN/hue migrate
   $HUE_BIN/hue migrate
 }
 }
 
 
+function db_connectivity_check() {
+  i="0"
+  ret="fail"
+
+  # perform db connectivity check for 5 times
+  while [[ $i -lt 5 ]]; do
+    echo "Running db connectivity check"
+
+    status=$(echo quit|$HUE_BIN/hue dbshell 2>&1|wc -l)
+    # check if db connection is successful
+    if [[ $status -gt 1 ]]; then
+      ret="success"
+      break
+    fi
+
+    sleep 1
+    i=$[$i+1]
+
+    echo "Failing db connectivity check: $i"
+  done
+
+  echo "$ret"
+}
+
+# If database connectivity is not set then fail
+ret=$(db_connectivity_check)
+if [[ $ret == "fail" ]];  then
+  exit 1
+fi
+
+# prepare db schema
+prepare_huedb
+
 if [[ $1 == kt_renewer ]]; then
 if [[ $1 == kt_renewer ]]; then
   if [ -e "/etc/hue/conf/kerberos.ini" ]; then
   if [ -e "/etc/hue/conf/kerberos.ini" ]; then
     # The Kerberos ticket renewer role needs to know where kinit is.
     # The Kerberos ticket renewer role needs to know where kinit is.
@@ -23,7 +57,6 @@ if [[ $1 == kt_renewer ]]; then
     $HUE_BIN/hue kt_renewer
     $HUE_BIN/hue kt_renewer
   fi
   fi
 elif [[ $1 == runcpserver ]]; then
 elif [[ $1 == runcpserver ]]; then
-    prepare_hue_start
     $HUE_BIN/hue runcherrypyserver
     $HUE_BIN/hue runcherrypyserver
 fi
 fi
 
 

+ 1 - 1
tools/container/huelb/Dockerfile

@@ -1,4 +1,4 @@
-FROM huelb_httpd:2.4
+FROM ${HUELBBASE_VERSION}
 
 
 LABEL description="Hue Project https://github.com/cloudera/hue"
 LABEL description="Hue Project https://github.com/cloudera/hue"