Skip to content

Commit ca07190

Browse files
Merge branch 'master' into issue-64708
2 parents 88e856f + fd2049b commit ca07190

File tree

26 files changed

+159
-458
lines changed

26 files changed

+159
-458
lines changed

.github/renovate.json

Lines changed: 6 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -30,22 +30,16 @@
3030
"description": "We focus on Guice 6 until core adopts 7"
3131
},
3232
{
33-
"groupName": "Selenium",
33+
"allowedVersions": "<100.0.0",
3434
"matchPackageNames": [
3535
"/selenium/"
36-
]
36+
],
37+
"description": "Confusing dual versioning scheme"
3738
},
3839
{
39-
"matchDepNames": [
40-
"docker",
41-
"docker/buildx",
42-
"firefox",
43-
"mozilla/geckodriver",
44-
"org.apache.maven:maven-core"
45-
],
46-
"labels": [
47-
"dependencies",
48-
"build-image"
40+
"groupName": "Selenium",
41+
"matchPackageNames": [
42+
"/selenium/"
4943
]
5044
}
5145
],
@@ -65,29 +59,6 @@
6559
"depNameTemplate": "org.seleniumhq.selenium:selenium-java",
6660
"datasourceTemplate": "maven"
6761
},
68-
{
69-
"customType": "regex",
70-
"managerFilePatterns": [
71-
"/src/main/resources/ath-container/Dockerfile/"
72-
],
73-
"matchStrings": [
74-
"ARG FIREFOX_VERSION=(?<currentValue>.*?)\n"
75-
],
76-
"depNameTemplate": "firefox",
77-
"versioningTemplate": "semver-coerced",
78-
"datasourceTemplate": "custom.firefox"
79-
},
80-
{
81-
"customType": "regex",
82-
"managerFilePatterns": [
83-
"/src/main/resources/ath-container/Dockerfile/"
84-
],
85-
"matchStrings": [
86-
"ARG GECKODRIVER_VERSION=(?<currentValue>.*?)\n"
87-
],
88-
"depNameTemplate": "mozilla/geckodriver",
89-
"datasourceTemplate": "github-releases"
90-
},
9162
{
9263
"customType": "regex",
9364
"managerFilePatterns": [
@@ -133,13 +104,5 @@
133104
"datasourceTemplate": "docker"
134105
}
135106
],
136-
"customDatasources": {
137-
"firefox": {
138-
"defaultRegistryUrlTemplate": "https://product-details.mozilla.org/1.0/firefox_history_stability_releases.json",
139-
"transformTemplates": [
140-
"{\"releases\": $map($keys($), function($v) { {\"version\": $v} })}"
141-
]
142-
}
143-
},
144107
"rebaseWhen": "conflicted"
145108
}

.gitignore

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,5 @@ jenkins*home/
2323
*.ipr
2424
jenkins-plugins/
2525
.jenkins_test/
26-
!src/test/resources/jacoco/test/target
2726
.history
2827
.vscode

Jenkinsfile

