Skip to content
This repository has been archived by the owner on Sep 21, 2021. It is now read-only.

Docker Swarm Implementation #982

Merged
merged 37 commits into from
Jun 10, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
37 commits
Select commit Hold shift + click to select a range
7bfe7ab
Add environment variable swarmOverlayNetwork
yosserO Mar 12, 2019
db351fa
Add class SwarmUtilities
yosserO Mar 12, 2019
b7abc98
Return overlay network in swarm mode
yosserO Mar 12, 2019
2e4d152
Set environment variable SELENIUM_NODE_HOST dynamically
yosserO Mar 12, 2019
8088ead
Revert "Return overlay network in swarm mode"
tstern Mar 12, 2019
f656fcb
Implement ssh to execute commands in containers on workers
tstern Mar 14, 2019
22ea97f
Disable copying logs when swarm mode enabled
yosserO Mar 14, 2019
fe6a2fd
Refactor ssh logic to execute commands on node
yosserO Mar 14, 2019
b7c59a2
Replace ssh with docker plugin to execute commands in containers on w…
lfeigl Mar 15, 2019
2cda66e
Adapt SwarmContainerClient wait for task status
tstern Mar 15, 2019
8443bb7
Fix getting correct ip of containers
tstern Mar 19, 2019
eaa5ab6
Mark container as terminated if it doesn't exist
yosserO Mar 19, 2019
cdba59a
Implement check for networkAttachments
tstern Mar 19, 2019
068e397
Clean up swarm container client class
tstern Mar 19, 2019
d054b14
Add dependency commons-collections4
yosserO Mar 20, 2019
c570bd0
Refactor function getContainerByIp
yosserO Mar 20, 2019
453aa40
Add warn message if the ipAddress is nor found in any network
yosserO Mar 20, 2019
0bf4fad
Refactor function getSwarmIp
yosserO Mar 20, 2019
b1e5d3e
Refactor function getContainerId
yosserO Mar 20, 2019
ef1530a
Refactor function executeCommand
yosserO Mar 20, 2019
b437c86
Refactor function stopContainer
yosserO Mar 20, 2019
cff7915
Refactor function createContainer
yosserO Mar 20, 2019
5ce242b
Refactor function getContainerIp
yosserO Mar 20, 2019
8087177
Refactor function isTerminated
yosserO Mar 20, 2019
45e7434
Remove superfluous comment
yosserO Mar 20, 2019
e45d527
Remove todo flag from function getLatestDownloadedImage, since this h…
yosserO Mar 20, 2019
2c93087
Pull swarmExecCommand image at the top of the executeCommand function
yosserO Mar 20, 2019
ae96c37
Improve logging inside function executeCommand
yosserO Mar 20, 2019
ca4174a
Print warning message only if containerInfo is null
yosserO Mar 20, 2019
12d6377
Improve iteration in getContainerByIp method
lfeigl Mar 21, 2019
6f9a23f
Improve iteration in executeCommand method
lfeigl Mar 21, 2019
8ede785
Add missing TODO
lfeigl Mar 21, 2019
b14be89
Fix index out of bounds bug
lfeigl Mar 21, 2019
7edabdc
Apply dynamic container ip only for swarm mode
tstern Mar 25, 2019
6be3405
Add example of a docker-compose file for swarm mode
yosserO Mar 26, 2019
cc99649
Fix error with simultaneous docker operations by synchronizing those …
tstern Apr 5, 2019
c303678
Improve code quality
tstern Apr 5, 2019
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 22 additions & 0 deletions docs/docker/docker-compose-swarm.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
version: "3.7"
services:
zalenium:
image: dosel/zalenium
deploy:
placement:
constraints:
- node.role == manager
ports:
- "4444:4444"
networks:
- zalenium
volumes:
- /var/run/docker.sock:/var/run/docker.sock
- /tmp/videos:/home/seluser/videos
environment:
- PULL_SELENIUM_IMAGE=true
command: ["start", "--swarmOverlayNetwork", "<stack-name>_zalenium", "--videoRecordingEnabled", "false"]
networks:
zalenium:
driver: overlay
attachable: true
5 changes: 5 additions & 0 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -231,6 +231,11 @@
<artifactId>httpmime</artifactId>
<version>${httpmime.version}</version>
</dependency>
<dependency>
<groupId>org.apache.commons</groupId>
<artifactId>commons-collections4</artifactId>
<version>4.3</version>
</dependency>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
Expand Down
7 changes: 7 additions & 0 deletions scripts/zalenium.sh
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ SELENIUM_IMAGE_NAME=${SELENIUM_IMAGE_NAME:-"elgalu/selenium"}
MAX_TEST_SESSIONS=${MAX_TEST_SESSIONS:-1}
DESIRED_CONTAINERS=${DESIRED_CONTAINERS:-2}
MAX_DOCKER_SELENIUM_CONTAINERS=${MAX_DOCKER_SELENIUM_CONTAINERS:-10}
SWARM_OVERLAY_NETWORK=${SWARM_OVERLAY_NETWORK:-""}
ZALENIUM_ARTIFACT="$(pwd)/${project.build.finalName}.jar"
SAUCE_LABS_ENABLED=${SAUCE_LABS_ENABLED:-false}
BROWSER_STACK_ENABLED=${BROWSER_STACK_ENABLED:-false}
Expand Down Expand Up @@ -383,6 +384,7 @@ StartUp()

