Using supervisor

This commit is contained in:
butomo1989 2017-02-11 22:46:41 +01:00
parent 06770df1db
commit 78cae6a79c
3 changed files with 53 additions and 21 deletions

View file

@ -17,11 +17,20 @@ RUN apt-get install xvfb x11vnc -y
#========================================================= #=========================================================
RUN apt-get install openbox menu python-numpy net-tools -y RUN apt-get install openbox menu python-numpy net-tools -y
#====================
# Install Supervisor
#====================
RUN apt-get install supervisor -y
#=============
# Set WORKDIR
#=============
WORKDIR /root
#====================== #======================
# Clone noVNC projects # Clone noVNC projects
#====================== #======================
RUN apt-get install git -y RUN apt-get install git -y
WORKDIR /root
RUN git clone https://github.com/kanaka/noVNC.git && \ RUN git clone https://github.com/kanaka/noVNC.git && \
cd noVNC/utils && git clone https://github.com/kanaka/websockify websockify cd noVNC/utils && git clone https://github.com/kanaka/websockify websockify
@ -65,9 +74,10 @@ RUN npm install -g appium@$APPIUM_VERSION
#============================================================ #============================================================
RUN apt-get install qemu-kvm libvirt-bin ubuntu-vm-builder bridge-utils -y RUN apt-get install qemu-kvm libvirt-bin ubuntu-vm-builder bridge-utils -y
#====================== #================================================
# noVNC Configurations # noVNC Default Configurations
#====================== # These Configurations can be changed through -e
#================================================
ENV DISPLAY=:0 \ ENV DISPLAY=:0 \
SCREEN=0 \ SCREEN=0 \
SCREEN_WIDTH=1600 \ SCREEN_WIDTH=1600 \
@ -75,7 +85,8 @@ ENV DISPLAY=:0 \
SCREEN_DEPTH=16 \ SCREEN_DEPTH=16 \
LOCAL_PORT=5900 \ LOCAL_PORT=5900 \
TARGET_PORT=6080 \ TARGET_PORT=6080 \
TIMEOUT=1 TIMEOUT=1 \
LOG_PATH=/var/log/supervisor
RUN ln -s noVNC/vnc_auto.html noVNC/index.html RUN ln -s noVNC/vnc_auto.html noVNC/index.html
#============== #==============
@ -84,13 +95,14 @@ RUN ln -s noVNC/vnc_auto.html noVNC/index.html
EXPOSE 4723 EXPOSE 4723
EXPOSE 6080 EXPOSE 6080
#================= #==================
# Add Browser Apk # Add Browser APKs
#================= #==================
COPY example/browser_apk /root/browser_apk COPY example/browser_apk /root/browser_apk
#=================== #===================
# Run docker-appium # Run docker-appium
#=================== #===================
COPY supervisord.conf /root/
COPY service /root/service COPY service /root/service
CMD python -m service.start CMD /usr/bin/supervisord --configuration supervisord.conf

View file

@ -34,14 +34,6 @@ def run():
subprocess.check_call('ln -s $ANDROID_HOME/tools/{shortcut_file} $ANDROID_HOME/tools/emulator'.format( subprocess.check_call('ln -s $ANDROID_HOME/tools/{shortcut_file} $ANDROID_HOME/tools/emulator'.format(
shortcut_file='emulator64-x86' if emulator_type == TYPE_X86 else 'emulator64-arm'), shell=True) shortcut_file='emulator64-x86' if emulator_type == TYPE_X86 else 'emulator64-arm'), shell=True)
# Start Xvfb
subprocess.check_call('Xvfb ${DISPLAY} -screen ${SCREEN} ${SCREEN_WIDTH}x${SCREEN_HEIGHT}x${SCREEN_DEPTH} & '
'sleep ${TIMEOUT}', shell=True)
# Start noVNC
vnc_cmd = 'openbox-session & x11vnc -display ${DISPLAY} -nopw -ncache 10 -forever & ' \
'./noVNC/utils/launch.sh --vnc localhost:${LOCAL_PORT} --listen ${TARGET_PORT}'
# Option to connect with selenium server # Option to connect with selenium server
connect_to_grid = str_to_bool(str(os.getenv('CONNECT_TO_GRID', False))) connect_to_grid = str_to_bool(str(os.getenv('CONNECT_TO_GRID', False)))
logger.info('Connect with selenium grid? {input}'.format(input=connect_to_grid)) logger.info('Connect with selenium grid? {input}'.format(input=connect_to_grid))
@ -61,12 +53,11 @@ def run():
# Start installation of android packages, emulator creation and appium in a terminal # Start installation of android packages, emulator creation and appium in a terminal
android_cmd = get_android_bash_commands(android_version, emulator_type) android_cmd = get_android_bash_commands(android_version, emulator_type)
if android_cmd: if android_cmd:
cmd = '({vnc}) & (xterm -T "Android-Appium" -n "Android-Appium" -e \"{android} && ' \ cmd = 'xterm -T "Android-Appium" -n "Android-Appium" -e \"{android} && ' \
'/bin/echo $EMULATOR_NAME && {appium}\")'.format( '/bin/echo $EMULATOR_NAME && {appium}\"'.format(android=android_cmd, appium=appium_cmd)
vnc=vnc_cmd, android=android_cmd, appium=appium_cmd)
else: else:
logger.warning('There is no android packages installed!') logger.warning('There is no android packages installed!')
cmd = '({vnc}) & (xterm -e \"{appium}\")'.format(vnc=vnc_cmd, appium=appium_cmd) cmd = 'xterm -e \"{appium}\"'.format(appium=appium_cmd)
subprocess.check_call(cmd, shell=True) subprocess.check_call(cmd, shell=True)

29
supervisord.conf Normal file
View file

@ -0,0 +1,29 @@
[supervisord]
nodaemon=true
logfile=%(ENV_LOG_PATH)s/supervisord.log
childlogdir=%(ENV_LOG_PATH)s
[program:xvfb]
command=/usr/bin/Xvfb %(ENV_DISPLAY)s -screen %(ENV_SCREEN)s %(ENV_SCREEN_WIDTH)sx%(ENV_SCREEN_HEIGHT)sx%(ENV_SCREEN_DEPTH)s
stdout_logfile=%(ENV_LOG_PATH)s/xvfb.stdout.log
stderr_logfile=%(ENV_LOG_PATH)s/xvfb.stderr.log
[program:openbox]
command=/usr/bin/openbox-session
stdout_logfile=%(ENV_LOG_PATH)s/openbox.stdout.log
stderr_logfile=%(ENV_LOG_PATH)s/openbox.stderr.log
[program:x11vnc]
command=/usr/bin/x11vnc -display %(ENV_DISPLAY)s -nopw -ncache 10 -forever
stdout_logfile=%(ENV_LOG_PATH)s/x11vnc.stdout.log
stderr_logfile=%(ENV_LOG_PATH)s/x11vnc.stderr.log
[program:novnc]
command=./noVNC/utils/launch.sh --vnc localhost:%(ENV_LOCAL_PORT)s --listen %(ENV_TARGET_PORT)s
stdout_logfile=%(ENV_LOG_PATH)s/novnc.stdout.log
stderr_logfile=%(ENV_LOG_PATH)s/novnc.stderr.log
[program:docker-appium]
command=python -m service.start
stdout_logfile=%(ENV_LOG_PATH)s/docker-appium.stdout.log
stderr_logfile=%(ENV_LOG_PATH)s/docker-appium.stderr.log