Skip to content

Commit 51ad8fa

Browse files
authored
One more demo/test to push Jenkins library (#581)
2 parents 1b089db + c905b53 commit 51ad8fa

3 files changed

Lines changed: 61 additions & 11 deletions

File tree

pom.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -304,7 +304,7 @@
304304
<inceptionYear>2024</inceptionYear>
305305
<addJavaLicenseAfterPackage>false</addJavaLicenseAfterPackage>
306306
<emptyLineAfterHeader>true</emptyLineAfterHeader>
307-
<excludes>**/logback*.xml,**/junit-platform.properties,**/*.json</excludes>
307+
<excludes>**/logback*.xml,**/junit-platform.properties,**/*.json,**/*.groovy</excludes>
308308
<processStartTag>= LICENSE =</processStartTag>
309309
<sectionDelimiter>===</sectionDelimiter>
310310
<processEndTag>= LICENSE END =</processEndTag>

src/test/java/land/oras/HarborS3ITCase.java

Lines changed: 57 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,9 @@
2727
import java.nio.file.Paths;
2828
import java.util.List;
2929
import java.util.Map;
30+
import land.oras.utils.ArchiveUtils;
3031
import land.oras.utils.Const;
32+
import land.oras.utils.SupportedCompression;
3133
import org.junit.jupiter.api.Disabled;
3234
import org.junit.jupiter.api.Test;
3335
import org.junit.jupiter.api.io.TempDir;
@@ -126,24 +128,69 @@ void shouldPushFluxArtifact() {
126128

127129
}
128130

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+
129175
@Test
130176
@Disabled
131177
void shouldPushJenkinsScriptArtifact() {
132178

133179
// language=groovy
134180
String jenkinsfile =
135181
"""
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+
}
142192
}
143-
stage('Deploy') {
144-
echo 'Deploying...'
145-
}
146-
""";
193+
""";
147194

148195
// The compressed manifests
149196
Path image = Paths.get("src/test/resources/img").resolve("jenkins.png");
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
def call() {
2+
print "This is myFunc from the oras library"
3+
}

0 commit comments

Comments
 (0)