export ZALENIUM_DESIRED_CONTAINERS=${DESIRED_CONTAINERS}
export ZALENIUM_MAX_DOCKER_SELENIUM_CONTAINERS=${MAX_DOCKER_SELENIUM_CONTAINERS}
export ZALENIUM_SWARM_OVERLAY_NETWORK=${SWARM_OVERLAY_NETWORK}
export ZALENIUM_VIDEO_RECORDING_ENABLED=${VIDEO_RECORDING_ENABLED}
export ZALENIUM_TZ=${TZ}
export ZALENIUM_SCREEN_WIDTH=${SCREEN_WIDTH}
Expand Down Expand Up @@ -635,6 +637,7 @@ StartUp()
# Gathering the options used to start Zalenium, in order to learn about the used options
ZALENIUM_START_COMMAND="zalenium.sh --desiredContainers $DESIRED_CONTAINERS
--maxDockerSeleniumContainers $MAX_DOCKER_SELENIUM_CONTAINERS --maxTestSessions $MAX_TEST_SESSIONS
--swarmOverlayNetwork $SWARM_OVERLAY_NETWORK
--sauceLabsEnabled $SAUCE_LABS_ENABLED --browserStackEnabled $BROWSER_STACK_ENABLED
--testingBotEnabled $TESTINGBOT_ENABLED --cbtEnabled $CBT_ENABLED
--videoRecordingEnabled $VIDEO_RECORDING_ENABLED
Expand Down Expand Up @@ -818,6 +821,7 @@ function usage()
echo -e "\t start <options, see below>"
echo -e "\t --desiredContainers -> Number of nodes/containers created on startup. Default is 2."
echo -e "\t --maxDockerSeleniumContainers -> Max number of docker-selenium containers running at the same time. Default is 10."
echo -e "\t --swarmOverlayNetwork -> Netowrk used for the swarm."
echo -e "\t --sauceLabsEnabled -> Determines if the Sauce Labs node is started. Defaults to 'false'."
echo -e "\t --browserStackEnabled -> Determines if the Browser Stack node is started. Defaults to 'false'."
echo -e "\t --testingBotEnabled -> Determines if the TestingBot node is started. Defaults to 'false'."
Expand Down Expand Up @@ -873,6 +877,9 @@ case ${SCRIPT_ACTION} in
--maxDockerSeleniumContainers)
MAX_DOCKER_SELENIUM_CONTAINERS=${VALUE}
;;
--swarmOverlayNetwork)
SWARM_OVERLAY_NETWORK=${VALUE}
;;
--sauceLabsEnabled)
SAUCE_LABS_ENABLED=${VALUE}
;;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@
import com.google.common.annotations.VisibleForTesting;

import de.zalando.ep.zalenium.container.kubernetes.KubernetesContainerClient;
import de.zalando.ep.zalenium.container.swarm.SwarmContainerClient;
import de.zalando.ep.zalenium.container.swarm.SwarmUtilities;
import de.zalando.ep.zalenium.util.Environment;
import io.fabric8.kubernetes.client.DefaultKubernetesClient;

Expand All @@ -15,12 +17,16 @@ public class ContainerFactory {

private static KubernetesContainerClient kubernetesContainerClient;
private static Supplier<DockerContainerClient> dockerContainerClient = DockerContainerClient::new;
private static Supplier<SwarmContainerClient> swarmContainerClient = SwarmContainerClient::new;

public static ContainerClient getContainerClient() {

if (isKubernetes.get()) {
return createKubernetesContainerClient();
}
else if (SwarmUtilities.isSwarmActive()) {
return createSwarmContainerClient();
}
else {
return createDockerContainerClient();
}
Expand Down Expand Up @@ -50,6 +56,12 @@ private static KubernetesContainerClient createKubernetesContainerClient() {
return kubernetesContainerClient;
}

private static SwarmContainerClient createSwarmContainerClient() {
SwarmContainerClient dockerClient = ContainerFactory.swarmContainerClient.get();
dockerClient.initialiseContainerEnvironment();
return dockerClient;
}

@VisibleForTesting
public static void setDockerContainerClient(Supplier<DockerContainerClient> dockerContainerClient) {
ContainerFactory.dockerContainerClient = dockerContainerClient;
Expand Down
Loading