Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
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
18 changes: 10 additions & 8 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ install: true

env:
global:
- CODECOV=true
- DOCKER_TLS_VERIFY=""
# The next declaration is the encrypted COVERITY_SCAN_TOKEN, created
# via the "travis encrypt" command using the project repo's public key
Expand All @@ -21,12 +22,13 @@ env:
- COVERITY_SCAN_NOTIFICATION_EMAIL="kanstantsin.sha@gmail.com"

matrix:
- repo="main" DOCKER_HOST="tcp://127.0.0.1:2375" DOCKER_VERSION="1.12.1-0~trusty" CODECOV=true
- repo="main" DOCKER_HOST="unix:///var/run/docker.sock" DOCKER_VERSION="1.12.1-0~trusty" CODECOV=true
- repo="main" DOCKER_HOST="tcp://127.0.0.1:2375" DOCKER_VERSION="1.11.2-0~trusty" DEPLOY=true COVERITY=true CODECOV=true
- repo="main" DOCKER_HOST="unix:///var/run/docker.sock" DOCKER_VERSION="1.11.2-0~trusty" CODECOV=true
- repo="main" DOCKER_HOST="tcp://127.0.0.1:2375" DOCKER_VERSION="1.10.3-0~trusty" CODECOV=true
- repo="main" DOCKER_HOST="unix:///var/run/docker.sock" DOCKER_VERSION="1.10.3-0~trusty" CODECOV=true
- repo="main" DOCKER_HOST="tcp://127.0.0.1:2377" DOCKER_VERSION="1.12.1-0~trusty" SWARM_VERSION="1.2.5"
- repo="main" DOCKER_HOST="tcp://127.0.0.1:2375" DOCKER_VERSION="1.12.1-0~trusty"
- repo="main" DOCKER_HOST="unix:///var/run/docker.sock" DOCKER_VERSION="1.12.1-0~trusty"
- repo="main" DOCKER_HOST="tcp://127.0.0.1:2375" DOCKER_VERSION="1.11.2-0~trusty" DEPLOY=true COVERITY=true
- repo="main" DOCKER_HOST="unix:///var/run/docker.sock" DOCKER_VERSION="1.11.2-0~trusty"
- repo="main" DOCKER_HOST="tcp://127.0.0.1:2375" DOCKER_VERSION="1.10.3-0~trusty"
- repo="main" DOCKER_HOST="unix:///var/run/docker.sock" DOCKER_VERSION="1.10.3-0~trusty"
# - repo="testing" DOCKER_HOST="tcp://127.0.0.1:2375"
# - repo="testing" DOCKER_HOST="unix:///var/run/docker.sock"
# - repo="experimental" DOCKER_HOST="tcp://127.0.0.1:2375"
Expand All @@ -48,5 +50,5 @@ script:
after_success:
- ./.travis/travis-after-success.sh

after_script:
- sudo cat /var/log/upstart/docker.log
#after_script:
# - sudo cat /var/log/upstart/docker.log
87 changes: 83 additions & 4 deletions .travis/travis-before-install.sh
Original file line number Diff line number Diff line change
@@ -1,19 +1,32 @@
#!/usr/bin/env bash

SWARM_VERSION="${SWARM_VERSION:-}"
FAST_BUILD="${FAST_BUILD:-}"

## fix coverity issue
sudo apt-get install -y -q ca-certificates

export HOST_PORT=2375
echo -n | openssl s_client -connect scan.coverity.com:443 | sed -ne '/-BEGIN CERTIFICATE-/,/-END CERTIFICATE-/p' | sudo tee -a /etc/ssl/certs/ca-certificates.crt
##


if [ "$FAST_BUILD" == true ]; then
if [ "$FAST_BUILD" == "true" ]; then
echo "Fast build, skipping docker installations."
exit 0
fi

set -exu

sudo ip a ls
sudo ip r ls
sudo ss -antpl

