Skip to content

Commit

Permalink
Fix fabric8io#986 : Create volumes with proper configuration during "…
Browse files Browse the repository at this point in the history
…docker:start"
  • Loading branch information
rohanKanojia committed Apr 22, 2018
1 parent b57bc9e commit 5f45bfe
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 0 deletions.
1 change: 1 addition & 0 deletions doc/changelog.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

* **0.25.2** (2018-04-14)
- Fix for docker login issue with index.docker.io using a credential helper ([#946](https://github.com/fabric8io/docker-maven-plugin/issues/946))
- Fix for creating volumes with proper configuration during "docker:start" ([#986](https://github.com/fabric8io/docker-maven-plugin/issues/986))

* **0.25.1** (2018-04-12)
- Fix regression which broke labels and env with space ([#988](https://github.com/fabric8io/docker-maven-plugin/issues/988))
Expand Down
25 changes: 25 additions & 0 deletions src/main/java/io/fabric8/maven/docker/StartMojo.java
Original file line number Diff line number Diff line change
Expand Up @@ -322,6 +322,11 @@ private Queue<ImageConfiguration> prepareStart(ServiceHub hub, QueryService quer
queryService.hasImage(imageConfig.getName()));

NetworkConfig config = runConfig.getNetworkingConfig();
RunVolumeConfiguration runVolumeConfig = runConfig.getVolumeConfiguration();
if(!runVolumeConfig.getBind().isEmpty()) {
List<VolumeConfiguration> volumes = getVolumes();
createVolumesAsPerVolumeBinds(hub, runVolumeConfig.getBind(), volumes);
}
if (autoCreateCustomNetworks && config.isCustomNetwork()) {
runService.createCustomNetworkIfNotExistant(config.getCustomNetwork());
}
Expand All @@ -331,6 +336,26 @@ private Queue<ImageConfiguration> prepareStart(ServiceHub hub, QueryService quer
return imagesWaitingToStart;
}

private void createVolumesAsPerVolumeBinds(ServiceHub hub, List<String> volumeBinds, List<VolumeConfiguration> volumesConfigs)
throws DockerAccessException {
Map<String, Integer> aIndexMap = new HashMap();
for(Integer aIndex = 0; aIndex < volumesConfigs.size(); aIndex++)
aIndexMap.put(volumesConfigs.get(aIndex).getName(), aIndex);

for(String aVolumeBind : volumeBinds) {
if(aVolumeBind.contains(":")) {
aVolumeBind = aVolumeBind.substring(0, aVolumeBind.indexOf(":"));
}
Integer nVolumeConfigIndex = aIndexMap.get(aVolumeBind);
if(nVolumeConfigIndex != null && nVolumeConfigIndex >= 0 && nVolumeConfigIndex < volumesConfigs.size()) {
VolumeConfiguration aVolumeConfig = volumesConfigs.get(nVolumeConfigIndex);
hub.getVolumeService().createVolume(aVolumeConfig);
} else {
log.warn("No volumeBind found with name : " + aVolumeBind + " " + aIndexMap.toString());
}
}
}

private String determinePullPolicy(RunImageConfiguration runConfig) {
return runConfig.getImagePullPolicy() != null ? runConfig.getImagePullPolicy() : imagePullPolicy;
}
Expand Down

0 comments on commit 5f45bfe

Please sign in to comment.