Skip to content

Commit

Permalink
Gravatarfix for issue #75
Browse files Browse the repository at this point in the history
- removed checking for existence of docker volume
- small refactoring
  • Loading branch information
sloukam committed Dec 5, 2018
1 parent 4052c48 commit 651fc67
Show file tree
Hide file tree
Showing 4 changed files with 4 additions and 34 deletions.
Expand Up @@ -88,27 +88,10 @@ private static Map<String, String> lineToMap(String line) {
return map;
}

public List<Mount> toMount(List<Volume> volumes) {

if (Util.isEmpty(volumes)) {
LOG.debug("No volumes to mount.");
return Collections.emptyList();
}

final Map<String, Volume> volumeMap = volumes.stream().collect(Collectors.toMap(o -> o.name(), o -> o));
public List<Mount> toMount() {
final List<Mount> mounts = new ArrayList<>();

for (DockerMount dockerMount : this) {
if (dockerMount.type().equals("volume")) {
final Volume volume = volumeMap.get(dockerMount.source);

if (volume == null) {
throw new RuntimeException(format("Volume with name `{0}` does not exist.", dockerMount.source()));
}

LOG.debug(format("Using volume `{0}`.", dockerMount.source()));
}

final Mount mount = Mount.builder()
.type(dockerMount.type())
.source(dockerMount.source())
Expand Down
Expand Up @@ -113,7 +113,7 @@ public static DockerService create(CreateAgentRequest request, PluginSettings se
if (dockerApiVersionAtLeast(docker, "1.26")) {
containerSpecBuilder.hosts(new Hosts().hosts(request.properties().get("Hosts")));
final DockerMounts dockerMounts = DockerMounts.fromString(request.properties().get("Mounts"));
containerSpecBuilder.mounts(dockerMounts.toMount(docker.listVolumes().volumes()));
containerSpecBuilder.mounts(dockerMounts.toMount());
final DockerSecrets dockerSecrets = DockerSecrets.fromString(request.properties().get("Secrets"));
containerSpecBuilder.secrets(dockerSecrets.toSecretBind(docker.listSecrets()));
} else {
Expand Down
Expand Up @@ -53,7 +53,7 @@ public ValidationResult validate(Map<String, String> elasticProfile) {
throw new RuntimeException("Docker volume mount requires api version 1.26 or higher.");
}

dockerMounts.toMount(dockerClient.listVolumes().volumes());
dockerMounts.toMount();
}
} catch (Exception e) {
validationResult.addError("Mounts", e.getMessage());
Expand Down
Expand Up @@ -79,7 +79,7 @@ public void shouldBuildMountFromDockerMount() throws Exception {

when(volume.name()).thenReturn("namedVolume");

final List<Mount> mounts = dockerMounts.toMount(asList(volume));
final List<Mount> mounts = dockerMounts.toMount();

assertThat(mounts, hasSize(2));
assertThat(mounts.get(0).type(), is("volume"));
Expand All @@ -92,17 +92,4 @@ public void shouldBuildMountFromDockerMount() throws Exception {
assertThat(mounts.get(1).target(), is("/path/in/container2"));
assertThat(mounts.get(1).readOnly(), is(true));
}

@Test
public void shouldErrorOutWhenVolumeDoesNotExist() throws Exception {
final DockerMounts dockerMounts = DockerMounts.fromString("source=namedVolume, target=/path/in/container\nsource=namedVolume2, target=/path/in/container2");
final Volume volume = mock(Volume.class);

when(volume.name()).thenReturn("namedVolume");

thrown.expect(RuntimeException.class);
thrown.expectMessage("Volume with name `namedVolume2` does not exist.");

dockerMounts.toMount(asList(volume));
}
}

0 comments on commit 651fc67

Please sign in to comment.