瀏覽代碼

HUE-8993 [core] Add supervisor based Hue process management inside docker container

(cherry picked from commit fb6e80d1211b825fc9ca3ec606fd6e2a26f9a5ad)
Prakash Ranade 6 年之前
父節點
當前提交
e4412a982c

+ 55 - 0
tools/container/build.sh

@@ -0,0 +1,55 @@
+#!/bin/bash
+
+set -ex
+
+WORK_DIR=$(dirname $(readlink -f $0))
+HUE_SRC=$(realpath $WORK_DIR/../..)
+BUILD_DIR=$(realpath $HUE_SRC/../containerbuild$GBN)
+HUE_DIR=$WORK_DIR/hue
+APACHE_DIR=$WORK_DIR/huelb
+REGISTRY=${REGISTRY:-"docker.io/hortonworks"}
+
+compile_hue() {
+  mkdir -p $BUILD_DIR
+  cd $HUE_SRC
+  PREFIX=$BUILD_DIR make install
+  cd $BUILD_DIR/hue
+  APPS=$(find apps -maxdepth 2 -name "src" -type d|cut -d"/" -f2|sort| sed 's/[^ ]* */apps\/&/g')
+  ./build/env/bin/python tools/app_reg/app_reg.py --install $APPS --relative-paths
+  bash tools/relocatable.sh
+}
+
+find_git_state() {
+  cd $HUE_SRC
+  export GBRANCH=$(git ls-remote  --get-url)"/commits/"$(git rev-parse --abbrev-ref HEAD)
+  export GSHA=$(git ls-remote  --get-url)"/commit/"$(git rev-list --no-walk HEAD)
+  export VERSION=$(grep "VERSION=" VERSION | cut -d"=" -f2 | cut -d'"' -f2)
+}
+
+docker_hue_build() {
+  cd $HUE_DIR
+  cp -a $BUILD_DIR/hue $HUE_DIR
+  rm -f $HUE_DIR/hue/desktop/conf/*
+  docker build -f $HUE_DIR/Dockerfile -t ${REGISTRY}/hue:$GBN \
+    --build-arg GBN=$GBN \
+    --build-arg GSHA="$GSHA" \
+    --build-arg GBRANCH=$GBRANCH \
+    --build-arg VERSION=$VERSION \
+    .
+}
+
+docker_huelb_build() {
+  cd $APACHE_DIR
+  cp -a $BUILD_DIR/hue/build/static $APACHE_DIR
+  docker build -f $APACHE_DIR/Dockerfile -t ${REGISTRY}/huelb:$GBN \
+    --build-arg GBN=$GBN \
+    --build-arg GSHA="$GSHA" \
+    --build-arg GBRANCH=$GBRANCH \
+    --build-arg VERSION=$VERSION \
+    .
+}
+
+compile_hue
+find_git_state
+docker_hue_build
+docker_huelb_build

+ 103 - 0
tools/container/hue/Dockerfile

@@ -0,0 +1,103 @@
+FROM centos:7
+
+LABEL description="Hue Project https://github.com/cloudera/hue"
+
+ARG GBN
+ARG GSHA
+ARG GBRANCH
+ARG VERSION
+
+# Set the environment variable
+ENV NAME="hue" \
+    HUE_HOME="/opt/hue" \
+    HUE_CONF="/etc/hue" \
+    HUE_BUILDNO=${GBN} \
+    HUE_SHAURL=${GSHA} \
+    HUE_BRANCHURL=${GBRANCH} \
+    HUE_VERSION=${VERSION} \
+    HUE_BIN="/opt/hue/build/env/bin" \
+    PATH=$PATH:$HUE_BIN \
+    SUPERVISOR_VERSION=4.0.2
+
+# Required for building Hue
+#RUN yum install -y \
+#      ant \
+#      curl \
+#      gcc \
+#      gcc-c++ \
+#      git \
+#      java-1.8.0-openjdk-devel \
+#      maven \
+#      make \
+#      mysql-devel \
+#      nc \
+#      sudo \
+#      tar \
+#      vim-enhanced
+#
+
+# Required libraries for running Hue
+RUN yum install -y \
+      asciidoc \
+      bzip2-devel \
+      cyrus-sasl-devel \
+      cyrus-sasl-gssapi \
+      cyrus-sasl-plain \
+      gmp-devel \
+      krb5-devel \
+      krb5-libs \
+      krb5-workstation \
+      libffi-devel \
+      libtidy \
+      libxml2-devel \
+      libxslt-devel \
+      nmap-ncat \
+      ncurses-devel \
+      openldap-devel \
+      openssl-devel \
+      python-devel \
+      python-setuptools \
+      readline-devel \
+      sqlite-devel \
+      sudo \
+      xmlsec1 \
+      zlib-devel
+
+RUN easy_install supervisor
+
+RUN curl -sL https://rpm.nodesource.com/setup_10.x | bash - \
+      && yum install -y nodejs \
+      && yum clean all -y
+
+# kubernetes health check
+COPY healthz.sh /
+
+# create hue user
+RUN groupadd -g 1123 hue && useradd -g 1123 -d ${HUE_HOME} -s /bin/bash -u 1123 hue
+WORKDIR /opt/hue
+COPY hue ${HUE_HOME}
+RUN $HUE_BIN/pip install psycopg2-binary
+RUN chown -R hue:hue ${HUE_HOME} && \
+    mkdir -p /var/log/hue && \
+    chown -R hue:hue /var/log/hue && \
+    mkdir -p ${HUE_CONF} && \
+    chown -R hue:hue ${HUE_CONF}
+
+ENV HUE_CONF_DIR ${HUE_CONF}/conf
+COPY hueconf ${HUE_CONF}/conf
+
+RUN ln -s ${HUE_CONF}/conf/log.conf ${HUE_HOME}/desktop/conf/log.conf; \
+    ln -s ${HUE_CONF}/conf/log4j.properties ${HUE_HOME}/desktop/conf/log4j.properties
+
+COPY hue.sh ${HUE_HOME}/hue.sh
+
+# supervisor stuff
+ADD supervisor-files/etc/supervisord.conf /etc/supervisord.conf
+RUN mkdir -p /etc/supervisor.d/ && chmod +w /etc/supervisor.d
+ADD supervisor-files/hue_server.conf /etc/supervisor.d/
+ADD supervisor-files/hue_ktrenewer.conf /etc/supervisor.d/
+
+EXPOSE 8888 9111
+
+USER hue
+CMD ["/usr/bin/supervisord","-c","/etc/supervisord.conf"]

+ 5 - 0
tools/container/hue/healthz.sh

@@ -0,0 +1,5 @@
+#!/bin/bash
+set -e
+set -x
+
+nc -zv -w 2 127.0.0.1 ${HEALTH_CHECK_PORT}

+ 30 - 0
tools/container/hue/hue.sh

@@ -0,0 +1,30 @@
+#!/bin/bash
+# Copyright (c) 2019 Cloudera, Inc. All rights reserved.
+
+set -x
+
+# Time marker for both stderr and stdout
+date; date 1>&2
+
+export DESKTOP_LOG_DIR="/var/log/hue"
+export PYTHON_EGG_CACHE=$HUE_CONF_DIR/.python-eggs
+export SERVER_SOFTWARE="apache"
+
+function prepare_hue_start() {
+  $HUE_BIN/hue syncdb --noinput
+  $HUE_BIN/hue migrate
+}
+
+if [[ $1 == kt_renewer ]]; then
+  if [ -e "/etc/hue/conf/kerberos.ini" ]; then
+    # The Kerberos ticket renewer role needs to know where kinit is.
+    KINIT_PATH=`which kinit`
+    KINIT_PATH=${KINIT_PATH-/usr/bin/kinit}
+    $HUE_BIN/hue kt_renewer
+  fi
+elif [[ $1 == runcpserver ]]; then
+    prepare_hue_start
+    $HUE_BIN/hue runcherrypyserver
+fi
+
+exit 0

+ 52 - 0
tools/container/hue/hueconf/hue.ini

@@ -0,0 +1,52 @@
+[desktop]
+allowed_hosts="*"
+secret_key_script=/bin/echo cloudera
+cluster_id=d6cb3d9f-953b-46ff-9dc4-ab2a9331f0db
+app_blacklist=filebrowser,oozie,search,hbase,security,metastore,pig,sqoop,spark
+time_zone=America/Los_Angeles
+django_debug_mode=false
+http_500_debug_mode=false
+cherrypy_server_threads=5
+default_site_encoding=utf
+collect_usage=true
+audit_event_log_dir=/etc/hue/conf
+audit_log_max_file_size=100MB
+[[metrics]]
+[[database]]
+[[smtp]]
+host=localhost
+port=25
+user=
+password=
+tls=no
+[[kerberos]]
+[[custom]]
+[[auth]]
+idle_session_timeout=-1
+user_augmentor=desktop.auth.backend.DefaultUserAugmentor
+backend=desktop.auth.backend.AllowFirstUserDjangoBackend
+[liboozie]
+[useradmin]
+[search]
+[proxy]
+[shell]
+[[ shelltypes ]]
+[[[ pig ]]]
+[[[[ environment ]]]]
+[[[[[ JAVA_HOME ]]]]]
+[[[[[ HADOOP_CONF_DIR ]]]]]
+[[[ hbase ]]]
+[[[[ environment ]]]]
+[[[[[ JAVA_HOME ]]]]]
+[[[[[ HADOOP_CONF_DIR ]]]]]
+[[[[[ HBASE_CONF_DIR ]]]]]
+[zookeeper]
+[[clusters]]
+[[[default]]]
+[libzookeeper]
+[hadoop]
+[[hdfs_clusters]]
+[[[default]]]
+fs_defaultfs=hdfs://localhost:8020
+webhdfs_url=http://localhost:20101/webhdfs/v1
+[beeswax]

+ 44 - 0
tools/container/hue/hueconf/log.conf

@@ -0,0 +1,44 @@
+# Just log to stdout for DWX environment
+[logger_root]
+handlers=stdout
+
+[logger_access]
+handlers=stdout
+qualname=access
+
+[logger_django_auth_ldap]
+handlers=stdout
+qualname=django_auth_ldap
+
+[logger_kazoo_client]
+handlers=stdout
+qualname=kazoo.client
+
+[logger_djangosaml2]
+handlers=stdout
+qualname=djangosaml2
+
+[logger_django_db]
+handlers=stdout
+qualname=django.db.backends
+
+# Handlers
+[handler_stdout]
+level=INFO
+class=StreamHandler
+formatter=default
+args=(sys.stdout,)
+
+[formatter_default]
+class=desktop.log.formatter.Formatter
+format=[%(asctime)s] %(module)-12s %(levelname)-8s %(message)s
+datefmt=%d/%b/%Y %H:%M:%S %z
+
+[loggers]
+keys=root,access,django_auth_ldap,kazoo_client,djangosaml2,django_db
+
+[handlers]
+keys=stdout
+
+[formatters]
+keys=default

+ 61 - 0
tools/container/hue/hueconf/log4j.properties

@@ -0,0 +1,61 @@
+# Define some default values that can be overridden by system properties
+hadoop.log.dir=.
+hadoop.log.file=hadoop.log
+
+# Define the root logger to the system property "hadoop.root.logger".
+log4j.rootLogger=INFO,console, EventCounter
+
+# Logging Threshold
+log4j.threshhold=ALL
+
+#
+# Daily Rolling File Appender
+#
+
+log4j.appender.DRFA=org.apache.log4j.DailyRollingFileAppender
+log4j.appender.DRFA.File=${hadoop.log.dir}/${hadoop.log.file}
+
+# Rollver at midnight
+log4j.appender.DRFA.DatePattern=.yyyy-MM-dd
+
+# 30-day backup
+#log4j.appender.DRFA.MaxBackupIndex=30
+log4j.appender.DRFA.layout=org.apache.log4j.PatternLayout
+
+# Pattern format: Date LogLevel LoggerName LogMessage
+log4j.appender.DRFA.layout.ConversionPattern=%d{ISO8601} %p %c: %m%n
+# Debugging Pattern format
+#log4j.appender.DRFA.layout.ConversionPattern=%d{ISO8601} %-5p %c{2} (%F:%M(%L)) - %m%n
+
+
+#
+# console
+# Add "console" to rootlogger above if you want to use this
+#
+
+log4j.appender.console=org.apache.log4j.ConsoleAppender
+log4j.appender.console.target=System.err
+log4j.appender.console.layout=org.apache.log4j.PatternLayout
+log4j.appender.console.layout.ConversionPattern=%d{yy/MM/dd HH:mm:ss} %p %c{2}: %m%n
+
+#
+# Rolling File Appender
+#
+
+#log4j.appender.RFA=org.apache.log4j.RollingFileAppender
+#log4j.appender.RFA.File=${hadoop.log.dir}/${hadoop.log.file}
+
+# Logfile size and and 30-day backups
+#log4j.appender.RFA.MaxFileSize=1MB
+#log4j.appender.RFA.MaxBackupIndex=30
+
+#log4j.appender.RFA.layout=org.apache.log4j.PatternLayout
+#log4j.appender.RFA.layout.ConversionPattern=%d{ISO8601} %-5p %c{2} - %m%n
+#log4j.appender.RFA.layout.ConversionPattern=%d{ISO8601} %-5p %c{2} (%F:%M(%L)) - %m%n
+
+#
+# Event Counter Appender
+# Sends counts of logging messages at different severity levels to Hadoop
+# Metrics.
+#
+log4j.appender.EventCounter=org.apache.hadoop.metrics.jvm.EventCounter

+ 31 - 0
tools/container/hue/supervisor-files/etc/supervisord.conf

@@ -0,0 +1,31 @@
+[unix_http_server]
+file=/var/log/hue/supervisord.sock
+username=6216803864979002924
+password=8373576301055810053
+
+[supervisord]
+pidfile=/var/log/hue/supervisord.pid
+stdout_logfile=/dev/stdout
+stdout_logfile_maxbytes=0
+stderr_logfile=/dev/stderr
+stderr_logfile_maxbytes=0
+loglevel=info
+nodaemon=true
+identifier=agent-6216803864979002924
+
+# These two (unix_http_server, rpcinterface) are needed for supervisorctl to work
+[inet_http_server]
+port=127.0.0.1:9111
+username=6216803864979002924
+password=8373576301055810053
+
+[rpcinterface:supervisor]
+supervisor.rpcinterface_factory=supervisor.rpcinterface:make_main_rpcinterface
+
+[supervisorctl]
+serverurl=http://localhost:9111
+username=6216803864979002924
+password=8373576301055810053
+
+[include]
+files = /etc/supervisor.d/*.conf

+ 18 - 0
tools/container/hue/supervisor-files/hue_ktrenewer.conf

@@ -0,0 +1,18 @@
+[program:hue_ktrenewer]
+command=/opt/hue/hue.sh kt_renewer
+directory=/opt/hue
+autostart=true
+startretries=3
+stdout_logfile=/dev/stdout
+stdout_logfile_maxbytes=0
+stderr_logfile=/dev/stderr
+stderr_logfile_maxbytes=0
+environment=DESKTOP_LOG_DIR="/var/log/hue",PYTHON_EGG_CACHE="$HUE_CONF_DIR/.python-eggs",SERVER_SOFTWARE="apache"
+user=hue
+group=hue
+exitcodes=0,2
+autorestart=false
+startsecs=20
+stopwaitsecs=30
+killasgroup=true
+# rlimits

+ 18 - 0
tools/container/hue/supervisor-files/hue_server.conf

@@ -0,0 +1,18 @@
+[program:hue_server]
+command=/opt/hue/hue.sh runcpserver
+directory=/opt/hue
+autostart=true
+startretries=3
+stdout_logfile=/dev/stdout
+stdout_logfile_maxbytes=0
+stderr_logfile=/dev/stderr
+stderr_logfile_maxbytes=0
+environment=DESKTOP_LOG_DIR="/var/log/hue",PYTHON_EGG_CACHE="$HUE_CONF_DIR/.python-eggs",SERVER_SOFTWARE="apache"
+user=hue
+group=hue
+exitcodes=0,2
+autorestart=false
+startsecs=20
+stopwaitsecs=30
+killasgroup=true
+# rlimits

+ 42 - 0
tools/container/huelb/Dockerfile

@@ -0,0 +1,42 @@
+FROM httpd:2.4
+
+LABEL description="Hue Project https://github.com/cloudera/hue"
+
+ARG GBN
+ARG GSHA
+ARG GBRANCH
+ARG VERSION
+
+# Set the environment variable
+ENV NAME="hue" \
+    HUE_HOME="/opt/hue" \
+    HUE_CONF="/etc/hue" \
+    HUE_BUILDNO=${GBN} \
+    HUE_SHAURL=${GSHA} \
+    HUE_BRANCHURL=${GBRANCH} \
+    HUE_VERSION=${VERSION} \
+    HUE_BIN="/opt/hue/build/env/bin" \
+    PATH=$PATH:$HUE_BIN
+
+RUN apt-get update; \
+    apt-get install -y --no-install-recommends \
+      netcat \
+      ; \
+    rm -r /var/lib/apt/lists/*;
+
+RUN echo "Include /usr/local/apache2/conf/hue_httpd.conf" >> /usr/local/apache2/conf/httpd.conf
+
+RUN groupadd -g 1123 hue && useradd -g 1123 -d ${HUE_HOME} -s /bin/bash -u 1123 hue
+
+COPY static ${HUE_HOME}/build/static
+
+COPY run_httpd.sh ${HUE_HOME}
+COPY healthz.sh /
+
+WORKDIR ${HUE_HOME}
+
+COPY hue_httpd.conf /usr/local/apache2/conf/hue_httpd.conf
+
+EXPOSE 80
+
+CMD ["run_httpd.sh"]

+ 5 - 0
tools/container/huelb/healthz.sh

@@ -0,0 +1,5 @@
+#!/bin/bash
+set -e
+set -x
+
+nc -zv -w 2 127.0.0.1 ${HEALTH_CHECK_PORT}

+ 3 - 0
tools/container/huelb/hue.conf

@@ -0,0 +1,3 @@
+<Proxy balancer://hue>
+  BalancerMember http://172.17.0.2:8888 retry=10 route=HUE-1-HUE_SERVER-6027230c682c63383f2385581e636e54
+</Proxy>

+ 47 - 0
tools/container/huelb/hue_httpd.conf

@@ -0,0 +1,47 @@
+LoadModule proxy_module /usr/local/apache2/modules/mod_proxy.so
+LoadModule proxy_balancer_module /usr/local/apache2/modules/mod_proxy_balancer.so
+LoadModule proxy_http_module /usr/local/apache2/modules/mod_proxy_http.so
+LoadModule slotmem_shm_module /usr/local/apache2/modules/mod_slotmem_shm.so
+LoadModule unixd_module /usr/local/apache2/modules/mod_unixd.so
+LoadModule lbmethod_byrequests_module /usr/local/apache2/modules/mod_lbmethod_byrequests.so
+LoadModule authz_core_module /usr/local/apache2/modules/mod_authz_core.so
+LoadModule log_config_module /usr/local/apache2/modules/mod_log_config.so
+LoadModule mime_module /usr/local/apache2/modules/mod_mime.so
+
+ErrorLog "${HUE_LOG_DIR}/httpd_error_log"
+LogLevel warn
+
+<IfModule log_config_module>
+  LogFormat "%h %l %u %t \"%r\" %>s %b \"%{Referer}i\" \"%{User-Agent}i\"" combined
+  LogFormat "%h %l %u %t \"%r\" %>s %b" common
+  CustomLog "${HUE_LOG_DIR}/httpd_access_log" common
+</IfModule>
+
+<IfModule mime_module>
+  TypesConfig conf/mime.types
+  AddType application/x-compress .Z
+  AddType application/x-gzip .gz .tgz
+</IfModule>
+
+<Directory />
+  Options FollowSymlinks
+  AllowOverride none
+</Directory>
+
+<Directory /opt/hue/build/static>
+  Options -Indexes
+  Require all granted
+</Directory>
+
+Alias /static /opt/hue/build/static
+
+Header add Set-Cookie "ROUTEID=.%{BALANCER_WORKER_ROUTE}e; path=/" env=BALANCER_ROUTE_CHANGED
+ProxyPreserveHost Off
+ProxyPass /static !
+ProxyPass / balancer://hue/ stickysession=ROUTEID
+
+SetEnv proxy-initial-not-pooled 1
+ProxyTimeout 900
+
+AllowEncodedSlashes NoDecode
+Include /usr/local/apache2/conf/hue.conf

+ 11 - 0
tools/container/huelb/run_httpd.sh

@@ -0,0 +1,11 @@
+#!/bin/sh
+
+export HUE_LOG_DIR="/var/log/hue"
+mkdir -p ${HUE_LOG_DIR}
+
+set -e
+
+# Apache gets grumpy about PID files pre-existing
+rm -f /usr/local/apache2/logs/httpd.pid
+
+exec httpd -DFOREGROUND "$@"