|
|
|
@ -64,7 +64,9 @@ public class DockerApi { |
|
|
|
|
|
|
|
|
|
|
|
private static final List<String> FORCE_PARAMS = Collections.unmodifiableList(Arrays.asList("force", "1")); |
|
|
|
private static final List<String> FORCE_PARAMS = Collections.unmodifiableList(Arrays.asList("force", "1")); |
|
|
|
|
|
|
|
|
|
|
|
static final ApiVersion MINIMUM_API_VERSION = ApiVersion.parse("1.24"); |
|
|
|
static final ApiVersion MINIMUM_API_VERSION = ApiVersion.of(1, 24); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
static final ApiVersion MINIMUM_PLATFORM_API_VERSION = ApiVersion.of(1, 41); |
|
|
|
|
|
|
|
|
|
|
|
static final String API_VERSION_HEADER_NAME = "API-Version"; |
|
|
|
static final String API_VERSION_HEADER_NAME = "API-Version"; |
|
|
|
|
|
|
|
|
|
|
|
@ -80,7 +82,7 @@ public class DockerApi { |
|
|
|
|
|
|
|
|
|
|
|
private final SystemApi system; |
|
|
|
private final SystemApi system; |
|
|
|
|
|
|
|
|
|
|
|
private ApiVersion apiVersion = null; |
|
|
|
private volatile ApiVersion apiVersion = null; |
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
/** |
|
|
|
* Create a new {@link DockerApi} instance. |
|
|
|
* Create a new {@link DockerApi} instance. |
|
|
|
@ -126,10 +128,7 @@ public class DockerApi { |
|
|
|
|
|
|
|
|
|
|
|
private URI buildUrl(String path, Object... params) { |
|
|
|
private URI buildUrl(String path, Object... params) { |
|
|
|
try { |
|
|
|
try { |
|
|
|
if (this.apiVersion == null) { |
|
|
|
URIBuilder builder = new URIBuilder("/v" + getApiVersion() + path); |
|
|
|
this.apiVersion = this.system.getApiVersion(); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
URIBuilder builder = new URIBuilder("/v" + this.apiVersion + path); |
|
|
|
|
|
|
|
int param = 0; |
|
|
|
int param = 0; |
|
|
|
while (param < params.length) { |
|
|
|
while (param < params.length) { |
|
|
|
builder.addParameter(Objects.toString(params[param++]), Objects.toString(params[param++])); |
|
|
|
builder.addParameter(Objects.toString(params[param++]), Objects.toString(params[param++])); |
|
|
|
@ -141,11 +140,19 @@ public class DockerApi { |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
private void verifyApiVersionForPlatform() { |
|
|
|
private void verifyApiVersionForPlatform(ImagePlatform platform) { |
|
|
|
ApiVersion minimumPlatformApiVersion = ApiVersion.of(1, 41); |
|
|
|
Assert.isTrue(platform == null || getApiVersion().supports(MINIMUM_PLATFORM_API_VERSION), |
|
|
|
Assert.isTrue(this.apiVersion.supports(minimumPlatformApiVersion), |
|
|
|
() -> "Docker API version must be at least " + MINIMUM_PLATFORM_API_VERSION |
|
|
|
"Docker API version must be at least " + minimumPlatformApiVersion |
|
|
|
+ " to support the 'imagePlatform' option, but current API version is " + getApiVersion()); |
|
|
|
+ " to support the 'imagePlatform' option, but current API version is " + this.apiVersion); |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
private ApiVersion getApiVersion() { |
|
|
|
|
|
|
|
ApiVersion apiVersion = this.apiVersion; |
|
|
|
|
|
|
|
if (this.apiVersion == null) { |
|
|
|
|
|
|
|
apiVersion = this.system.getApiVersion(); |
|
|
|
|
|
|
|
this.apiVersion = apiVersion; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
return apiVersion; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
/** |
|
|
|
@ -206,14 +213,10 @@ public class DockerApi { |
|
|
|
UpdateListener<PullImageUpdateEvent> listener, String registryAuth) throws IOException { |
|
|
|
UpdateListener<PullImageUpdateEvent> listener, 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; |
|
|
|
verifyApiVersionForPlatform(platform); |
|
|
|
if (platform != null) { |
|
|
|
URI createUri = (platform != null) |
|
|
|
createUri = buildUrl("/images/create", "fromImage", reference, "platform", platform); |
|
|
|
? buildUrl("/images/create", "fromImage", reference, "platform", platform) |
|
|
|
verifyApiVersionForPlatform(); |
|
|
|
: buildUrl("/images/create", "fromImage", reference); |
|
|
|
} |
|
|
|
|
|
|
|
else { |
|
|
|
|
|
|
|
createUri = buildUrl("/images/create", "fromImage", reference); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
DigestCaptureUpdateListener digestCapture = new DigestCaptureUpdateListener(); |
|
|
|
DigestCaptureUpdateListener digestCapture = new DigestCaptureUpdateListener(); |
|
|
|
listener.onStart(); |
|
|
|
listener.onStart(); |
|
|
|
try { |
|
|
|
try { |
|
|
|
@ -400,14 +403,9 @@ public class DockerApi { |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
private ContainerReference createContainer(ContainerConfig config, ImagePlatform platform) throws IOException { |
|
|
|
private ContainerReference createContainer(ContainerConfig config, ImagePlatform platform) throws IOException { |
|
|
|
URI createUri; |
|
|
|
verifyApiVersionForPlatform(platform); |
|
|
|
if (platform != null) { |
|
|
|
URI createUri = (platform != null) ? buildUrl("/containers/create", "platform", platform) |
|
|
|
createUri = buildUrl("/containers/create", "platform", platform); |
|
|
|
: buildUrl("/containers/create"); |
|
|
|
verifyApiVersionForPlatform(); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
else { |
|
|
|
|
|
|
|
createUri = 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 |
|
|
|
.of(SharedObjectMapper.get().readTree(response.getContent()).at("/Id").asText()); |
|
|
|
.of(SharedObjectMapper.get().readTree(response.getContent()).at("/Id").asText()); |
|
|
|
|