Skip to content

Commit 35942bb

Browse files
committed
Add Makefile support to stay DRY
1 parent 2c39f33 commit 35942bb

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

55 files changed

+502
-184
lines changed

.env

Lines changed: 35 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,14 +2,45 @@
22
# file named docker-compose.yml in the current directory and then each
33
# parent directory in succession until a file by that name is found.
44
# https://docs.docker.com/compose/reference/envvars/#compose-file
5-
COMPOSE_FILE=docker-compose.yml
5+
export COMPOSE_FILE ?= docker-compose.yml
6+
7+
# We prefer Real VNC client because it allows the
8+
# -Scaling % option
9+
export VNC_CLIENT_NAME ?= RealVNC
10+
export VNC_DOWNLOAD_BASE_URL = https://www.realvnc.com/download/file/vnc.files
11+
export VNC_CLIENT_VERSION = 5.3.2
12+
export VNC_CLIENT ?= vncviewer
13+
export VNC_CLIENT_ERROR_MSG="Required VNC viewer '${VNC_CLIENT_NAME}' is not installed"
14+
export VNC_FILE_OSX = VNC-${VNC_CLIENT_VERSION}-MacOSX-x86_64.pkg
15+
export VNC_FILE_LINUX = VNC-${VNC_CLIENT_VERSION}-Linux-x64-DEB.tar.gz
16+
export VNC_MD5SUM_OSX = a9b2ba07286f04dadc63db252a95b639
17+
export VNC_MD5SUM_LINUX = 5b0da4c2d3a8f1e3db5982b9e6be2cb6
18+
# The command we will use to check if proper VNC is installed
19+
export VNC_CHECK_CMD = ${VNC_CLIENT} -h | grep -i '${VNC_CLIENT_NAME}' >/dev/null
20+
21+
# Timeouts
22+
export WAIT_ALL_DONE ?= 40s
23+
24+
# Number of nodes
25+
export chrome ?= 1
26+
export firefox ?= 1
27+
28+
# To target a specific node number
29+
# for example to VNC into it via
30+
# make see browser=chrome node=1
31+
export browser ?= chrome
32+
export node ?= 1
633

734
# If you project name is selenium and it includes two services
835
# `hub` and `node` then compose starts containers named
9-
# selenium_hub_1 and selenium_node_1 respectively.
36+
# grid_hub_1 and grid_node_1 respectively.
1037
# It will also
1138
# https://docs.docker.com/compose/reference/envvars/#compose-project-name
12-
COMPOSE_PROJECT_NAME=selenium
39+
export COMPOSE_PROJ_NAME ?= grid
40+
41+
# App name is the service name for the web app under test
42+
export APP_NAME ?= mock
1343

1444
# We need a fixed port number to know where to connect the selenium tests
15-
SELENIUM_HUB_PORT=4444
45+
export HUB_PORT ?= 4444
46+
export SELENIUM_HUB_PORT ?= ${HUB_PORT}

.gitignore

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,17 @@ binaries/
44
READMEBS.md
55
READMEZala.sh
66
.python-version
7-
videos/
7+
videos
88
android/
99
binaries
1010
scm-source.json
1111
TODO.md
1212
docker_push.log
1313
bats/
14+
compose_down.log
15+
docker-pull.log
16+
VNC-*-Linux-x64-DEB.tar.gz
17+
VNC-Viewer-*-Linux-x64.deb
18+
VNC-*-MacOSX-x86_64.pkg
19+
vnc_linux.md5
20+
vnc_osx.md5

.travis.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,7 @@ install:
7777

7878
script:
7979
- ./test/script_start
80-
- travis_retry ./test/script_with_retry
80+
- travis_retry ./test/script_scenario_compose_N_N
8181
- ./test/script_end
8282

8383
# cleanup though doesn't seem to be necessary in Travis infra

CHANGELOG.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,8 @@ Note image ids also change after scm-source.json has being updated which trigger
1010
## TBD_DOCKER_TAG
1111
+ Date: TBD_DATE
1212
+ Upgrade dockertoolbox cask to 1.12.0-rc4
13+
+ Add Makefile support to stay DRY
14+
+ Upgrade Python from 2.7.11 to 2.7.12
1315
+ Image tag details:
1416
+ Selenium: vTBD_SELENIUM_VERSION (TBD_SELENIUM_REVISION)
1517
+ Chrome stable: TBD_CHROME_STABLE

