Sfoglia il codice sorgente

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

(cherry picked from commit df3cbe027fa53aac0e580cdbac7bd7a4beb95053)
Prakash Ranade 6 anni fa
parent
commit
6dad162a89

+ 11 - 0
tools/container/build.sh

@@ -26,15 +26,26 @@ find_git_state() {
   export VERSION=$(grep "VERSION=" VERSION | cut -d"=" -f2 | cut -d'"' -f2)
 }
 
+generate_random_string() {
+  cd $HUE_DIR
+  thisuser=$(uuidgen | cut -d"-" -f5)
+  thispass=$(uuidgen | cut -d"-" -f5)
+  sed -i -e "s|username=.*|username=${thisuser}|g" supervisor-files/etc/supervisord.conf
+  sed -i -e "s|password=.*|password=${thispass}|g" supervisor-files/etc/supervisord.conf
+}
+
 docker_hue_build() {
   cd $HUE_DIR
+  generate_random_string
   cp -a $BUILD_DIR/hue $HUE_DIR
   rm -f $HUE_DIR/hue/desktop/conf/*
+  export HUEUSER="hive"
   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 \
+    --build-arg HUEUSER="hive" \
     .
 }
 

+ 15 - 12
tools/container/hue/Dockerfile

@@ -6,18 +6,20 @@ ARG GBN
 ARG GSHA
 ARG GBRANCH
 ARG VERSION
+ARG HUEUSER
 
 # Set the environment variable
 ENV NAME="hue" \
-    HUE_HOME="/opt/hue" \
+    HUE_HOME="/opt/${HUEUSER}" \
     HUE_CONF="/etc/hue" \
     HUE_BUILDNO=${GBN} \
     HUE_SHAURL=${GSHA} \
     HUE_BRANCHURL=${GBRANCH} \
     HUE_VERSION=${VERSION} \
-    HUE_BIN="/opt/hue/build/env/bin" \
+    HUE_BIN="/opt/${HUEUSER}/build/env/bin" \
     PATH=$PATH:$HUE_BIN \
-    SUPERVISOR_VERSION=4.0.2
+    SUPERVISOR_VERSION=4.0.2 \
+    HUE_USER=${HUEUSER}
 
 # Required for building Hue
 #RUN yum install -y \
@@ -73,15 +75,18 @@ RUN curl -sL https://rpm.nodesource.com/setup_10.x | bash - \
 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
+RUN groupadd -g 1123 ${HUE_USER} && useradd -g 1123 -d ${HUE_HOME} -s /bin/bash -u 1123 ${HUE_USER}
+WORKDIR /opt/${HUE_USER}
 COPY hue ${HUE_HOME}
+COPY hue.sh ${HUE_HOME}/hue.sh
 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 && \
+RUN chown -R ${HUE_USER}:${HUE_USER} ${HUE_HOME} && \
+    mkdir -p /var/log/${HUE_USER} && \
+    chown -R ${HUE_USER}:${HUE_USER} /var/log/${HUE_USER} && \
     mkdir -p ${HUE_CONF} && \
-    chown -R hue:hue ${HUE_CONF}
+    chown -R ${HUE_USER}:${HUE_USER} ${HUE_CONF} && \
+    echo "${HUE_USER} ALL=(root) NOPASSWD:ALL" > /etc/sudoers.d/${HUE_USER} && \
+    chmod 0440 /etc/sudoers.d/${HUE_USER}
 
 ENV HUE_CONF_DIR ${HUE_CONF}/conf
 COPY hueconf ${HUE_CONF}/conf
@@ -89,8 +94,6 @@ 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
@@ -99,5 +102,5 @@ ADD supervisor-files/hue_ktrenewer.conf /etc/supervisor.d/
 
 EXPOSE 8888 9111
 
-USER hue
+USER ${HUE_USER}
 CMD ["/usr/bin/supervisord","-c","/etc/supervisord.conf"]

+ 1 - 1
tools/container/hue/hue.sh

@@ -6,7 +6,7 @@ set -x
 # Time marker for both stderr and stdout
 date; date 1>&2
 
-export DESKTOP_LOG_DIR="/var/log/hue"
+export DESKTOP_LOG_DIR="/var/log/hive"
 export PYTHON_EGG_CACHE=$HUE_CONF_DIR/.python-eggs
 export SERVER_SOFTWARE="apache"
 

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

@@ -1,31 +1,31 @@
 [unix_http_server]
-file=/var/log/hue/supervisord.sock
-username=6216803864979002924
-password=8373576301055810053
+file=/var/log/hive/supervisord.sock
+username=57c4015687d4
+password=cf065b403d9c
 
 [supervisord]
-pidfile=/var/log/hue/supervisord.pid
+pidfile=/var/log/hive/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
+identifier=agent-57c4015687d4
 
 # 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
+username=57c4015687d4
+password=cf065b403d9c
 
 [rpcinterface:supervisor]
 supervisor.rpcinterface_factory=supervisor.rpcinterface:make_main_rpcinterface
 
 [supervisorctl]
 serverurl=http://localhost:9111
-username=6216803864979002924
-password=8373576301055810053
+username=57c4015687d4
+password=cf065b403d9c
 
 [include]
 files = /etc/supervisor.d/*.conf

+ 5 - 5
tools/container/hue/supervisor-files/hue_ktrenewer.conf

@@ -1,15 +1,15 @@
 [program:hue_ktrenewer]
-command=/opt/hue/hue.sh kt_renewer
-directory=/opt/hue
+command=/opt/hive/hue.sh kt_renewer
+directory=/opt/hive
 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
+environment=DESKTOP_LOG_DIR="/var/log/hive",PYTHON_EGG_CACHE="$HUE_CONF_DIR/.python-eggs",SERVER_SOFTWARE="apache"
+user=hive
+group=hive
 exitcodes=0,2
 autorestart=false
 startsecs=20

+ 5 - 5
tools/container/hue/supervisor-files/hue_server.conf

@@ -1,15 +1,15 @@
 [program:hue_server]
-command=/opt/hue/hue.sh runcpserver
-directory=/opt/hue
+command=/opt/hive/hue.sh runcpserver
+directory=/opt/hive
 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
+environment=DESKTOP_LOG_DIR="/var/log/hive",PYTHON_EGG_CACHE="$HUE_CONF_DIR/.python-eggs",SERVER_SOFTWARE="apache"
+user=hive
+group=hive
 exitcodes=0,2
 autorestart=false
 startsecs=20