|
27 | 27 | import java.nio.file.Paths; |
28 | 28 | import java.util.List; |
29 | 29 | import java.util.Map; |
| 30 | +import land.oras.utils.ArchiveUtils; |
30 | 31 | import land.oras.utils.Const; |
| 32 | +import land.oras.utils.SupportedCompression; |
31 | 33 | import org.junit.jupiter.api.Disabled; |
32 | 34 | import org.junit.jupiter.api.Test; |
33 | 35 | import org.junit.jupiter.api.io.TempDir; |
@@ -126,24 +128,69 @@ void shouldPushFluxArtifact() { |
126 | 128 |
|
127 | 129 | } |
128 | 130 |
|
| 131 | + @Test |
| 132 | + @Disabled |
| 133 | + void shouldPushJenkinsLibArtifact() { |
| 134 | + |
| 135 | + Path image = Paths.get("src/test/resources/img").resolve("jenkins.png"); |
| 136 | + Path library = Paths.get("src/test/resources/content/lib").toAbsolutePath(); |
| 137 | + LocalPath compressedLibrary = |
| 138 | + ArchiveUtils.tarcompress(LocalPath.of(library), SupportedCompression.GZIP.getMediaType()); |
| 139 | + |
| 140 | + Map<String, String> annotations = Map.of( |
| 141 | + Const.ANNOTATION_REVISION, "@sha1:6d63912ed9a9443dd01fbfd2991173a246050079", |
| 142 | + Const.ANNOTATION_SOURCE, "git@github.com:jonesbusy/oras-java.git", |
| 143 | + Const.ANNOTATION_CREATED, Const.currentTimestamp()); |
| 144 | + |
| 145 | + // Create objects |
| 146 | + ContainerRef containerRef = ContainerRef.parse("demo.goharbor.io/oras/jenkins-lib:latest"); |
| 147 | + Registry registry = Registry.builder().defaults().build(); |
| 148 | + |
| 149 | + Config config = Config.empty(); |
| 150 | + Layer layer = Layer.fromFile(compressedLibrary.getPath()) |
| 151 | + .withMediaType(Const.DEFAULT_BLOB_DIR_MEDIA_TYPE) |
| 152 | + .withAnnotations(Map.of(Const.ANNOTATION_ORAS_UNPACK, "true", Const.ANNOTATION_TITLE, "lib")); |
| 153 | + Layer imageLayer = Layer.fromFile(image) |
| 154 | + .withMediaType("image/png") |
| 155 | + .withAnnotations(Map.of("io.goharbor.artifact.v1alpha1.icon", "")); |
| 156 | + |
| 157 | + Manifest manifest = Manifest.empty() |
| 158 | + .withConfig(config) |
| 159 | + .withArtifactType(ArtifactType.from("application/vnd.jenkins.lib.manifest.v1+json")) |
| 160 | + .withLayers(List.of(layer, imageLayer)) |
| 161 | + .withAnnotations(annotations); |
| 162 | + |
| 163 | + registry.pushConfig(containerRef, config); |
| 164 | + registry.pushBlob(containerRef, compressedLibrary.getPath()); |
| 165 | + registry.pushBlob(containerRef, image); |
| 166 | + registry.pushManifest(containerRef, manifest); |
| 167 | + |
| 168 | + // Ensure we can pull |
| 169 | + Manifest createdManifest = registry.getManifest(containerRef); |
| 170 | + assertNotNull(createdManifest); |
| 171 | + |
| 172 | + assertNotNull(createdManifest); |
| 173 | + } |
| 174 | + |
129 | 175 | @Test |
130 | 176 | @Disabled |
131 | 177 | void shouldPushJenkinsScriptArtifact() { |
132 | 178 |
|
133 | 179 | // language=groovy |
134 | 180 | String jenkinsfile = |
135 | 181 | """ |
136 | | - node { |
137 | | - stage('Build') { |
138 | | - echo 'Building...' |
139 | | - } |
140 | | - stage('Test') { |
141 | | - echo 'Testing...' |
| 182 | + node { |
| 183 | + stage('Build') { |
| 184 | + echo 'Building...' |
| 185 | + } |
| 186 | + stage('Test') { |
| 187 | + echo 'Testing...' |
| 188 | + } |
| 189 | + stage('Deploy') { |
| 190 | + echo 'Deploying...' |
| 191 | + } |
142 | 192 | } |
143 | | - stage('Deploy') { |
144 | | - echo 'Deploying...' |
145 | | - } |
146 | | - """; |
| 193 | + """; |
147 | 194 |
|
148 | 195 | // The compressed manifests |
149 | 196 | Path image = Paths.get("src/test/resources/img").resolve("jenkins.png"); |
|
0 commit comments