CONTRIBUTING.md

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -3,24 +3,24 @@
33
## Local
44
For pull requests or local commits:
55

6-
time (./test/before_install_build && ./test/install && ./test/script_start && ./test/script_with_retry && ./test/script_end) ; beep
6+
time (./test/before_install_build && ./test/install && ./test/script_start && ./test/N_N && ./test/script_end) ; beep
77
docker exec grid versions && ./test/after_script
88
open ./images/grid_console.png #to verify the versions are correct
99
git checkout ./images/grid_console.png && open ./videos/chrome/test.mkv
1010
travis lint #if you changed .travis.yml
11-
git checkout -b tmp-2.53.1i #name your branch according to your changes
11+
git checkout -b tmp-2.53.1j #name your branch according to your changes
1212
#git add ... git commit ... git push ... open pull request
1313

1414
For repository owners only:
1515

16-
git commit -m "Upgrade dockertoolbox cask to 1.12.0-rc4"
16+
git commit -m "Add Makefile support to stay DRY"
1717
git tag -d latest #tag latest will be updated from TravisCI
18-
git tag 2.53.1i && git push origin tmp-2.53.1i && git push --tags
18+
git tag 2.53.1j && git push origin tmp-2.53.1j && git push --tags
1919

2020
-- Wait for Travis to pass OK
2121
-- Make sure changes got merged into master by elgalubot
2222

23-
git checkout master && git pull && git branch -d tmp-2.53.1i && git push origin --delete tmp-2.53.1i
23+
git checkout master && git pull && git branch -d tmp-2.53.1j && git push origin --delete tmp-2.53.1j
2424

2525
-- Re-add TBD_* section in CHANGELOG.md starting with TBD_DOCKER_TAG
2626
-- If Chrome version changed upload:
@@ -36,9 +36,9 @@ Keep certain bins if chrome version changed for example:
3636
## Retry
3737
Failed in Travis? retry
3838

39-
git tag -d 2.53.1i && git push origin :2.53.1i
39+
git tag -d 2.53.1j && git push origin :2.53.1j
4040
#git add ...
41-
git commit --amend && git tag 2.53.1i && git push --force origin tmp-2.53.1i && git push --tags
41+
git commit --amend && git tag 2.53.1j && git push --force origin tmp-2.53.1j && git push --tags
4242

