Skip to content
This repository was archived by the owner on Jun 30, 2021. It is now read-only.

Commit e45cf2b

Browse files
committed
Support non-sudo environments like K8s for running the container #175
1 parent 07b9818 commit e45cf2b

File tree

9 files changed

+56
-70
lines changed

9 files changed

+56
-70
lines changed

Dockerfile

Lines changed: 12 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -583,6 +583,9 @@ RUN wget --no-verbose -O geckodriver.tar.gz \
583583
&& rm -rf /opt/geckodriver* \
584584
&& tar -C /opt -xvzf geckodriver.tar.gz \
585585
&& chmod +x /opt/geckodriver \
586+
&& cp /opt/geckodriver /usr/bin/geckodriver \
587+
&& chown seluser:seluser /opt/geckodriver \
588+
&& chown seluser:seluser /usr/bin/geckodriver \
586589
&& rm geckodriver.tar.gz
587590

588591
#===============
@@ -619,6 +622,7 @@ COPY lib/* /usr/lib/
619622
# Use a custom wallpaper for Fluxbox
620623
COPY images/wallpaper-dosel.png /usr/share/images/fluxbox/ubuntu-light.png
621624
COPY images/wallpaper-zalenium.png /usr/share/images/fluxbox/
625+
RUN chown -R seluser:seluser /usr/share/images/fluxbox/
622626

623627
#===================================================
624628
# Run the following commands as non-privileged user
@@ -924,6 +928,7 @@ ENV FIREFOX_VERSION="${FF_VER}" \
924928
GA_ENDPOINT=https://www.google-analytics.com/collect \
925929
GA_API_VERSION="1" \
926930
DEBIAN_FRONTEND="" \
931+
USE_KUBERNETES="false" \
927932
DEBCONF_NONINTERACTIVE_SEEN=""
928933

929934
#================================
@@ -957,16 +962,13 @@ COPY Analytics.md /home/seluser/
957962
#===================================
958963
# The .X11-unix stuff is useful when using Xephyr
959964
RUN mkdir -p /home/seluser/.vnc \
960-
&& sudo touch /capabilities3.json \
961-
&& sudo chown seluser:seluser /capabilities3.json \
962-
&& generate_capabilities3_json > /capabilities3.json \
963-
&& cp /capabilities3.json /home/seluser/capabilities3.json \
964-
&& cp /capabilities3.json /home/seluser/capabilities3 \
965-
&& cp /capabilities3.json /home/seluser/caps3.json \
966-
&& cp /capabilities3.json /home/seluser/caps3 \
967-
&& sudo cp /capabilities3.json /capabilities.json \
968-
&& sudo cp /capabilities3.json /home/seluser/capabilities.json \
969-
&& sudo cp /capabilities3.json /home/seluser/caps.json \
965+
&& sudo touch /capabilities.json \
966+
&& sudo chown seluser:seluser /capabilities.json \
967+
&& generate_capabilities_json > /capabilities.json \
968+
&& cp /capabilities.json /home/seluser/capabilities.json \
969+
&& cp /capabilities.json /home/seluser/capabilities \
970+
&& cp /capabilities.json /home/seluser/caps.json \
971+
&& cp /capabilities.json /home/seluser/caps \
970972
&& mkdir -p ${VIDEOS_DIR} \
971973
&& sudo ln -s ${VIDEOS_DIR} /videos \
972974
&& sudo chown seluser:seluser /videos \

bin/clear_x_locks.sh

Lines changed: 0 additions & 13 deletions
This file was deleted.

bin/entry.sh

Lines changed: 22 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -13,25 +13,32 @@ die () {
1313
exit $errnum
1414
}
1515

16+
if [ -f /var/run/secrets/kubernetes.io/serviceaccount/token ]; then
17+
log "Kubernetes service account found."
18+
export USE_KUBERNETES=true
19+
fi
20+
1621
#==============================================
1722
# Java blocks until kernel have enough entropy
1823
# to generate the /dev/random seed
1924
#==============================================
2025
# See: SeleniumHQ/docker-selenium/issues/14
21-
sudo haveged
26+
# Added a non-sudo conditional so this works on non-sudo environments like K8s
27+
(sudo haveged) || haveged
2228

2329
# Workaround that might help to get dbus working in docker
2430
# http://stackoverflow.com/a/38355729/511069
2531
# https://github.com/SeleniumHQ/docker-selenium/issues/87#issuecomment-187659234
2632
# - still unclear if this helps: `-v /var/run/dbus:/var/run/dbus`
2733
# - this works generates errors: DBUS_SESSION_BUS_ADDRESS="/dev/null"
2834
# - this gives less erros: DBUS_SESSION_BUS_ADDRESS="unix:abstract=/dev/null"
29-
sudo rm -f /var/lib/dbus/machine-id
30-
sudo mkdir -p /var/run/dbus
31-
sudo service dbus restart >dbus_service.log
35+
# Added a non-sudo conditional so this works on non-sudo environments like K8s
36+
(sudo rm -f /var/lib/dbus/machine-id) || (rm -f /var/lib/dbus/machine-id) || true
37+
(sudo mkdir -p /var/run/dbus) || (mkdir -p /var/run/dbus) || true
38+
(sudo service dbus restart >dbus_service.log) || (service dbus restart >dbus_service.log) || true
3239
# Test dbus works
33-
service dbus status >dbus_service_status.log
34-
export $(dbus-launch)
40+
(service dbus status >dbus_service_status.log) || true
41+
export $(dbus-launch) || true
3542
export NSS_USE_SHARED_DB=ENABLED
3643
# echo "-- INFO: DBUS_SESSION_BUS_ADDRESS=${DBUS_SESSION_BUS_ADDRESS}"
3744
#=> e.g. DBUS_SESSION_BUS_ADDRESS=unix:abstract=/tmp/dbus-APZO4BE4TJ,guid=6e9c098d053d3038cb0756ae57ecc885
@@ -44,22 +51,11 @@ stop >/dev/null 2>&1 || true
4451
rm -f ${LOGS_DIR}/*
4552
rm -f ${RUN_DIR}/*
4653

47-
# Support restart docker container for selenium 3 @aituganov
48-
if [ ! -f /usr/bin/geckodriver ]; then
49-
sudo mv /opt/geckodriver /usr/bin/geckodriver
50-
sudo ln -fs /usr/bin/geckodriver /opt/geckodriver
51-
fi
52-
53-
sudo cp /capabilities3.json /capabilities.json
54-
sudo cp /capabilities3.json /home/seluser/capabilities.json
55-
sudo cp /capabilities3.json /home/seluser/caps.json
56-
5754
#---------------------
5855
# Fix/extend ENV vars
5956
#---------------------
6057
export SELENIUM_JAR_PATH="/home/seluser/selenium-server-standalone-3.jar"
6158
export FIREFOX_DEST_BIN="/home/seluser/firefox-for-sel-3/firefox"
62-
sudo ln -fs ${FIREFOX_DEST_BIN} /usr/bin/firefox
6359
export DOSEL_VERSION=$(cat VERSION)
6460
export FIREFOX_VERSION=$(firefox_version)
6561
# CHROME_FLAVOR would allow to have separate installations for stable, beta, unstable
@@ -183,7 +179,7 @@ echo "Please send us a PR if you know how to set the path for the Firefox browse
183179
# When running for Zalenium prepare certain customizations
184180
if [ "${ZALENIUM}" == "true" ]; then
185181
# Set proper desktop background
186-
sudo mv -f /usr/share/images/fluxbox/wallpaper-zalenium.png /usr/share/images/fluxbox/ubuntu-light.png
182+
mv -f /usr/share/images/fluxbox/wallpaper-zalenium.png /usr/share/images/fluxbox/ubuntu-light.png
187183
fi
188184

189185
# TODO: Remove this duplicated logic
@@ -375,24 +371,23 @@ ga_track_start () {
375371
fi
376372
}
377373

378-
#----------------------------------------
379-
# Remove lock files, thanks @garagepoort
380-
# clear_x_locks.sh
381-
382374
#--------------------------------
383375
# Improve etc/hosts and fix dirs
384-
improve_etc_hosts.sh
385-
fix_dirs.sh
376+
if [ "${USE_KUBERNETES}" == "false" ]; then
377+
sudo improve_etc_hosts.sh
378+
fi
386379

387380
#-------------------------
388381
# Docker alongside docker
389-
docker_alongside_docker.sh
382+
if [ "${USE_KUBERNETES}" == "false" ]; then
383+
docker_alongside_docker.sh
384+
fi
390385

391386
#-------------------------------
392387
# Fix small tiny 64mb shm issue
393388
#-------------------------------
394389
# https://github.com/elgalu/docker-selenium/issues/20
395-
if [ "${SHM_TRY_MOUNT_UNMOUNT}" = "true" ]; then
390+
if [ "${SHM_TRY_MOUNT_UNMOUNT}" = "true" ] && [ "${USE_KUBERNETES}" == "false" ]; then
396391
sudo umount /dev/shm || true
397392
sudo mount -t tmpfs -o rw,nosuid,nodev,noexec,relatime,size=${SHM_SIZE} \
398393
tmpfs /dev/shm || true
@@ -440,6 +435,7 @@ echo "${SEL_UNREGISTER_IF_STILL_DOWN_AFTER}" > SEL_UNREGISTER_IF_STILL_DOWN_AFTE
440435
echo "${SELENIUM_NODE_PARAMS}" > SELENIUM_NODE_PARAMS
441436
echo "${CUSTOM_SELENIUM_NODE_PROXY_PARAMS}" > CUSTOM_SELENIUM_NODE_PROXY_PARAMS
442437
echo "${CUSTOM_SELENIUM_NODE_REGISTER_CYCLE}" > CUSTOM_SELENIUM_NODE_REGISTER_CYCLE
438+
echo "${USE_KUBERNETES}" > USE_KUBERNETES
443439
echo "${XMANAGER}" > XMANAGER
444440
echo "${GRID}" > GRID
445441

dns/bin/improve_etc_hosts.sh

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,13 @@
11
#!/usr/bin/env bash
22

3-
sudo -E sh -c 'cat /tmp/hosts >> /etc/hosts'
4-
sudo -E sh -c 'echo "$DOCKER_HOST_IP docker.host" >> /etc/hosts'
5-
sudo -E sh -c 'echo "$CONTAINER_IP docker.guest" >> /etc/hosts'
6-
sudo -E sh -c 'echo "$DOCKER_HOST_IP docker.host.dev" >> /etc/hosts'
7-
sudo -E sh -c 'echo "$DOCKER_HOST_IP d.host.loc.dev" >> /etc/hosts'
8-
sudo -E sh -c 'echo "$CONTAINER_IP docker.guest.dev" >> /etc/hosts'
9-
sudo -E sh -c 'echo "$DOCKER_HOST_IP host.docker.local" >> /etc/hosts'
10-
sudo -E sh -c 'echo "$CONTAINER_IP guest.docker.local" >> /etc/hosts'
11-
sudo -E sh -c 'echo "$CONTAINER_IP d.guest.loc.dev" >> /etc/hosts'
12-
sudo -E sh -c 'echo "$DOCKER_HOST_IP host.docker" >> /etc/hosts'
13-
sudo -E sh -c 'echo "$CONTAINER_IP guest.docker" >> /etc/hosts'
3+
cat /tmp/hosts >> /etc/hosts
4+
echo "$DOCKER_HOST_IP docker.host" >> /etc/hosts
5+
echo "$CONTAINER_IP docker.guest" >> /etc/hosts
6+
echo "$DOCKER_HOST_IP docker.host.dev" >> /etc/hosts
7+
echo "$DOCKER_HOST_IP d.host.loc.dev" >> /etc/hosts
8+
echo "$CONTAINER_IP docker.guest.dev" >> /etc/hosts
9+
echo "$DOCKER_HOST_IP host.docker.local" >> /etc/hosts
10+
echo "$CONTAINER_IP guest.docker.local" >> /etc/hosts
11+
echo "$CONTAINER_IP d.guest.loc.dev" >> /etc/hosts
12+
echo "$DOCKER_HOST_IP host.docker" >> /etc/hosts
13+
echo "$CONTAINER_IP guest.docker" >> /etc/hosts

test/script_scenario_basic

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -86,4 +86,3 @@ fi
8686
docker exec grid errors || true
8787
docker cp grid:/test/console.png ./images/grid3_console.png
8888
docker cp grid:/capabilities.json .
89-
docker cp grid:/capabilities3.json .

test/script_scenario_node_dies

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -133,20 +133,22 @@ fi
133133

134134
echo "#======================================================"
135135
echo "# Scenario 3c [node_dies]: Dies by killing a Multi-node"
136+
echo "# + run tests again simulation USE_KUBERNETES=true"
136137
echo "#======================================================"
137138

138139
# Ensure clean env
139140
docker rm -vf mynodes || true
140141
docker rm -vf grid_mock || true
141142

142-
# Create container for Firefox
143+
# Create container for Firefox and simulate USE_KUBERNETES=true
143144
docker run --name=mynodes -d \
144145
-v /dev/shm:/dev/shm \
145146
--privileged \
146147
-e CHROME=false \
147148
-e FIREFOX=false \
148149
-e MULTINODE=true \
149150
-e CI \
151+
-e USE_KUBERNETES=true \
150152
-e SELENIUM_MULTINODE_PORT \
151153
-p ${SELENIUM_MULTINODE_PORT}:${SELENIUM_MULTINODE_PORT} \
152154
selenium

utils/bin/fix_dirs.sh

Lines changed: 0 additions & 4 deletions
This file was deleted.

video-rec/bin/fix_videos.sh

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,10 +24,12 @@ if [ -z "${HOST_GID}" ] && [ -z "${HOST_UID}" ]; then
2424
[ -z "${VIDEOS_DIR}" ] && die "Need env var set \$VIDEOS_DIR"
2525
export HOST_GID=$(stat -c "%g" ${VIDEOS_DIR})
2626
export HOST_UID=$(stat -c "%u" ${VIDEOS_DIR})
27+
elif [ "${USE_KUBERNETES}" == "true" ]; then
28+
log "No sudo support in K8s so will skip setting up sudo groupadd -g ${HOST_GID} tempgroup"
2729
else
2830
GROUP_EXISTS=$(cat /etc/group | grep ${HOST_GID} | wc -l)
2931
# Create new group using target GID and add seluser user
30-
if [ $GROUP_EXISTS == "0" ]; then
32+
if [ ${GROUP_EXISTS} == "0" ]; then
3133
sudo groupadd -g ${HOST_GID} tempgroup
3234
sudo gpasswd -a seluser tempgroup
3335
else

video-rec/bin/start-video-rec.sh

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,8 @@ set -e
1010
FFMPEG_FRAME_SIZE="${SCREEN_WIDTH}x${SCREEN_HEIGHT}"
1111

1212
# Remove the video file if exists
13-
sudo rm -f "${VIDEO_BASE_PATH}"*
13+
# Added a non-sudo conditional so this works on non-sudo environments like K8s
14+
(sudo rm -f "${VIDEO_BASE_PATH}"*) || (rm -f "${VIDEO_BASE_PATH}"*)
1415

1516
# record testing video using password file
1617
# using sudo due to http://stackoverflow.com/questions/23544282/
@@ -30,8 +31,9 @@ export tmp_video_path="${VIDEOS_DIR}/${VIDEO_FILE_NAME}.${VIDEO_TMP_FILE_EXTENSI
3031
export final_video_path="${VIDEOS_DIR}/${VIDEO_FILE_NAME}.${VIDEO_FILE_EXTENSION}"
3132

3233
# Fix perms to be able to start ffmpeg without sudo
33-
sudo touch "${tmp_video_path}"
34-
sudo chown seluser:seluser "${tmp_video_path}"
34+
# Added a non-sudo conditional so this works on non-sudo environments like K8s
35+
(sudo touch "${tmp_video_path}") || (touch "${tmp_video_path}")
36+
(sudo chown seluser:seluser "${tmp_video_path}") || (chown seluser:seluser "${tmp_video_path}") || true
3537

3638
# avconv or ffmpeg
3739
ffmpeg -f x11grab \

0 commit comments

Comments
 (0)