export HOST_PORT="2375"
export SWARM_PORT="2377"
export HOST_IP="$(ip a show dev eth0 | grep "inet\b" | awk '{print $2}' | cut -d/ -f1)"
# because of swarm use docker-engine directly
export PRE_DOCKER_HOST="$DOCKER_HOST"
export DOCKER_HOST="tcp://127.0.0.1:${HOST_PORT}"


docker info
docker version

Expand Down Expand Up @@ -89,3 +102,69 @@ registry.email=${registry_email}
registry.url=https://index.docker.io/v1/

EOF

if [[ -n $SWARM_VERSION ]]; then
# export SWARM_PORT="${PRE_DOCKER_HOST##*:}"

docker pull swarm

# # kv store https://docs.docker.com/v1.11/engine/userguide/networking/get-started-overlay/
# docker run -d \
# -p "8500:8500" \
# -h "consul" \
# --name=consul \
# progrium/consul -server -bootstrap
#
# sleep 5

# SWARM_TOKEN=$(docker run swarm c)

# docker run \
# -d \
# --name=swarm_manager \
# -p ${SWARM_PORT}:2375 \
# "swarm:${SWARM_VERSION}" \
# manage token://${SWARM_TOKEN}

docker run \
-d \
-p ${SWARM_PORT}:2375 \
--name=swarm_manager \
swarm manage --engine-refresh-min-interval "3s" --engine-refresh-max-interval "6s" "nodes://${HOST_IP}:${HOST_PORT}"
# swarm manage --engine-refresh-min-interval "3s" --engine-refresh-max-interval "6s" "consul://${HOST_IP}:8500"

# join engine to swarm
docker run \
-d \
"--name=swarm_join" \
"swarm:${SWARM_VERSION}" \
join --advertise="${HOST_IP}:${HOST_PORT}" --delay="0s" --heartbeat "5s" "nodes://${HOST_IP}:${HOST_PORT}"
# join --advertise="${HOST_IP}:${HOST_PORT}" --delay="0s" --heartbeat "5s" "token://${SWARM_TOKEN}"

docker run --rm \
"swarm:${SWARM_VERSION}" list "nodes://${HOST_IP}:${HOST_PORT}"

docker ps -a
sudo ss -antpl

sleep 30

docker logs swarm_join
docker logs swarm_manager
# docker logs consul

# switch to swarm connection
DOCKER_HOST="$PRE_DOCKER_HOST"

docker version
docker info

NODES=$(docker info | grep "Nodes:" | awk '{ print $2 }')
if [[ $NODES -eq "0" ]]; then
echo "Swarm didn't connect"
exit 1
fi

# test via swarm
docker pull busybox
fi
63 changes: 55 additions & 8 deletions src/main/java/com/github/dockerjava/api/DockerClient.java
Original file line number Diff line number Diff line change
@@ -1,12 +1,5 @@
package com.github.dockerjava.api;

import java.io.Closeable;
import java.io.File;
import java.io.IOException;
import java.io.InputStream;

import javax.annotation.Nonnull;

