Skip to content

Commit

Permalink
Add 'force' when removing images
Browse files Browse the repository at this point in the history
  • Loading branch information
rhuss committed Oct 24, 2014
1 parent 39b1b21 commit 9cc650e
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -128,10 +128,11 @@ public interface DockerAccess {
* Remove an image from this docker installation
*
* @param image image to remove
* @param force if set to true remove containers as well (only the first vararg is evaluated)
* @return true if an image was removed, false if none was removed
* @throws DockerAccessException if an image cannot be removed
*/
boolean removeImage(String image) throws DockerAccessException;
boolean removeImage(String image, boolean ... force) throws DockerAccessException;

/**
* Lifecycle method for this access class which must be called before any other method is called.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -180,8 +180,9 @@ public void pushImage(String image, AuthConfig authConfig) throws DockerAccessEx
}

/** {@inheritDoc} */
public boolean removeImage(String image) throws DockerAccessException {
HttpUriRequest req = newDelete(baseUrl + "/images/" + image);
public boolean removeImage(String image, boolean ... forceOpt) throws DockerAccessException {
boolean force = forceOpt != null && forceOpt.length > 0 && forceOpt[0];
HttpUriRequest req = newDelete(baseUrl + "/images/" + image + (force ? "?force=1" : ""));
HttpResponse resp = request(req);
checkReturnCode("Removing image " + image, resp, 200, 404);
if (log.isDebugEnabled()) {
Expand Down Expand Up @@ -519,13 +520,23 @@ public void process(JSONObject json) {
}
} else if (json.has("stream")) {
String message = json.getString("stream");
while (message.endsWith("\n")) {
message = message.substring(0,message.length() - 1);
log.debug(trim(message));
} else if (json.has("status")) {
String status = trim(json.getString("status"));
String id = json.has("id") ? json.getString("id") : null;
if (status.matches("^.*(Download|Pulling).*")) {
log.info(" " + (id != null ? id + " " : "") + status);
}
log.debug(message);
}
}

private String trim(String message) {
while (message.endsWith("\n")) {
message = message.substring(0,message.length() - 1);
}
return message;
}

public String getErrorMessage(StatusLine status) {
return "Error while building image '" + image + "' (code: " + status.getStatusCode()
+ ", " + status.getReasonPhrase() + ")";
Expand Down

0 comments on commit 9cc650e

Please sign in to comment.