Skip to content

Commit

Permalink
Add debug images with VNC server
Browse files Browse the repository at this point in the history
These debug images are not meant to be included in the official docker
supported debug solution, they are merely a stop gap till #2 is
resolved.

Part of #3
  • Loading branch information
mtscout6 committed Nov 20, 2014
1 parent 41b5b4b commit 5eb0ab8
Show file tree
Hide file tree
Showing 12 changed files with 301 additions and 12 deletions.
3 changes: 2 additions & 1 deletion Base/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -30,4 +30,5 @@ RUN mkdir -p /opt/selenium \
#========================================
RUN sudo useradd seluser --shell /bin/bash --create-home \
&& sudo usermod -a -G sudo seluser \
&& echo 'ALL ALL = (ALL) NOPASSWD: ALL' >> /etc/sudoers
&& echo 'ALL ALL = (ALL) NOPASSWD: ALL' >> /etc/sudoers \
&& echo 'seluser:secret' | chpasswd
19 changes: 17 additions & 2 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ NAME := selenium
VERSION := $(or $(VERSION),$(VERSION),'2.44.0')
PLATFORM := $(shell uname -s)

all: hub chrome firefox
all: hub chrome firefox chromedebug firefoxdebug

build: all

Expand All @@ -23,6 +23,18 @@ chrome: nodebase
firefox: nodebase
cd ./NodeFirefox && docker build -t $(NAME)/node-firefox:$(VERSION) .

generate_chromedebug:
cd ./NodeDebug && ./generate.sh NodeChromeDebug node-chrome $(VERSION)

chromedebug: generate_chromedebug chrome
cd ./NodeChromeDebug && docker build -t $(NAME)/node-chrome-debug:$(VERSION) .

generate_firefoxdebug:
cd ./NodeDebug && ./generate.sh NodeFirefoxDebug node-firefox $(VERSION)

firefoxdebug: generate_firefoxdebug firefox
cd ./NodeFirefoxDebug && docker build -t $(NAME)/node-firefox-debug:$(VERSION) .

tag_latest:
docker tag $(NAME)/base:$(VERSION) $(NAME)/base:latest
docker tag $(NAME)/hub:$(VERSION) $(NAME)/hub:latest
Expand All @@ -45,5 +57,8 @@ release: tag_latest

test:
./test.sh
./test.sh debug

.PHONY: all base hub nodebase chrome firefox full tag_latest release build test
.PHONY: all build ci base hub nodebase chrome firefox \
generate_chromedebug chromedebug generate_firefoxdebug firefoxdebug \
tag_latest release test
2 changes: 1 addition & 1 deletion NodeBase/entry_point.sh
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ fi

# TODO: Look into http://www.seleniumhq.org/docs/05_selenium_rc.jsp#browser-side-logs

exec xvfb-run --server-args="$DISPLAY -screen 0 $GEOMETRY -ac +extension RANDR" \
xvfb-run --server-args="$DISPLAY -screen 0 $GEOMETRY -ac +extension RANDR" \
java -jar /opt/selenium/selenium-server-standalone.jar \
-role node \
-hub http://hub:4444/grid/register \
Expand Down
56 changes: 56 additions & 0 deletions NodeChromeDebug/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
FROM selenium/node-chrome:2.44.0
#FROM selenium/node-*:2.44.0 Proper FROM attr will be applied throuh generate.sh
MAINTAINER Selenium <[email protected]>

USER root

