|
|
|
@ -124,6 +124,13 @@ public class DockerApi { |
|
|
|
return this.jsonStream; |
|
|
|
return this.jsonStream; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
URI buildPlatformJsonUrl(Feature feature, @Nullable ImagePlatform platform, String path) { |
|
|
|
|
|
|
|
if (platform != null && getApiVersion().supports(feature.minimumVersion())) { |
|
|
|
|
|
|
|
return buildUrl(feature, path, "platform", platform.toJson()); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
return buildUrl(path); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
private URI buildUrl(String path, @Nullable Collection<?> params) { |
|
|
|
private URI buildUrl(String path, @Nullable Collection<?> params) { |
|
|
|
return buildUrl(Feature.BASELINE, path, (params != null) ? params.toArray() : null); |
|
|
|
return buildUrl(Feature.BASELINE, path, (params != null) ? params.toArray() : null); |
|
|
|
} |
|
|
|
} |
|
|
|
@ -229,9 +236,8 @@ public class DockerApi { |
|
|
|
UpdateListener<PullImageUpdateEvent> listener, @Nullable String registryAuth) throws IOException { |
|
|
|
UpdateListener<PullImageUpdateEvent> listener, @Nullable String registryAuth) throws IOException { |
|
|
|
Assert.notNull(reference, "'reference' must not be null"); |
|
|
|
Assert.notNull(reference, "'reference' must not be null"); |
|
|
|
Assert.notNull(listener, "'listener' must not be null"); |
|
|
|
Assert.notNull(listener, "'listener' must not be null"); |
|
|
|
URI createUri = (platform != null) |
|
|
|
URI createUri = (platform != null) ? buildUrl(Feature.PLATFORM_IMAGE_PULL, "/images/create", "fromImage", |
|
|
|
? buildUrl(Feature.PLATFORM, "/images/create", "fromImage", reference, "platform", platform) |
|
|
|
reference, "platform", platform) : buildUrl("/images/create", "fromImage", reference); |
|
|
|
: buildUrl("/images/create", "fromImage", reference); |
|
|
|
|
|
|
|
DigestCaptureUpdateListener digestCapture = new DigestCaptureUpdateListener(); |
|
|
|
DigestCaptureUpdateListener digestCapture = new DigestCaptureUpdateListener(); |
|
|
|
listener.onStart(); |
|
|
|
listener.onStart(); |
|
|
|
try { |
|
|
|
try { |
|
|
|
@ -313,9 +319,24 @@ public class DockerApi { |
|
|
|
*/ |
|
|
|
*/ |
|
|
|
public void exportLayers(ImageReference reference, IOBiConsumer<String, TarArchive> exports) |
|
|
|
public void exportLayers(ImageReference reference, IOBiConsumer<String, TarArchive> exports) |
|
|
|
throws IOException { |
|
|
|
throws IOException { |
|
|
|
|
|
|
|
exportLayers(reference, null, exports); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
|
|
|
* Export the layers of an image as {@link TarArchive TarArchives}. |
|
|
|
|
|
|
|
* @param reference the reference to export |
|
|
|
|
|
|
|
* @param platform the platform (os/architecture/variant) of the image to export. |
|
|
|
|
|
|
|
* Ignored on older versions of Docker. |
|
|
|
|
|
|
|
* @param exports a consumer to receive the layers (contents can only be accessed |
|
|
|
|
|
|
|
* during the callback) |
|
|
|
|
|
|
|
* @throws IOException on IO error |
|
|
|
|
|
|
|
* @since 3.4.12 |
|
|
|
|
|
|
|
*/ |
|
|
|
|
|
|
|
public void exportLayers(ImageReference reference, @Nullable ImagePlatform platform, |
|
|
|
|
|
|
|
IOBiConsumer<String, TarArchive> exports) throws IOException { |
|
|
|
Assert.notNull(reference, "'reference' must not be null"); |
|
|
|
Assert.notNull(reference, "'reference' must not be null"); |
|
|
|
Assert.notNull(exports, "'exports' must not be null"); |
|
|
|
Assert.notNull(exports, "'exports' must not be null"); |
|
|
|
URI uri = buildUrl("/images/" + reference + "/get"); |
|
|
|
URI uri = buildPlatformJsonUrl(Feature.PLATFORM_IMAGE_EXPORT, platform, "/images/" + reference + "/get"); |
|
|
|
try (Response response = http().get(uri)) { |
|
|
|
try (Response response = http().get(uri)) { |
|
|
|
try (ExportedImageTar exportedImageTar = new ExportedImageTar(reference, response.getContent())) { |
|
|
|
try (ExportedImageTar exportedImageTar = new ExportedImageTar(reference, response.getContent())) { |
|
|
|
exportedImageTar.exportLayers(exports); |
|
|
|
exportedImageTar.exportLayers(exports); |
|
|
|
@ -359,20 +380,13 @@ public class DockerApi { |
|
|
|
// The Docker documentation is incomplete but platform parameters
|
|
|
|
// The Docker documentation is incomplete but platform parameters
|
|
|
|
// are supported since 1.49 (see https://github.com/moby/moby/pull/49586)
|
|
|
|
// are supported since 1.49 (see https://github.com/moby/moby/pull/49586)
|
|
|
|
Assert.notNull(reference, "'reference' must not be null"); |
|
|
|
Assert.notNull(reference, "'reference' must not be null"); |
|
|
|
URI inspectUrl = inspectUrl(reference, platform); |
|
|
|
URI inspectUrl = buildPlatformJsonUrl(Feature.PLATFORM_IMAGE_INSPECT, platform, |
|
|
|
|
|
|
|
"/images/" + reference + "/json"); |
|
|
|
try (Response response = http().get(inspectUrl)) { |
|
|
|
try (Response response = http().get(inspectUrl)) { |
|
|
|
return Image.of(response.getContent()); |
|
|
|
return Image.of(response.getContent()); |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
private URI inspectUrl(ImageReference reference, @Nullable ImagePlatform platform) { |
|
|
|
|
|
|
|
String path = "/images/" + reference + "/json"; |
|
|
|
|
|
|
|
if (platform != null && getApiVersion().supports(Feature.PLATFORM_INSPECT.minimumVersion())) { |
|
|
|
|
|
|
|
return buildUrl(Feature.PLATFORM_INSPECT, path, "platform", platform.toJson()); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
return buildUrl(path); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
public void tag(ImageReference sourceReference, ImageReference targetReference) throws IOException { |
|
|
|
public void tag(ImageReference sourceReference, ImageReference targetReference) throws IOException { |
|
|
|
Assert.notNull(sourceReference, "'sourceReference' must not be null"); |
|
|
|
Assert.notNull(sourceReference, "'sourceReference' must not be null"); |
|
|
|
Assert.notNull(targetReference, "'targetReference' must not be null"); |
|
|
|
Assert.notNull(targetReference, "'targetReference' must not be null"); |
|
|
|
@ -415,7 +429,8 @@ public class DockerApi { |
|
|
|
|
|
|
|
|
|
|
|
private ContainerReference createContainer(ContainerConfig config, @Nullable ImagePlatform platform) |
|
|
|
private ContainerReference createContainer(ContainerConfig config, @Nullable ImagePlatform platform) |
|
|
|
throws IOException { |
|
|
|
throws IOException { |
|
|
|
URI createUri = (platform != null) ? buildUrl(Feature.PLATFORM, "/containers/create", "platform", platform) |
|
|
|
URI createUri = (platform != null) |
|
|
|
|
|
|
|
? buildUrl(Feature.PLATFORM_CONTAINER_CREATE, "/containers/create", "platform", platform) |
|
|
|
: buildUrl("/containers/create"); |
|
|
|
: buildUrl("/containers/create"); |
|
|
|
try (Response response = http().post(createUri, "application/json", config::writeTo)) { |
|
|
|
try (Response response = http().post(createUri, "application/json", config::writeTo)) { |
|
|
|
return ContainerReference |
|
|
|
return ContainerReference |
|
|
|
@ -624,9 +639,13 @@ public class DockerApi { |
|
|
|
|
|
|
|
|
|
|
|
BASELINE(ApiVersion.of(1, 24)), |
|
|
|
BASELINE(ApiVersion.of(1, 24)), |
|
|
|
|
|
|
|
|
|
|
|
PLATFORM(ApiVersion.of(1, 41)), |
|
|
|
PLATFORM_IMAGE_PULL(ApiVersion.of(1, 41)), |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
PLATFORM_CONTAINER_CREATE(ApiVersion.of(1, 41)), |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
PLATFORM_IMAGE_INSPECT(ApiVersion.of(1, 49)), |
|
|
|
|
|
|
|
|
|
|
|
PLATFORM_INSPECT(ApiVersion.of(1, 49)); |
|
|
|
PLATFORM_IMAGE_EXPORT(ApiVersion.of(1, 48)); |
|
|
|
|
|
|
|
|
|
|
|
private final ApiVersion minimumVersion; |
|
|
|
private final ApiVersion minimumVersion; |
|
|
|
|
|
|
|
|
|
|
|
|