4343
## Docker push from Travis CI
4444
Travis [steps](https://docs.travis-ci.com/user/docker/#Pushing-a-Docker-Image-to-a-Registry) involve `docker login` and docker credentials encryptions.

Dockerfile

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1011,8 +1011,11 @@ ENV FIREFOX_VERSION="${FF_VER}" \
10111011
VNC_PORT="${DEFAULT_VNC_PORT}" \
10121012
# VNC_CLI_OPTS="-noipv6 -no6 -forever -shared" \
10131013
VNC_CLI_OPTS="-forever -shared" \
1014-
# You can set the VNC password or leave null so a random password is generated:
1015-
# ENV VNC_PASSWORD topsecret
1014+
# VNC password options:
1015+
# - "no" means no password; less secure but not a big deal
1016+
# - "" (empty string) means it will be randomly generated
1017+
# - "some-value" will use that password "some-value" or whatever
1018+
VNC_PASSWORD=no \
10161019
NOVNC_PORT="${DEFAULT_NOVNC_PORT}" \
10171020
NOVNC="false" \
10181021
SSHD="false" \

Makefile

Lines changed: 148 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,148 @@
1+
# Usage
2+
# make setup #first time
3+
# make chrome=3 firefox=5
4+
# note is destructive, firsts `compose down`
5+
# warns if your service is not listed in the `docker-compose.yml`
6+
# make cleanup
7+
#
8+
# All in one
9+
# make setup compose chrome=3 firefox=5 see browser=firefox node=5
10+
include .env
11+
12+
ECHOERR=sh -c 'awk " BEGIN { print \"-- ERROR: $$1\" > \"/dev/fd/2\" }"' ECHOERR
13+
# TODO: Output warning in color: yellow
14+
ECHOWARN=sh -c 'awk " BEGIN { print \"-- WARN: $$1\" > \"/dev/fd/2\" }"' ECHOWARN
15+
16+
default: compose
17+
18+
docker-compose.yml:
19+
wget -nv "https://raw.githubusercontent.com/elgalu/docker-selenium/latest/docker-compose.yml"
20+
21+
.env:
22+
wget -nv "https://raw.githubusercontent.com/elgalu/docker-selenium/latest/.env"
23+
24+
mk/install_vnc.sh:
25+
wget -nv "https://raw.githubusercontent.com/elgalu/docker-selenium/latest/mk/install_vnc.sh" \
26+
-O mk/install_vnc.sh
27+
28+
mk/vnc_cask.rb:
29+
wget -nv "https://raw.githubusercontent.com/elgalu/docker-selenium/latest/mk/vnc_cask.rb" \
30+
-O mk/vnc_cask.rb
31+
32+
mk/see.sh:
33+
wget -nv "https://raw.githubusercontent.com/elgalu/docker-selenium/latest/mk/see.sh" \
34+
-O mk/see.sh
35+
36+
mk/wait.sh:
37+
wget -nv "https://raw.githubusercontent.com/elgalu/docker-selenium/latest/mk/wait.sh" \
38+
-O mk/wait.sh
39+
40+
install_vnc:
41+
./mk/install_vnc.sh
42+
43+
mk:
44+
mkdir -p mk
45+
46+
docker:
47+
@if ! docker --version; then \
48+
${ECHOERR} "We need docker installed" ; \
49+
${ECHOERR} "google: 'install docker'" ; \
50+
exit 1; \
51+
fi
52+
53+
docker-compose:
54+
@if ! docker-compose --version; then \
55+
${ECHOERR} "We need docker installed" ; \
56+
${ECHOERR} "google: 'install docker-compose'" ; \
57+
exit 1; \
58+
fi
59+
60+
pull:
61+
# Only pull for end users
62+
@if [ "${TESTING}" != "true" ]; then \
63+
docker pull elgalu/selenium:latest > mk/docker-pull.log ; \
64+
fi
65+
66+
warn_vncviewer:
67+
# Only check if not in a CI server
68+
@if [ "${BUILD_NUMBER}" = "" ]; then \
69+
if ! eval ${VNC_CHECK_CMD}; then \
70+
${ECHOWARN} ${VNC_CLIENT_ERROR_MSG} ; \
71+
${ECHOWARN} " RUN: make install_vnc" ; \
72+
fi ; \
73+
fi
74+
75+
check_vncviewer:
76+
@if ! eval ${VNC_CHECK_CMD}; then \
77+
${ECHOERR} ${VNC_CLIENT_ERROR_MSG} ; \
78+
exit 4; \
79+
fi
80+
81+
see: check_vncviewer
82+
./mk/see.sh &
83+
84+
# Shortcut to VNC into Firefox
85+
seeff:
86+
$(MAKE) see browser=firefox
87+
88+
# Shortcut to VNC into Chrome
89+
seech:
90+
$(MAKE) see browser=chrome
91+
92+
env:
93+
env
94+
95+
basic_reqs: docker-compose.yml .env mk mk/wait.sh docker docker-compose
96+
97+
# Gather all requisites
98+
setup: basic_reqs mk/install_vnc.sh mk/vnc_cask.rb mk/see.sh warn_vncviewer pull
99+
@echo "Requirements checked."
100+
101+
cleanup:
102+
docker-compose -f ${COMPOSE_FILE} -p ${COMPOSE_PROJ_NAME} down \
103+
--remove-orphans >./mk/compose_down.log 2>&1
104+
105+
# Alias
106+
down: cleanup
107+
108+
scale:
109+
docker-compose -f ${COMPOSE_FILE} -p ${COMPOSE_PROJ_NAME} scale \
110+
${APP_NAME}=1 hub=1 chrome=${chrome} firefox=${firefox}
111+
$(MAKE) wait chrome=${chrome} firefox=${firefox}
112+
113+
compose: basic_reqs cleanup
114+
docker-compose -f ${COMPOSE_FILE} -p ${COMPOSE_PROJ_NAME} up -d
115+
$(MAKE) scale chrome=${chrome} firefox=${firefox}
116+
117+
wait:
118+
./mk/wait.sh
119+
120+
# Run self tests
121+
test:
122+
docker-compose -f ${COMPOSE_FILE} -p ${COMPOSE_PROJ_NAME} exec \
123+
--index 1 hub run_test
124+
125+
# PHONY: Given make doesn't execute a task if there is an existing file
126+
# with that task name, .PHONY is used to skip that logic listing task names
127+
.PHONY: \
128+
default \
129+
docker \
130+
docker-compose \
131+
pull \
132+
setup \
133+
basic_reqs \
134+
check_vncviewer \
135+
warn_vncviewer \
136+
vncviewer \
137+
vnc \
138+
see \
139+
install_vnc \
140+
scale \
141+
seeff \
142+
seech \
143+
compose \
144+
wait \
145+
down \
146+
cleanup \
147+
env \
148+
test

README.md

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -68,8 +68,7 @@ You will need to run the second `eval` command for every new terminal window.
6868
docker pull elgalu/selenium #upgrades to latest if a newer version is available
6969

7070
docker run -d --name=grid -p 4444:24444 -p 5900:25900 \
71-
-e TZ="US/Pacific" -e VNC_PASSWORD=no \
72-
-v /dev/shm:/dev/shm elgalu/selenium
71+
-e TZ="US/Pacific" -v /dev/shm:/dev/shm elgalu/selenium
7372

7473
2. Wait until the grid starts properly before starting the tests _(Optional but recommended)_
7574

@@ -79,7 +78,7 @@ After this, [Selenium][] should be up and running at `http://localhost:4444/wd/h
7978
If you are using Mac (OSX) or [Microsoft Windows](https://docs.docker.com/engine/installation/windows/) `localhost` won't work unless you are in Docker Beta (version >= 1.12) If you are using Docker version <= 1.11 please find out the correct IP through `docker-machine ip default`.
8079

8180
**Notes:**
82-
* `VNC_PASSWORD=no` will make it VNC passwordless accessible.
81+
* The new default `VNC_PASSWORD=no` will make it VNC passwordless accessible.
8382
* Once this [docker feature](https://github.com/docker/docker/pull/22719) is in place `wait_all_done` won't be necessary anymore.
8483

8584
#### Stop
@@ -101,9 +100,9 @@ See [jenkins](./docs/jenkins.md)
101100
### Parallel
102101
This image is designed to run one test on each docker container but if you still want to run multiple tests in parallel you can still do so, there are some ways to do this:
103102

104-
1. The recommended way is via [docker-compose](./docs/docker-compose.md) and you should replace `adwords_mock` with your web service under test within the [docker-compose.yml][] file.
103+
1. The recommended way is via [docker-compose](./docs/docker-compose.md) and you should replace `mock` with your web service under test within the [docker-compose.yml][] file.
105104

106-
SELENIUM_HUB_PORT=4444 docker-compose -p selenium scale adwords_mock=1 hub=1 chrome=3 firefox=3
105+
SELENIUM_HUB_PORT=4444 docker-compose -p grid scale mock=1 hub=1 chrome=3 firefox=3
107106

108107
1. The _(not recommended)_ way is by increasing `MAX_INSTANCES` and `MAX_SESSIONS` which now [defaults](https://github.com/elgalu/docker-selenium/blob/2.53.1a/Dockerfile#L967) to 1.
109108

browserstack/bin/start-browserstack.sh

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,7 @@
33
# set -e: exit asap if a command exits with a non-zero status
44
set -e
55

6-
# echo fn that outputs to stderr http://stackoverflow.com/a/2990533/511069
7-
echoerr() {
8-
cat <<< "$@" 1>&2;
9-
}
6+
echoerr() { awk " BEGIN { print \"$@\" > \"/dev/fd/2\" }" ; }
107

118
# print error and exit
129
die () {

browserstack/bin/wait-browserstack.sh

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,7 @@
33
# set -e: exit asap if a command exits with a non-zero status
44
set -e
55

6-
# echo fn that outputs to stderr http://stackoverflow.com/a/2990533/511069
7-
echoerr() {
8-
cat <<< "$@" 1>&2;
9-
}
6+
echoerr() { awk " BEGIN { print \"$@\" > \"/dev/fd/2\" }" ; }
107

118
# print error and exit
129
die () {

0 commit comments

Comments
 (0)