public static String loadLayer(DockerSettings docker,
String repoName,
String uuid,
String digest,
String state,
File layer){
try {
URI uri = new URI(format("%s/v2/%s/blobs/uploads/%s",
docker.host, repoName, uuid));
int timeout = 5;
RequestConfig config = RequestConfig.custom()
.setConnectTimeout(timeout * 1000)
.setConnectionRequestTimeout(timeout * 1000)
.setSocketTimeout(timeout * 1000).build();
CloseableHttpClient httpClient = HttpClientBuilder.create().setDefaultRequestConfig(config).build();
HttpPut httpPut = new HttpPut(uri);
httpPut.setHeader("Authorization", "Basic " + docker.token);
httpPut.setHeader("Content-Type", "application/octet-stream");
MultipartEntityBuilder builder = MultipartEntityBuilder.create();
builder.setMode(HttpMultipartMode.BROWSER_COMPATIBLE);
builder.addBinaryBody("", layer, ContentType.APPLICATION_OCTET_STREAM, layer.getAbsolutePath());
builder.addTextBody("digest", digest);
builder.addTextBody("_state", state);
HttpEntity entity = builder.build();
httpPut.setEntity(entity);
HttpResponse resp = httpClient.execute(httpPut);
System.out.println(resp);
int status = resp.getStatusLine().getStatusCode();
String respText = resp.getStatusLine().getReasonPhrase();
String result = "";
if (status >= 400) {
throw new RuntimeException(format("Запрос %s выполнился с ошибкой %s: %s", uri, status, respText));
}
return result;
} catch (Exception e) {
throw new RuntimeException(e);
}
}