From 6641723edd65d281946f725ff5419aeb88afda82 Mon Sep 17 00:00:00 2001 From: LAMY Julien Date: Tue, 10 Dec 2019 15:09:37 +0100 Subject: [PATCH] Add browsermob-proxy in run supervisor (#362) * Add browsermob-proxy in run supervisor * Delete browsermob proxy jar file and replaced by http get --- .gitignore | 2 + Dockerfile | 18 +++++++ browsermobproxy/bin/browsermob-proxy | 30 +++++++++++ .../supervisor/conf.d/browsermobproxy.conf | 52 +++++++++++++++++++ 4 files changed, 102 insertions(+) create mode 100755 browsermobproxy/bin/browsermob-proxy create mode 100644 browsermobproxy/etc/supervisor/conf.d/browsermobproxy.conf diff --git a/.gitignore b/.gitignore index 109233ec..c8dbc605 100644 --- a/.gitignore +++ b/.gitignore @@ -31,3 +31,5 @@ temp.md git_shortlog.stdout .bitballoon .idea +*.DS_Store +*.iml diff --git a/Dockerfile b/Dockerfile index f3293816..2539672c 100644 --- a/Dockerfile +++ b/Dockerfile @@ -688,6 +688,7 @@ ENV FIREFOX_VERSION="${FF_VER}" \ HOME="/home/seluser" \ VNC_STORE_PWD_FILE="/home/seluser/.vnc/passwd" \ BIN_UTILS="/usr/bin" \ + LIB_UTILS="/usr/lib" \ MEM_JAVA_PERCENT=80 \ WAIT_FOREGROUND_RETRY="2s" \ WAIT_VNC_FOREGROUND_RETRY="6s" \ @@ -740,6 +741,7 @@ ENV FIREFOX_VERSION="${FF_VER}" \ NOVNC_PORT="${DEFAULT_NOVNC_PORT}" \ NOVNC="false" \ NOVNC_WAIT_TIMEOUT="5s" \ + BROWSERMOBPROXY_START="false" \ SUPERVISOR_HTTP_PORT="${DEFAULT_SUPERVISOR_HTTP_PORT}" \ SUPERVISOR_HTTP_USERNAME="supervisorweb" \ SUPERVISOR_HTTP_PASSWORD="somehttpbasicauthpwd" \ @@ -799,6 +801,7 @@ ENV FIREFOX_VERSION="${FF_VER}" \ VNC_STOP_SIGNAL="TERM" \ NOVNC_STOP_SIGNAL="TERM" \ VIDEO_REC_STOP_SIGNAL="INT" \ + BROWSERMOBPROXY_STOP_SIGNAL="TERM" \ DOCKER_SOCK="/var/run/docker.sock" \ TEST_SLEEPS="0.1" \ ZALENIUM="false" \ @@ -848,6 +851,21 @@ ENV SUPERVISOR_PIDFILE="${RUN_DIR}/supervisord.pid" \ VNC_TRYOUT_ERR_LOG="${LOGS_DIR}/vnc-tryouts-stderr" \ VNC_TRYOUT_OUT_LOG="${LOGS_DIR}/vnc-tryouts-stdout" +# Include Lib Browsermob Proxy +USER root + +ENV BROWSERMOBPROXY_VER=2.1.4 +ENV BROWSERMOBPROXY_FOLDER=browsermob-proxy-${BROWSERMOBPROXY_VER} + +RUN wget -nv -O browsermob-proxy.zip \ + "https://github.com/lightbody/browsermob-proxy/releases/download/browsermob-proxy-${BROWSERMOBPROXY_VER}/browsermob-proxy-${BROWSERMOBPROXY_VER}-bin.zip" \ + && unzip -x browsermob-proxy.zip \ + && rm browsermob-proxy.zip \ + && mv ${BROWSERMOBPROXY_FOLDER}/lib/browsermob-dist-${BROWSERMOBPROXY_VER}.jar ${LIB_UTILS}/ \ + && rm -r ${BROWSERMOBPROXY_FOLDER} + +USER seluser + #=================================== # Fix dirs (again) and final chores #=================================== diff --git a/browsermobproxy/bin/browsermob-proxy b/browsermobproxy/bin/browsermob-proxy new file mode 100755 index 00000000..6bf053c6 --- /dev/null +++ b/browsermobproxy/bin/browsermob-proxy @@ -0,0 +1,30 @@ +#!/bin/sh + +BASEDIR=`dirname $0`/.. +BASEDIR=`(cd "$BASEDIR"; pwd)` + +# if user has not explicitly set a command to use to invoke java, use 'java' and assume it is on the path +if [ -z "$JAVACMD" ] +then + JAVACMD="java" +fi + +"$JAVACMD" $JAVA_OPTS \ + -Dapp.name="browsermob-proxy" \ + -Dbasedir="$BASEDIR" \ + -jar "$BASEDIR/lib/browsermob-dist-2.1.4.jar" \ + --port ${ENV_BROWSERMOBPROXY_PORT:-8080} + "$@" + +# if we couldn't find java, print a helpful error message +if [ $? -eq 127 ] +then + echo + echo "Unable to run java using command: $JAVACMD" + echo "Make sure java is installed and on the path, or set JAVACMD to the java executable before running this script." + echo + echo "Example:" + echo + echo " $ JAVACMD=/var/lib/jdk/bin/java ./browsermob-proxy" + echo +fi diff --git a/browsermobproxy/etc/supervisor/conf.d/browsermobproxy.conf b/browsermobproxy/etc/supervisor/conf.d/browsermobproxy.conf new file mode 100644 index 00000000..4f4faccb --- /dev/null +++ b/browsermobproxy/etc/supervisor/conf.d/browsermobproxy.conf @@ -0,0 +1,52 @@ +[program:browsermobproxy] + +;The relative priority of the program in the start and shutdown ordering. +;Lower priorities indicate programs that start first and shut down last. +priority=95 + +;User to run-as, note environment expansion outside of `command` is only +;supported in supervisor >= 3.2 +;user=seluser + +;The command that will be run when this program is started. +;Controlled programs should themselves not be daemons, as supervisord +;assumes it is responsible for daemonizing its subprocesses +directory=/home/seluser +command=%(ENV_BIN_UTILS)s/browsermob-proxy + +;If true, this program will start automatically when supervisord is started. +;default=true +autostart=%(ENV_BROWSERMOBPROXY_START)s + +;If false, the process will never be autorestarted. +;If true, the process will be unconditionally restarted when it exits, +;without regard to its exit code. default=unexpected +;If unexpected, the process will be restart when the program exits with an +;exit code that is not one of the exit codes associated with this process. +autorestart=unexpected + +;Set to 0 to indicate that the program needn’t stay running for any +;particular amount of time. +;So using custom wait-xxxx.sh scripts to perform a more efficient +;active waiting until https://github.com/Supervisor/supervisor/issues/584 +startsecs=2 + +;The number of serial failure attempts that supervisord will allow when +;attempting to start the program before giving up and puting the process +;into an FATAL state. +startretries=3 + +;Logs +redirect_stderr=false +stdout_logfile=%(ENV_LOGS_DIR)s/browsermobproxy-stdout.log +stderr_logfile=%(ENV_LOGS_DIR)s/browsermobproxy-stderr.log +stdout_logfile_maxbytes=%(ENV_LOGFILE_MAXBYTES)s +stderr_logfile_maxbytes=%(ENV_LOGFILE_MAXBYTES)s +stdout_logfile_backups=%(ENV_LOGFILE_BACKUPS)s +stderr_logfile_backups=%(ENV_LOGFILE_BACKUPS)s +stdout_capture_maxbytes=%(ENV_LOGFILE_MAXBYTES)s +stderr_capture_maxbytes=%(ENV_LOGFILE_MAXBYTES)s + +;The signal used to kill the program when a stop is requested. This can be +;any of TERM, HUP, INT, QUIT, KILL, USR1, or USR2. default=TERM +stopsignal=%(ENV_BROWSERMOBPROXY_STOP_SIGNAL)s