#=====
# VNC
#=====
RUN apt-get update -qqy \
&& apt-get -qqy install \
x11vnc \
&& rm -rf /var/lib/apt/lists/* \
&& mkdir -p ~/.vnc \
&& x11vnc -storepasswd secret ~/.vnc/passwd

#=================
# Locale settings
#=================
ENV LANGUAGE en_US.UTF-8
ENV LANG en_US.UTF-8
RUN locale-gen en_US.UTF-8 \
&& dpkg-reconfigure --frontend noninteractive locales \
&& apt-get update -qqy \
&& apt-get -qqy --no-install-recommends install \
language-pack-en \
&& rm -rf /var/lib/apt/lists/*

#=======
# Fonts
#=======
RUN apt-get update -qqy \
&& apt-get -qqy --no-install-recommends install \
fonts-ipafont-gothic \
xfonts-100dpi \
xfonts-75dpi \
xfonts-cyrillic \
xfonts-scalable \
&& rm -rf /var/lib/apt/lists/*

#=========
# fluxbox
# A fast, lightweight and responsive window manager
#=========
RUN apt-get update -qqy \
&& apt-get -qqy install \
fluxbox \
&& rm -rf /var/lib/apt/lists/*

#==============================
# Scripts to run Selenium Node
#==============================
COPY entry_point.sh /opt/bin/entry_point.sh
RUN chmod +x /opt/bin/entry_point.sh

EXPOSE 5900
28 changes: 28 additions & 0 deletions NodeChromeDebug/entry_point.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
#!/bin/bash
export GEOMETRY="$SCREEN_WIDTH""x""$SCREEN_HEIGHT""x""$SCREEN_DEPTH"

if [ ! -e /opt/selenium/config.json ]; then
echo No Selenium Node configuration file, the node-base image is not intended to be run directly. 1>&2
exit 1
fi

if [ -z "$HUB_PORT_4444_TCP_ADDR" ]; then
echo Not linked with a running Hub container 1>&2
exit 1
fi

# TODO: Look into http://www.seleniumhq.org/docs/05_selenium_rc.jsp#browser-side-logs

sudo -E -i -u seluser \
DISPLAY=$DISPLAY \
xvfb-run --server-args="$DISPLAY -screen 0 $GEOMETRY -ac +extension RANDR" \
java -jar /opt/selenium/selenium-server-standalone.jar \
-role node \
-hub http://hub:4444/grid/register \
-nodeConfig /opt/selenium/config.json \
| tee "/tmp/sel-node.log" &
sleep 0.5

fluxbox -display $DISPLAY &

x11vnc -forever -usepw -shared -rfbport 5900 -display $DISPLAY
55 changes: 55 additions & 0 deletions NodeDebug/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
#FROM selenium/node-*:2.44.0 Proper FROM attr will be applied throuh generate.sh
MAINTAINER Selenium <[email protected]>

USER root

#=====
# VNC
#=====
RUN apt-get update -qqy \
&& apt-get -qqy install \
x11vnc \
&& rm -rf /var/lib/apt/lists/* \
&& mkdir -p ~/.vnc \
&& x11vnc -storepasswd secret ~/.vnc/passwd

#=================
# Locale settings
#=================
ENV LANGUAGE en_US.UTF-8
ENV LANG en_US.UTF-8
RUN locale-gen en_US.UTF-8 \
&& dpkg-reconfigure --frontend noninteractive locales \
&& apt-get update -qqy \
&& apt-get -qqy --no-install-recommends install \
language-pack-en \
&& rm -rf /var/lib/apt/lists/*

#=======
# Fonts
#=======
RUN apt-get update -qqy \
&& apt-get -qqy --no-install-recommends install \
fonts-ipafont-gothic \
xfonts-100dpi \
xfonts-75dpi \
xfonts-cyrillic \
xfonts-scalable \
&& rm -rf /var/lib/apt/lists/*

#=========
# fluxbox
# A fast, lightweight and responsive window manager
#=========
RUN apt-get update -qqy \
&& apt-get -qqy install \
fluxbox \
&& rm -rf /var/lib/apt/lists/*

#==============================
# Scripts to run Selenium Node
#==============================
COPY entry_point.sh /opt/bin/entry_point.sh
RUN chmod +x /opt/bin/entry_point.sh

EXPOSE 5900
6 changes: 6 additions & 0 deletions NodeDebug/debug-script.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
| tee "/tmp/sel-node.log" &
sleep 0.5

fluxbox -display $DISPLAY &

x11vnc -forever -usepw -shared -rfbport 5900 -display $DISPLAY
19 changes: 19 additions & 0 deletions NodeDebug/generate.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
#!/bin/bash
FOLDER=../$1
BASE=$2
VERSION=$3

rm -rf $FOLDER
mkdir -p $FOLDER

echo FROM selenium/$BASE:$VERSION > $FOLDER/Dockerfile
cat ./Dockerfile >> $FOLDER/Dockerfile

sed '${s/$/ \\/;}' ../NodeBase/entry_point.sh > $FOLDER/entry_point.sh

sed 's/^xvfb-run/sudo -E -i -u seluser \\\
DISPLAY=$DISPLAY \\\
xvfb-run/' $FOLDER/entry_point.sh > $FOLDER/entry_point.sh.tmp
mv $FOLDER/entry_point.sh.tmp $FOLDER/entry_point.sh

cat ./debug-script.sh >> $FOLDER/entry_point.sh
56 changes: 56 additions & 0 deletions NodeFirefoxDebug/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
FROM selenium/node-firefox:2.44.0
#FROM selenium/node-*:2.44.0 Proper FROM attr will be applied throuh generate.sh
MAINTAINER Selenium <[email protected]>

USER root

#=====
# VNC
#=====
RUN apt-get update -qqy \
&& apt-get -qqy install \
x11vnc \
&& rm -rf /var/lib/apt/lists/* \
&& mkdir -p ~/.vnc \
&& x11vnc -storepasswd secret ~/.vnc/passwd

#=================
# Locale settings
#=================
ENV LANGUAGE en_US.UTF-8
ENV LANG en_US.UTF-8
RUN locale-gen en_US.UTF-8 \
&& dpkg-reconfigure --frontend noninteractive locales \
&& apt-get update -qqy \
&& apt-get -qqy --no-install-recommends install \
language-pack-en \
&& rm -rf /var/lib/apt/lists/*

#=======
# Fonts
#=======
RUN apt-get update -qqy \
&& apt-get -qqy --no-install-recommends install \
fonts-ipafont-gothic \
xfonts-100dpi \
xfonts-75dpi \
xfonts-cyrillic \
xfonts-scalable \
&& rm -rf /var/lib/apt/lists/*

#=========
# fluxbox
# A fast, lightweight and responsive window manager
#=========
RUN apt-get update -qqy \
&& apt-get -qqy install \
fluxbox \
&& rm -rf /var/lib/apt/lists/*

#==============================
# Scripts to run Selenium Node
#==============================
COPY entry_point.sh /opt/bin/entry_point.sh
RUN chmod +x /opt/bin/entry_point.sh

EXPOSE 5900
28 changes: 28 additions & 0 deletions NodeFirefoxDebug/entry_point.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
#!/bin/bash
export GEOMETRY="$SCREEN_WIDTH""x""$SCREEN_HEIGHT""x""$SCREEN_DEPTH"

if [ ! -e /opt/selenium/config.json ]; then
echo No Selenium Node configuration file, the node-base image is not intended to be run directly. 1>&2
exit 1
fi

if [ -z "$HUB_PORT_4444_TCP_ADDR" ]; then
echo Not linked with a running Hub container 1>&2
exit 1
fi

# TODO: Look into http://www.seleniumhq.org/docs/05_selenium_rc.jsp#browser-side-logs

sudo -E -i -u seluser \
DISPLAY=$DISPLAY \
xvfb-run --server-args="$DISPLAY -screen 0 $GEOMETRY -ac +extension RANDR" \
java -jar /opt/selenium/selenium-server-standalone.jar \
-role node \
-hub http://hub:4444/grid/register \
-nodeConfig /opt/selenium/config.json \
| tee "/tmp/sel-node.log" &
sleep 0.5

fluxbox -display $DISPLAY &

x11vnc -forever -usepw -shared -rfbport 5900 -display $DISPLAY
7 changes: 5 additions & 2 deletions Test/smoke-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,12 +25,15 @@ module.exports = function(browserName) {
browser.init({
browserName: browserName
}, function() {
browser.get("http://google.com", function() {
browser.get("https://github.com", function() {
browser.title(function(err, title) {
if (err) {
console.error(err);
browser.quit();
process.exit(1);
}
title.should.include('Google');

title.should.include('GitHub');
browser.quit();
});
});
Expand Down
34 changes: 28 additions & 6 deletions test.sh
Original file line number Diff line number Diff line change
@@ -1,4 +1,9 @@
#!/bin/bash
DEBUG=''

if [ -n "$1" ] && [ $1 == 'debug' ]; then
DEBUG='-debug'
fi

echo Building test container image
docker build -t selenium/test:local ./Test
Expand All @@ -8,12 +13,8 @@ HUB=$(docker run -d selenium/hub:2.44.0)
HUB_NAME=$(docker inspect -f '{{ .Name }}' $HUB | sed s:/::)
sleep 2

echo Hub Name $HUB_NAME

NODE_CHROME=$(docker run -d --link $HUB_NAME:hub selenium/node-chrome:2.44.0)
NODE_FIREFOX=$(docker run -d --link $HUB_NAME:hub selenium/node-firefox:2.44.0)

trap "echo Tearing down Selenium Chrome Node container; docker stop $NODE_CHROME; docker rm $NODE_CHROME; echo Tearing down Selenium Firefox Node container; docker stop $NODE_FIREFOX; docker rm $NODE_FIREFOX; echo Tearing down Selenium Hub container; docker stop $HUB; docker rm $HUB; echo Done" EXIT
NODE_CHROME=$(docker run -d --link $HUB_NAME:hub selenium/node-chrome$DEBUG:2.44.0)
NODE_FIREFOX=$(docker run -d --link $HUB_NAME:hub selenium/node-firefox$DEBUG:2.44.0)

docker logs -f $HUB &
docker logs -f $NODE_CHROME &
Expand All @@ -22,3 +23,24 @@ sleep 2

echo Running test container...
docker run --rm -it --link $HUB_NAME:hub selenium/test:local
STATUS=$?

echo Tearing down Selenium Chrome Node container
docker stop $NODE_CHROME
docker rm $NODE_CHROME

echo Tearing down Selenium Firefox Node container
docker stop $NODE_FIREFOX
docker rm $NODE_FIREFOX

echo Tearing down Selenium Hub container
docker stop $HUB
docker rm $HUB

if [ ! $STATUS == 0 ]; then
stopHub
echo Failed
exit 1
fi

echo Done

0 comments on commit 5eb0ab8

Please sign in to comment.