From 7e91ba3c33a5853b6b606d352a9ade80a415ac56 Mon Sep 17 00:00:00 2001 From: Edwin Wiles Date: Wed, 24 May 2017 21:28:46 -0400 Subject: [PATCH 1/3] Don't fail build if volume-clean fails. This fix is admittedly simplistic. It does not take into account any of the other possible causes for an exception. However, if you are using volume-clean, chances are you're using volume-create, or many of the other goals provided by DMP. In that case, you will almost certainly receive errors pointing you at the real problem. --- .../io/fabric8/maven/docker/service/VolumeService.java | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/src/main/java/io/fabric8/maven/docker/service/VolumeService.java b/src/main/java/io/fabric8/maven/docker/service/VolumeService.java index bf6707005..5583b21c8 100644 --- a/src/main/java/io/fabric8/maven/docker/service/VolumeService.java +++ b/src/main/java/io/fabric8/maven/docker/service/VolumeService.java @@ -33,6 +33,14 @@ public String createVolume(VolumeConfiguration vc) throws DockerAccessException } public void removeVolume(String volumeName) throws DockerAccessException { - docker.removeVolume(volumeName); + try { + docker.removeVolume(volumeName); + } catch ( DockerAccessException dae ) { + // IGNORE + // If you're using volume-clean, the most likely cause for a failure + // is that the volume doesn't exist. In that case, the build should + // not be failed. For any other probable cause of failure, another + // goal will almost certainly point you at the real problem. + } } } From d45a4dd8a88eeb2c1c52492e28bf42f4b1d7d021 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Roland=20Hu=C3=9F?= Date: Sat, 4 Nov 2017 12:37:31 +0100 Subject: [PATCH 2/3] fix: Allow 404 as valid response code when removing a volume --- .../io/fabric8/maven/docker/access/DockerAccess.java | 2 +- .../docker/access/hc/DockerAccessWithHcClient.java | 2 +- .../io/fabric8/maven/docker/service/VolumeService.java | 10 +--------- 3 files changed, 3 insertions(+), 11 deletions(-) diff --git a/src/main/java/io/fabric8/maven/docker/access/DockerAccess.java b/src/main/java/io/fabric8/maven/docker/access/DockerAccess.java index 5e1868a9c..cd4c88a2a 100644 --- a/src/main/java/io/fabric8/maven/docker/access/DockerAccess.java +++ b/src/main/java/io/fabric8/maven/docker/access/DockerAccess.java @@ -272,7 +272,7 @@ void copyArchive(String containerId, File archive, String targetPath) String createVolume(VolumeCreateConfig configuration) throws DockerAccessException; /** - * removes a volume + * Removes a volume. It is a no-op if the volume does not exist. * @param name volume name to remove * @throws DockerAccessException if the volume could not be removed */ diff --git a/src/main/java/io/fabric8/maven/docker/access/hc/DockerAccessWithHcClient.java b/src/main/java/io/fabric8/maven/docker/access/hc/DockerAccessWithHcClient.java index 43ae96572..960291d2c 100644 --- a/src/main/java/io/fabric8/maven/docker/access/hc/DockerAccessWithHcClient.java +++ b/src/main/java/io/fabric8/maven/docker/access/hc/DockerAccessWithHcClient.java @@ -524,7 +524,7 @@ public String createVolume(VolumeCreateConfig containerConfig) public void removeVolume(String name) throws DockerAccessException { try { String url = urlBuilder.removeVolume(name); - delegate.delete(url, HTTP_NO_CONTENT); + delegate.delete(url, HTTP_NO_CONTENT, HTTP_NOT_FOUND); } catch (IOException e) { throw new DockerAccessException(e, "Unable to remove volume [%s]", name); } diff --git a/src/main/java/io/fabric8/maven/docker/service/VolumeService.java b/src/main/java/io/fabric8/maven/docker/service/VolumeService.java index 5583b21c8..bf6707005 100644 --- a/src/main/java/io/fabric8/maven/docker/service/VolumeService.java +++ b/src/main/java/io/fabric8/maven/docker/service/VolumeService.java @@ -33,14 +33,6 @@ public String createVolume(VolumeConfiguration vc) throws DockerAccessException } public void removeVolume(String volumeName) throws DockerAccessException { - try { - docker.removeVolume(volumeName); - } catch ( DockerAccessException dae ) { - // IGNORE - // If you're using volume-clean, the most likely cause for a failure - // is that the volume doesn't exist. In that case, the build should - // not be failed. For any other probable cause of failure, another - // goal will almost certainly point you at the real problem. - } + docker.removeVolume(volumeName); } } From 0e67badf94befddfa31a8372415b816ab63e61ff Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Roland=20Hu=C3=9F?= Date: Sat, 4 Nov 2017 12:39:35 +0100 Subject: [PATCH 3/3] chore: changelog update --- doc/changelog.md | 1 + 1 file changed, 1 insertion(+) diff --git a/doc/changelog.md b/doc/changelog.md index d93055425..ee55ea3aa 100644 --- a/doc/changelog.md +++ b/doc/changelog.md @@ -8,6 +8,7 @@ - Preserve leading whitespace in logs (#875) - Maven property interpolation in Dockerfiles (#877) - Allow parameters for the log prefix (#890) + - When removing a volume don't error if the volume does not exist (#788) * **0.22.1** (2017-08-28) - Allow Docker compose version "2", too ([#829](https://github.com/fabric8io/docker-maven-plugin/issues/829))