Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Return ContainerConfig exposedPorts if no HostConfig boundPorts found #210

Merged
merged 1 commit into from Nov 18, 2015
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
Expand Up @@ -95,6 +95,9 @@ public boolean await() {

switch(this.type) {
case "ping": {
if(ports.getBindingPort() == -1) {
throw new IllegalArgumentException("Can not use polling of type " + type + " on non externally bound port " + ports.getExposedPort());
}
if (!Ping.ping(bindings.getIP(), ports.getBindingPort(), this.pollIterations, this.sleepPollTime,
this.timeUnit)) {
return false;
Expand Down
Expand Up @@ -178,7 +178,7 @@ private void enrichHostPort(Object containerObjectInstance, org.arquillian.cube.
if (hostPortValue > 0) {
final Binding.PortBinding bindingForExposedPort = cube.bindings().getBindingForExposedPort(hostPortValue);

if (bindingForExposedPort != null) {
if (bindingForExposedPort != null && bindingForExposedPort.getBindingPort() != -1) {
field.set(containerObjectInstance, bindingForExposedPort.getBindingPort());
} else {
throw new IllegalArgumentException(String.format("Container Object %s contains field %s annotated with %s but exposed port %s is not exposed on container object.", containerObjectInstance.getClass().getSimpleName(), field.getName(), HostPort.class.getSimpleName(), hostPortValue));
Expand Down
Expand Up @@ -8,6 +8,7 @@
import org.arquillian.cube.spi.Binding;

import com.github.dockerjava.api.command.InspectContainerResponse;
import com.github.dockerjava.api.model.ContainerConfig;
import com.github.dockerjava.api.model.ExposedPort;
import com.github.dockerjava.api.model.HostConfig;

Expand All @@ -22,16 +23,22 @@ private BindingUtil() {
public static Binding binding(DockerClientExecutor executor, String cubeId) {
InspectContainerResponse inspectResponse = executor.getDockerClient().inspectContainerCmd( cubeId ).exec();

HostConfig hostConfig = inspectResponse.getHostConfig();

String dockerIp = getDockerServerIp(executor);
Binding binding = new Binding(dockerIp);

for (Entry<ExposedPort, com.github.dockerjava.api.model.Ports.Binding[]> bind : hostConfig.getPortBindings()
.getBindings().entrySet()) {
com.github.dockerjava.api.model.Ports.Binding[] allBindings = bind.getValue();
for (com.github.dockerjava.api.model.Ports.Binding bindings : allBindings) {
binding.addPortBinding(bind.getKey().getPort(), bindings.getHostPort());
HostConfig hostConfig = inspectResponse.getHostConfig();
if(hostConfig.getPortBindings() != null) {
for (Entry<ExposedPort, com.github.dockerjava.api.model.Ports.Binding[]> bind : hostConfig.getPortBindings()
.getBindings().entrySet()) {
com.github.dockerjava.api.model.Ports.Binding[] allBindings = bind.getValue();
for (com.github.dockerjava.api.model.Ports.Binding bindings : allBindings) {
binding.addPortBinding(bind.getKey().getPort(), bindings.getHostPort());
}
}
} else {
ContainerConfig connectionConfig = inspectResponse.getConfig();
for(ExposedPort port : connectionConfig.getExposedPorts()) {
binding.addPortBinding(port.getPort(), -1);
}
}
return binding;
Expand Down