|
|
@@ -111,29 +111,13 @@ public class DockerImpl implements Docker {
|
|
|
@Override
|
|
|
public void push(String image) throws Exception {
|
|
|
try {
|
|
|
- ResultCallback.Adapter<PushResponseItem> callback = new ResultCallback.Adapter<>() {
|
|
|
- @Override
|
|
|
- public void onNext(PushResponseItem object) {
|
|
|
- PushResponseItem.ErrorDetail errorDetail = object.getErrorDetail();
|
|
|
- if (errorDetail != null) {
|
|
|
- log.info("{} {}", errorDetail.getCode(), errorDetail.getMessage());
|
|
|
- } else {
|
|
|
- log.info("{} {} {}", object.getStatus(), object.getId(), object.getProgressDetail());
|
|
|
- }
|
|
|
- }
|
|
|
-
|
|
|
- @Override
|
|
|
- public void onComplete() {
|
|
|
- super.onComplete();
|
|
|
- }
|
|
|
-
|
|
|
- @Override
|
|
|
- public void onError(Throwable throwable) {
|
|
|
- throwable.printStackTrace();
|
|
|
- }
|
|
|
- };
|
|
|
+ ResultCallback.Adapter<PushResponseItem> callback = new PushCallback();
|
|
|
dockerClient.pushImageCmd(image).exec(callback).awaitCompletion();
|
|
|
- //dockerClient.pushImageCmd(image).exec(new PushImageResultCallback()).awaitCompletion();
|
|
|
+ PushCallback pushCallback = (PushCallback) callback;
|
|
|
+ int code = pushCallback.getCode();
|
|
|
+ if (code != 0) {
|
|
|
+ throw new Exception(pushCallback.getMsg());
|
|
|
+ }
|
|
|
} catch (InterruptedException e) {
|
|
|
throw new Exception(ExceptionUtil.errorMsg(e));
|
|
|
}
|
|
|
@@ -321,4 +305,43 @@ public class DockerImpl implements Docker {
|
|
|
String containerId = container.getId();
|
|
|
return dockerClient.inspectContainerCmd(containerId).exec();
|
|
|
}
|
|
|
+
|
|
|
+ static class PushCallback extends ResultCallback.Adapter<PushResponseItem> {
|
|
|
+ private int code;
|
|
|
+ private String msg;
|
|
|
+
|
|
|
+ public PushCallback() {
|
|
|
+ this.code = 0;
|
|
|
+ }
|
|
|
+
|
|
|
+ public int getCode() {
|
|
|
+ return code;
|
|
|
+ }
|
|
|
+
|
|
|
+ public String getMsg() {
|
|
|
+ return msg;
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public void onNext(PushResponseItem object) {
|
|
|
+ PushResponseItem.ErrorDetail errorDetail = object.getErrorDetail();
|
|
|
+ if (errorDetail != null) {
|
|
|
+ log.info("error: {} {}", errorDetail.getCode(), errorDetail.getMessage());
|
|
|
+ code = 1;
|
|
|
+ msg = errorDetail.getMessage();
|
|
|
+ } else {
|
|
|
+ log.info("info: {} {} {}", object.getStatus(), object.getId(), object.getProgressDetail());
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public void onComplete() {
|
|
|
+ super.onComplete();
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public void onError(Throwable throwable) {
|
|
|
+ throwable.printStackTrace();
|
|
|
+ }
|
|
|
+ }
|
|
|
}
|