forked from spring-projects/spring-boot
-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
11 changed files
with
426 additions
and
11 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
125 changes: 125 additions & 0 deletions
125
...ava/org/springframework/boot/buildpack/platform/docker/type/DistributionManifestList.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,125 @@ | ||
/* | ||
* Copyright 2012-2024 the original author or authors. | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* https://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
package org.springframework.boot.buildpack.platform.docker.type; | ||
|
||
import java.lang.invoke.MethodHandles; | ||
import java.util.ArrayList; | ||
import java.util.Collections; | ||
import java.util.List; | ||
import java.util.function.Function; | ||
|
||
import com.fasterxml.jackson.databind.JsonNode; | ||
|
||
import org.springframework.boot.buildpack.platform.json.MappedObject; | ||
|
||
/** | ||
* A distribution manifest list as defined in | ||
* {@code application/vnd.docker.distribution.manifest.list} files. | ||
* | ||
* @author Phillip Webb | ||
* @since 3.1.12 | ||
* @see <a href="https://github.com/opencontainers/image-spec/blob/main/manifest.md">OCI | ||
* Image Manifest Specification</a> | ||
*/ | ||
public class DistributionManifestList extends MappedObject { | ||
|
||
private final Integer schemaVersion; | ||
|
||
private final String mediaType; | ||
|
||
private final List<Manifest> manifests; | ||
|
||
private final List<Layer> layers; | ||
|
||
protected DistributionManifestList(JsonNode node) { | ||
super(node, MethodHandles.lookup()); | ||
this.schemaVersion = valueAt("/schemaVersion", Integer.class); | ||
this.mediaType = valueAt("/mediaType", String.class); | ||
this.manifests = loadChildren(getNode().at("/manifests"), Manifest::new); | ||
this.layers = loadChildren(getNode().at("/layers"), Layer::new); | ||
} | ||
|
||
private static <T> List<T> loadChildren(JsonNode node, Function<JsonNode, T> factory) { | ||
if (node.isEmpty()) { | ||
return Collections.emptyList(); | ||
} | ||
List<T> children = new ArrayList<>(); | ||
node.elements().forEachRemaining((childNode) -> children.add(factory.apply(childNode))); | ||
return Collections.unmodifiableList(children); | ||
} | ||
|
||
public Integer getSchemaVersion() { | ||
return this.schemaVersion; | ||
} | ||
|
||
public String getMediaType() { | ||
return this.mediaType; | ||
} | ||
|
||
public List<Manifest> getManifests() { | ||
return this.manifests; | ||
} | ||
|
||
public List<Layer> getLayers() { | ||
return this.layers; | ||
} | ||
|
||
public static class Manifest extends MappedObject { | ||
|
||
private final String mediaType; | ||
|
||
private final String digest; | ||
|
||
protected Manifest(JsonNode node) { | ||
super(node, MethodHandles.lookup()); | ||
this.mediaType = valueAt("/mediaType", String.class); | ||
this.digest = valueAt("/digest", String.class); | ||
} | ||
|
||
public String getMediaType() { | ||
return this.mediaType; | ||
} | ||
|
||
public String getDigest() { | ||
return this.digest; | ||
} | ||
|
||
} | ||
|
||
public static class Layer extends MappedObject { | ||
|
||
private final String mediaType; | ||
|
||
private final String digest; | ||
|
||
protected Layer(JsonNode node) { | ||
super(node, MethodHandles.lookup()); | ||
this.mediaType = valueAt("/mediaType", String.class); | ||
this.digest = valueAt("/digest", String.class); | ||
} | ||
|
||
public String getMediaType() { | ||
return this.mediaType; | ||
} | ||
|
||
public String getDigest() { | ||
return this.digest; | ||
} | ||
|
||
} | ||
|
||
} |
88 changes: 88 additions & 0 deletions
88
.../main/java/org/springframework/boot/buildpack/platform/docker/type/ImageArchiveIndex.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,88 @@ | ||
/* | ||
* Copyright 2012-2024 the original author or authors. | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* https://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
package org.springframework.boot.buildpack.platform.docker.type; | ||
|
||
import java.lang.invoke.MethodHandles; | ||
import java.util.ArrayList; | ||
import java.util.Collections; | ||
import java.util.List; | ||
|
||
import com.fasterxml.jackson.databind.JsonNode; | ||
|
||
import org.springframework.boot.buildpack.platform.json.MappedObject; | ||
|
||
/** | ||
* Image archive index information as provided by {@code index.json}. | ||
* | ||
* @author Phillip Webb | ||
* @since 3.1.12 | ||
* @see <a href= | ||
* "https://github.com/opencontainers/image-spec/blob/main/image-index.md">OCI Image Index | ||
* Specification</a> | ||
*/ | ||
public class ImageArchiveIndex extends MappedObject { | ||
|
||
private final Integer schemaVersion; | ||
|
||
private final List<Manifest> manifests; | ||
|
||
protected ImageArchiveIndex(JsonNode node) { | ||
super(node, MethodHandles.lookup()); | ||
this.schemaVersion = valueAt("/schemaVersion", Integer.class); | ||
this.manifests = loadManifests(getNode().at("/manifests")); | ||
} | ||
|
||
private static List<Manifest> loadManifests(JsonNode node) { | ||
if (node.isEmpty()) { | ||
return Collections.emptyList(); | ||
} | ||
List<Manifest> manifests = new ArrayList<>(); | ||
node.elements().forEachRemaining((manifestNode) -> manifests.add(new Manifest(manifestNode))); | ||
return Collections.unmodifiableList(manifests); | ||
} | ||
|
||
public Integer getSchemaVersion() { | ||
return this.schemaVersion; | ||
} | ||
|
||
public List<Manifest> getManifests() { | ||
return this.manifests; | ||
} | ||
|
||
public static class Manifest extends MappedObject { | ||
|
||
private final String mediaType; | ||
|
||
private final String digest; | ||
|
||
protected Manifest(JsonNode node) { | ||
super(node, MethodHandles.lookup()); | ||
this.mediaType = valueAt("/mediaType", String.class); | ||
this.digest = valueAt("/digest", String.class); | ||
} | ||
|
||
public String getMediaType() { | ||
return this.mediaType; | ||
} | ||
|
||
public String getDigest() { | ||
return this.digest; | ||
} | ||
|
||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
45 changes: 45 additions & 0 deletions
45
...ck-platform/src/test/java/org/springframework/boot/buildpack/platform/docker/Gh40100.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
/* | ||
* Copyright 2012-2024 the original author or authors. | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* https://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
package org.springframework.boot.buildpack.platform.docker; | ||
|
||
import java.io.IOException; | ||
import java.nio.file.Files; | ||
|
||
import org.apache.commons.compress.archivers.tar.TarArchiveInputStream; | ||
import org.junit.jupiter.api.Test; | ||
|
||
import org.springframework.boot.buildpack.platform.docker.type.ImageReference; | ||
|
||
/** | ||
* @author Phillip Webb | ||
*/ | ||
class Gh40100 { | ||
|
||
@Test | ||
void testName() throws IOException { | ||
DockerApi api = new DockerApi(); | ||
ImageReference reference = ImageReference.of("gcr.io/paketo-buildpacks/adoptium:latest"); | ||
api.image().pull(reference, UpdateListener.none()); | ||
api.image().exportLayerFiles(reference, (name, path) -> { | ||
System.out.println(name); | ||
System.out.println(path); | ||
TarArchiveInputStream tarIn = new TarArchiveInputStream(Files.newInputStream(path)); | ||
tarIn.getNextEntry(); | ||
}); | ||
} | ||
|
||
} |
48 changes: 48 additions & 0 deletions
48
...rg/springframework/boot/buildpack/platform/docker/type/DistributionManifestListTests.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
/* | ||
* Copyright 2012-2024 the original author or authors. | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* https://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
package org.springframework.boot.buildpack.platform.docker.type; | ||
|
||
import java.io.IOException; | ||
|
||
import org.junit.jupiter.api.Test; | ||
|
||
import org.springframework.boot.buildpack.platform.json.AbstractJsonTests; | ||
|
||
/** | ||
* Tests for {@link DistributionManifestList}. | ||
* | ||
* @author Phillip Webb | ||
*/ | ||
class DistributionManifestListTests extends AbstractJsonTests { | ||
|
||
@Test | ||
void loadJsonWhenHasManifests() throws IOException { | ||
String content = getContentAsString("distribution-manifest-list-with-manifests.json"); | ||
DistributionManifestList manifestList = getManifestList(content); | ||
} | ||
|
||
@Test | ||
void loadJsonWhenHasLayers() throws IOException { | ||
String content = getContentAsString("distribution-manifest-list-with-layers.json"); | ||
DistributionManifestList manifestList = getManifestList(content); | ||
} | ||
|
||
private DistributionManifestList getManifestList(String content) throws IOException { | ||
return new DistributionManifestList(getObjectMapper().readTree(content)); | ||
} | ||
|
||
} |
Oops, something went wrong.