Lines changed: 4 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ stage('Record builds and sessions') {
5555
}
5656
axes['jenkinsVersions'].each { jenkinsVersion ->
5757
infra.withArtifactCachingProxy {
58-
sh "rm -rf target && DISPLAY=:0 ./run.sh firefox ${jenkinsVersion} -Dmaven.repo.local=${WORKSPACE_TMP}/m2repo -B clean process-test-resources"
58+
sh "rm -rf target && DISPLAY=:0 ./src/main/resources/ath-container/run.sh firefox ${jenkinsVersion} -Dmaven.repo.local=${WORKSPACE_TMP}/m2repo -B clean process-test-resources"
5959
}
6060
def coreCommit = sh(script: './core-commit.sh', returnStdout: true).trim()
6161
/*
@@ -97,8 +97,6 @@ branches['CI'] = {
9797
}
9898
}
9999

100-
def skipImageBuild = env.CHANGE_ID && !pullRequest.labels.contains('build-image')
101-
102100
for (int i = 0; i < splits.size(); i++) {
103101
int index = i
104102
axes.values().combinations {
@@ -122,11 +120,7 @@ for (int i = 0; i < splits.size(); i++) {
122120
retryCounts = retryCounts + 1 // increment the retry count before allocating a node in case it fails
123121
node(nodeLabel) {
124122
checkout scm
125-
def image = skipImageBuild ? docker.image('jenkins/ath') : docker.build('jenkins/ath', '--build-arg uid="$(id -u)" --build-arg gid="$(id -g)" ./src/main/resources/ath-container/')
126-
sh 'mkdir -p target/ath-reports && chmod a+rwx target/ath-reports'
127-
def cwd = pwd()
128-
def dockergid = sh label: 'get docker group', returnStdout: true, script: 'getent group docker | cut -d: -f3'
129-
image.inside("--group-add ${dockergid} -v /var/run/docker.sock:/var/run/docker.sock -v '${cwd}/target/ath-reports:/reports:rw' --shm-size 2g") {
123+
sh './build-image.sh'
130124
def exclusions = splits.get(index).join('\n')
131125
writeFile file: 'excludes.txt', text: exclusions
132126
infra.withArtifactCachingProxy {
@@ -140,24 +134,14 @@ for (int i = 0; i < splits.size(); i++) {
140134
// but not letting the build to fail will cause next build not to try those tests again.
141135
allowEmptyResults: true
142136
) {
143-
sh """
144-
set-java.sh ${jdk}
145-
# Ensure that Jenkins node setup does not influence the container java setup
146-
unset JAVA_HOME
147-
eval \$(vnc.sh)
148-
java -version
149-
mvn -v
150-
run.sh ${browser} ${jenkinsVersion} -Dmaven.repo.local=${WORKSPACE_TMP}/m2repo -Dmaven.test.failure.ignore=true -Dcsp.rule -DforkCount=1 -B
151-
cp --verbose target/surefire-reports/TEST-*.xml /reports
152-
"""
137+
sh "./ci.sh ${jdk} ${browser} ${jenkinsVersion}"
153138
}
154-
}
155139
}
156140
withCredentials([string(credentialsId: 'launchable-jenkins-acceptance-test-harness', variable: 'LAUNCHABLE_TOKEN')]) {
157141
def sessionFile = "launchable-session-${jenkinsVersion}-${platform}-jdk${jdk}-${browser}.txt"
158142
unstash sessionFile
159143
def session = readFile(sessionFile).trim()
160-
sh "launchable verify && launchable record tests --session ${session} maven './target/ath-reports'"
144+
sh "launchable verify && launchable record tests --session ${session} maven './target/surefire-reports'"
161145
}
162146
}
163147
}

ath-container.sh

Lines changed: 10 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -1,45 +1,19 @@
11
#!/usr/bin/env bash
2-
# https://disconnected.systems/blog/another-bash-strict-mode/
3-
set -euo pipefail
4-
trap 's=$?; echo "$0: Error $s on line "$LINENO": $BASH_COMMAND"; exit $s' ERR
2+
set -uo pipefail
53

64
DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" >/dev/null && pwd)"
75

8-
uid=$(id -u)
9-
gid=$(id -g)
10-
tag='jenkins/ath'
11-
java_version="${java_version:-17}"
12-
13-
# high chance of uid / group already existing in the container
14-
# known to happen on macOS
15-
if ((uid < 1000)); then
16-
uid=1001
6+
# Obtain the group ID to grant to access the Docker socket
7+
if [[ -z ${DOCKER_GID:-} ]]; then
8+
DOCKER_GID=$(docker run --rm -v /var/run/docker.sock:/var/run/docker.sock ubuntu:noble stat -c %g /var/run/docker.sock) || exit 1
9+
export DOCKER_GID
1710
fi
1811

19-
if ((gid < 1000)); then
20-
gid=1001
21-
fi
12+
"${DIR}/build-image.sh" || exit 1
2213

23-
docker build \
24-
--build-arg=uid="$uid" \
25-
--build-arg=gid="$gid" \
26-
"$DIR/src/main/resources/ath-container" \
27-
-t "$tag"
14+
trap 'docker-compose kill && docker-compose down' EXIT
2815

29-
# obtain the groupId to grant to access the docker socket
30-
dockergid=$(docker run --rm -v /var/run/docker.sock:/var/run/docker.sock ubuntu:noble stat -c %g /var/run/docker.sock)
16+
docker-compose run --name mvn --rm -P -v "${HOME}/.m2/repository:/home/ath-user/.m2/repository" mvn bash -c 'set-java.sh 17; bash'
17+
status=$?
3118

32-
docker run \
33-
--interactive \
34-
--tty \
35-
--rm \
36-
--publish-all \
37-
--user ath-user \
38-
--workdir /home/ath-user/sources \
39-
--shm-size 2g \
40-
--group-add ${dockergid} \
41-
-v /var/run/docker.sock:/var/run/docker.sock \
42-
-v "$(pwd):/home/ath-user/sources" \
43-
-v "${HOME}/.m2/repository:/home/ath-user/.m2/repository" \
44-
$tag \
45-
/bin/bash -c "set-java.sh $java_version; bash"
19+
exit $status

build-image.sh

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
#!/usr/bin/env bash
2+
set -uo pipefail
3+
4+
uid=$(id -u) || exit 1
5+
gid=$(id -g) || exit 1
6+
7+
# high chance of uid / group already existing in the container
8+
# known to happen on macOS
9+
if ((uid < 1000)); then
10+
uid=1001
11+
fi
12+
13+
if ((gid < 1000)); then
14+
gid=1001
15+
fi
16+
17+
# Obtain the group ID to grant to access the Docker socket
18+
if [[ -z ${DOCKER_GID:-} ]]; then
19+
DOCKER_GID=$(docker run --rm -v /var/run/docker.sock:/var/run/docker.sock ubuntu:noble stat -c %g /var/run/docker.sock) || exit 1
20+
export DOCKER_GID
21+
fi
22+
23+
docker-compose pull || exit 1
24+
docker-compose build --build-arg=uid="$uid" --build-arg=gid="$gid" || exit 1
25+
26+
exit 0

ci.sh

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
#!/usr/bin/env bash
2+
set -uo pipefail
3+
4+
jdk="$1"
5+
browser="$2"
6+
jenkinsVersion="$3"
7+
8+
# Obtain the group ID to grant to access the Docker socket
9+
if [[ -z ${DOCKER_GID:-} ]]; then
10+
DOCKER_GID=$(docker run --rm -v /var/run/docker.sock:/var/run/docker.sock ubuntu:noble stat -c %g /var/run/docker.sock) || exit 1
11+
export DOCKER_GID
12+
fi
13+
14+
RECORDER=failuresOnly
15+
if ((jdk == 17)); then
16+
# Crashes Monte when used with a remote X11 display
17+
RECORDER=off
18+
fi
19+
20+
trap 'docker-compose kill && docker-compose down' EXIT
21+
22+
docker-compose run -e "MAVEN_ARGS=${MAVEN_ARGS}" -e "RECORDER=${RECORDER}" --name mvn -T --rm -v "${MAVEN_SETTINGS}:${MAVEN_SETTINGS}" mvn bash -s <<-INSIDE
23+
set-java.sh ${jdk}
24+
25+
# Ensure that Jenkins node setup does not influence the container Java setup
26+
unset JAVA_HOME
27+
28+
java -version
29+
mvn -v
30+
31+
run.sh remote-webdriver-${browser} ${jenkinsVersion} -Dmaven.test.failure.ignore=true -Dcsp.rule -DforkCount=1 -B
32+
INSIDE
33+
status=$?
34+
35+
if [[ -d target/surefire-reports ]]; then
36+
find target/surefire-reports -type f -name 'TEST-*.xml' -print0 |
37+
xargs -0 sed -i 's!\[\[ATTACHMENT|/home/ath-user/sources/target\(/[^]]*\)\]\]![[ATTACHMENT|'"$PWD"'/target\1]]!g'
38+
else
39+
echo 'No test results to be saved'
40+
fi
41+
42+
exit $status

docker-compose.yml

Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
1+
---
2+
services:
3+
firefox:
4+
container_name: firefox
5+
environment:
6+
- SE_JAVA_OPTS=-Xmx256m -XX:+HeapDumpOnOutOfMemoryError -XX:+TieredCompilation -XX:TieredStopAtLevel=1
7+
- SE_NODE_GRID_URL=http://firefox:4444 # Selenium needs to know where to advertise itself (e.g. BiDi)
8+
- SE_SCREEN_HEIGHT=1090
9+
- SE_SCREEN_WIDTH=1680
10+
extra_hosts:
11+
- host.docker.internal:host-gateway
12+
image: selenium/standalone-firefox:4.32.0@sha256:40c0aa58b61f51aadda3dc0f92f7b8fa02658bb1cf8a9293b8cd7e5c7913d506
13+
networks:
14+
- ath-network
15+
ports:
16+
- 4444:4444 # Selenium Grid port
17+
- 5900:5900 # VNC port
18+
shm_size: 2g
19+
volumes:
20+
- shared_tmp:/tmp
21+
mvn:
22+
build:
23+
context: src/main/resources/ath-container
24+
dockerfile: Dockerfile
25+
cache_from:
26+
- jenkins/ath:latest
27+
container_name: mvn
28+
depends_on:
29+
- firefox
30+
environment:
31+
- DISPLAY=firefox:99.0
32+
- DOCKER_FIXTURES_NETWORK=ath-network
33+
- JENKINS_LOCAL_HOSTNAME=mvn
34+
- REMOTE_WEBDRIVER_URL=http://firefox:4444/wd/hub
35+
- SELENIUM_PROXY_HOSTNAME=mvn
36+
- SHARED_DOCKER_SERVICE=true
37+
- TESTCONTAINERS_HOST_OVERRIDE=host.docker.internal
38+
extra_hosts:
39+
- host.docker.internal:host-gateway
40+
group_add:
41+
- ${DOCKER_GID}
42+
image: jenkins/ath:latest
43+
networks:
44+
- ath-network
45+
ports:
46+
- 5005:5005 # Maven debug port
47+
shm_size: 2g
48+
user: ath-user
49+
volumes:
50+
- ${PWD}:/home/ath-user/sources
51+
- shared_tmp:/tmp
52+
- /var/run/docker.sock:/var/run/docker.sock
53+
working_dir: /home/ath-user/sources
54+
networks:
55+
ath-network:
56+
name: ath-network
57+
attachable: true
58+
volumes:
59+
shared_tmp:
60+
driver: local
61+
driver_opts:
62+
type: tmpfs
63+
device: tmpfs

docs/BROWSER.md

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -72,15 +72,6 @@ If this is the case you can specify the address to use using:
7272
The same issue will also impact any other containers started that the tests that the Browser (rather than Jenkins) needs to access.
7373
For [Testcontainers](https://testcontainers.com/) you can additionally set `TESTCONTAINERS_HOST_OVERRIDE=ip.address.of.host`
7474

75-
## Avoid focus steal with Xvnc on Linux
76-
If you select a real GUI browser, such as Firefox,
77-
a browser window will pop up left and right during tests,
78-
making it practically unusable for you to use your computer.
79-
There is a script to run VNC server and propagate the display number to the test suite using the dedicated variable `BROWSER_DISPLAY`.
80-
81-
$ eval "$(./vnc.sh)"
82-
$ mvn test
83-
8475
## Example using remote web driver
8576

8677
Untested pseudo bash example

docs/DOCKER.md

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@ To enable this, set the environment variable SHARED_DOCKER_SERVICE=true, and the
99
Interactive shell:
1010
```
1111
harry@devbox $ ./ath-container.sh
12-
ath-user@0b968f00a942:~$ eval $(vnc.sh)
1312
ath-user@0b968f00a942:~$ run.sh firefox latest -Dmaven.test.failure.ignore=true -DforkCount=1 -B -Dtest=...
1413
```
1514

@@ -21,7 +20,7 @@ See the repository `Jenkinsfile` for inspiration.
2120
If you need to debug the tests running in a Docker container, run the tests with:
2221

2322
```bash
24-
run.sh firefox latest -Dmaven.surefire.debug="-Xdebug -Xrunjdwp:transport=dt_socket,server=y,suspend=y,address=*:5005 -Xnoagent -Djava.compiler=NONE" -Dtest=...
23+
run.sh remote-webdriver-firefox latest -Dmaven.surefire.debug="-Xdebug -Xrunjdwp:transport=dt_socket,server=y,suspend=y,address=*:5005 -Xnoagent -Djava.compiler=NONE" -Dtest=...
2524
```
2625

2726
With this instruction, the tests will stop until you connect a remote debugger.
@@ -41,11 +40,7 @@ It's best explained with an example:
4140
harry@devbox:~/acceptance-test-harness$ ./ath-container.sh
4241
```
4342

44-
1. In the container shell, set up the VNC server and run the tests with debugging:
45-
46-
```bash
47-
ath-user@1803848e337f:~/ath-sources$ eval $(vnc.sh)
48-
```
43+
1. In the container shell, run the tests with debugging:
4944

5045
```bash
5146
ath-user@1803848e337f:~/ath-sources$ run.sh firefox latest -Dmaven.surefire.debug="-Xdebug -Xrunjdwp:transport=dt_socket,server=y,suspend=y,address=*:5005 -Xnoagent -Djava.compiler=NONE" -DrunSmokeTests

0 commit comments

Comments
 (0)