import com.github.dockerjava.api.command.AttachContainerCmd;
import com.github.dockerjava.api.command.AuthCmd;
import com.github.dockerjava.api.command.BuildImageCmd;
Expand All @@ -25,12 +18,16 @@
import com.github.dockerjava.api.command.ExecCreateCmd;
import com.github.dockerjava.api.command.ExecStartCmd;
import com.github.dockerjava.api.command.InfoCmd;
import com.github.dockerjava.api.command.InitializeSwarmCmd;
import com.github.dockerjava.api.command.InspectContainerCmd;
import com.github.dockerjava.api.command.InspectExecCmd;
import com.github.dockerjava.api.command.InspectImageCmd;
import com.github.dockerjava.api.command.InspectNetworkCmd;
import com.github.dockerjava.api.command.InspectSwarmCmd;
import com.github.dockerjava.api.command.InspectVolumeCmd;
import com.github.dockerjava.api.command.JoinSwarmCmd;
import com.github.dockerjava.api.command.KillContainerCmd;
import com.github.dockerjava.api.command.LeaveSwarmCmd;
import com.github.dockerjava.api.command.ListContainersCmd;
import com.github.dockerjava.api.command.ListImagesCmd;
import com.github.dockerjava.api.command.ListNetworksCmd;
Expand All @@ -45,6 +42,7 @@
import com.github.dockerjava.api.command.RemoveImageCmd;
import com.github.dockerjava.api.command.RemoveNetworkCmd;
import com.github.dockerjava.api.command.RemoveVolumeCmd;
import com.github.dockerjava.api.command.RenameContainerCmd;
import com.github.dockerjava.api.command.RestartContainerCmd;
import com.github.dockerjava.api.command.SaveImageCmd;
import com.github.dockerjava.api.command.SearchImagesCmd;
Expand All @@ -55,14 +53,21 @@
import com.github.dockerjava.api.command.TopContainerCmd;
import com.github.dockerjava.api.command.UnpauseContainerCmd;
import com.github.dockerjava.api.command.UpdateContainerCmd;
import com.github.dockerjava.api.command.UpdateSwarmCmd;
import com.github.dockerjava.api.command.VersionCmd;
import com.github.dockerjava.api.command.WaitContainerCmd;
import com.github.dockerjava.api.command.RenameContainerCmd;
import com.github.dockerjava.api.exception.DockerException;
import com.github.dockerjava.api.model.AuthConfig;
import com.github.dockerjava.api.model.Identifier;
import com.github.dockerjava.api.model.SwarmSpec;
import com.github.dockerjava.core.RemoteApiVersion;

import javax.annotation.Nonnull;
import java.io.Closeable;
import java.io.File;
import java.io.IOException;
import java.io.InputStream;

// https://godoc.org/github.com/fsouza/go-dockerclient
public interface DockerClient extends Closeable {

Expand Down Expand Up @@ -251,6 +256,48 @@ public interface DockerClient extends Closeable {

DisconnectFromNetworkCmd disconnectFromNetworkCmd();

/**
* Enables swarm mode for the docker engine and creates a new swarm cluster
*
* @since 1.24
* @param swarmSpec the specification for the swarm
* @return the command
*/
InitializeSwarmCmd initializeSwarmCmd(SwarmSpec swarmSpec);
Copy link
Member

@KostyaSha KostyaSha Sep 1, 2016

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sorry, missed that it can be enabled in runtime (because also thinking about standard swarm tests that people also asking), thought that it could be done only during startup.
But i fear that other standard tests that may be running in parallel may fail.

SwarmMode related tests should be grouped into new group/category imho. And maybe we should create separate travis runs?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh, the tests are run in parallel? That's complicated even for the swarm tests themselves, because they need to initialize/join/leave swarm mode a few times. How about running each test in its own dind? I added a nice helper method to spin up (and automatically remove) dinds because I need two docker engines in the Join test, anyway.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Dind will have performance issues + port exposure issues. I would at all suggest to migrate to Junit with @Rule and @Resources as i already have a lot of working solutions in yet-another-docker-plugin for it.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

See https://github.com/KostyaSha/yet-another-docker-plugin/blob/1931326a58c43093f3aff5e5c993ada2eb46f8c9/yet-another-docker-its/src/test/java/com/github/kostyasha/it/tests/NginxRegistryTest.java#L62-L115

About order as i understand all tests are not ordered by it's nature.
If swarm mode doesn't affect standard docker-engine mode, then it's fine.
It also maybe possible to do something in scopes of Suite afair or testng has something specific...


/**
* Gets information about the swarm the docker engine is currently in
*
* @since 1.24
* @return the command
*/
InspectSwarmCmd inspectSwarmCmd();

/**
* Enables swarm mode for the docker engine and joins an existing swarm cluster
*
* @since 1.24
* @return the command
*/
JoinSwarmCmd joinSwarmCmd();

/**
* Disables swarm node for the docker engine and leaves the swarm cluster
*
* @since 1.24
* @return the command
*/
LeaveSwarmCmd leaveSwarmCmd();

/**
* Updates the swarm specification
*
* @since 1.24
* @param swarmSpec the specification for the swarm
* @return the command
*/
UpdateSwarmCmd updateSwarmCmd(SwarmSpec swarmSpec);

@Override
void close() throws IOException;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,16 @@ public interface DockerCmdExecFactory extends Closeable {

DisconnectFromNetworkCmd.Exec createDisconnectFromNetworkCmdExec();

InitializeSwarmCmd.Exec createInitializeSwarmCmdExec();

InspectSwarmCmd.Exec createInspectSwarmCmdExec();

JoinSwarmCmd.Exec createJoinSwarmCmdExec();

LeaveSwarmCmd.Exec createLeaveSwarmCmdExec();

UpdateSwarmCmd.Exec createUpdateSwarmCmdExec();

@Override
void close() throws IOException;

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
package com.github.dockerjava.api.command;


import com.github.dockerjava.api.model.SwarmSpec;

import javax.annotation.CheckForNull;

public interface InitializeSwarmCmd extends SyncDockerCmd<Void> {

@CheckForNull
String getListenAddr();

InitializeSwarmCmd withListenAddr(String listenAddr);

@CheckForNull
String getAdvertiseAddr();

InitializeSwarmCmd withAdvertiseAddr(String advertiseAddr);

@CheckForNull
Boolean isForceNewCluster();

InitializeSwarmCmd withForceNewCluster(Boolean forceNewCluster);

@CheckForNull
SwarmSpec getSwarmSpec();

InitializeSwarmCmd withSwarmSpec(SwarmSpec swarmSpec);

@Override
Void exec();

interface Exec extends DockerCmdSyncExec<InitializeSwarmCmd, Void> {

}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
package com.github.dockerjava.api.command;


import com.github.dockerjava.api.model.Swarm;

/**
* Inspect a swarm.
*/
public interface InspectSwarmCmd extends SyncDockerCmd<Swarm> {

@Override
Swarm exec();

interface Exec extends DockerCmdSyncExec<InspectSwarmCmd, Swarm> {
}


}
34 changes: 34 additions & 0 deletions src/main/java/com/github/dockerjava/api/command/JoinSwarmCmd.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
package com.github.dockerjava.api.command;


import javax.annotation.CheckForNull;
import java.util.List;

public interface JoinSwarmCmd extends SyncDockerCmd<Void> {

@CheckForNull
String getListenAddr();

JoinSwarmCmd withListenAddr(String listenAddr);

@CheckForNull
String getAdvertiseAddr();

JoinSwarmCmd withAdvertiseAddr(String advertiseAddr);

@CheckForNull
List<String> getRemoteAddrs();

JoinSwarmCmd withRemoteAddrs(List<String> remoteAddrs);

@CheckForNull
String getJoinToken();

JoinSwarmCmd withJoinToken(String joinToken);

@Override
Void exec();

interface Exec extends DockerCmdSyncExec<JoinSwarmCmd, Void> {
}
}
18 changes: 18 additions & 0 deletions src/main/java/com/github/dockerjava/api/command/LeaveSwarmCmd.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
package com.github.dockerjava.api.command;


import javax.annotation.CheckForNull;

public interface LeaveSwarmCmd extends SyncDockerCmd<Void> {

@CheckForNull
Boolean hasForceEnabled();

LeaveSwarmCmd withForceEnabled(Boolean force);

@Override
Void exec();

interface Exec extends DockerCmdSyncExec<LeaveSwarmCmd, Void> {
}
}
Loading