Skip to content

Commit 588f9f1

Browse files
committed
Add zot unsecure container
Signed-off-by: Valentin Delaye <[email protected]>
1 parent ceb8cd5 commit 588f9f1

File tree

4 files changed

+120
-5
lines changed

4 files changed

+120
-5
lines changed

src/test/java/land/oras/RegistryTest.java

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@
3636
import land.oras.utils.RegistryContainer;
3737
import land.oras.utils.SupportedAlgorithm;
3838
import land.oras.utils.ZotContainer;
39+
import land.oras.utils.ZotUnsecureContainer;
3940
import org.junit.jupiter.api.Assertions;
4041
import org.junit.jupiter.api.BeforeEach;
4142
import org.junit.jupiter.api.Test;
@@ -52,6 +53,9 @@ class RegistryTest {
5253
@Container
5354
private final ZotContainer registry = new ZotContainer().withStartupAttempts(3);
5455

56+
@Container
57+
private final ZotUnsecureContainer unsecureRegistry = new ZotUnsecureContainer().withStartupAttempts(3);
58+
5559
@TempDir
5660
private Path blobDir;
5761

@@ -157,6 +161,14 @@ void shouldFailWithoutAuthentication() {
157161
});
158162
}
159163

164+
@Test
165+
void shouldPushUnsecure() {
166+
Registry registry = Registry.Builder.builder().insecure().build();
167+
ContainerRef containerRef =
168+
ContainerRef.parse("%s/library/artifact-text".formatted(this.unsecureRegistry.getRegistry()));
169+
registry.pushBlob(containerRef, "hello".getBytes());
170+
}
171+
160172
@Test
161173
void shouldFailWithoutAuthenticationAndRegistry() {
162174
Registry registry =

src/test/java/land/oras/utils/ZotContainer.java

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -47,8 +47,8 @@ public class ZotContainer extends GenericContainer<ZotContainer> {
4747
*/
4848
public ZotContainer() {
4949
super("ghcr.io/project-zot/zot-linux-amd64:v2.1.5");
50-
addExposedPort(5000);
51-
setWaitStrategy(Wait.forHttp("/v2/_catalog").forPort(5000).forStatusCode(401));
50+
addExposedPort(ZOT_PORT);
51+
setWaitStrategy(Wait.forHttp("/v2/_catalog").forPort(ZOT_PORT).forStatusCode(401));
5252

5353
try {
5454
// Auth file
@@ -64,7 +64,7 @@ public ZotContainer() {
6464
"storage": { "rootDirectory": "/var/lib/registry" },
6565
"http": {
6666
"address": "0.0.0.0",
67-
"port": 5000,
67+
"port": %s,
6868
"auth": {
6969
"htpasswd": { "path": "/etc/zot/auth.htpasswd" }
7070
}
@@ -73,7 +73,8 @@ public ZotContainer() {
7373
"search": { "enable": true }
7474
}
7575
}
76-
""";
76+
"""
77+
.formatted(ZOT_PORT);
7778

7879
Files.writeString(configFile, configJson);
7980

@@ -93,7 +94,7 @@ public ZotContainer() {
9394
* @return The registry URL
9495
*/
9596
public String getRegistry() {
96-
return getHost() + ":" + getMappedPort(5000);
97+
return getHost() + ":" + getMappedPort(ZOT_PORT);
9798
}
9899

99100
public ZotContainer withFollowOutput() {
Lines changed: 93 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,93 @@
1+
/*-
2+
* =LICENSE=
3+
* ORAS Java SDK
4+
* ===
5+
* Copyright (C) 2024 - 2025 ORAS
6+
* ===
7+
* Licensed under the Apache License, Version 2.0 (the "License");
8+
* you may not use this file except in compliance with the License.
9+
* You may obtain a copy of the License at
10+
*
11+
* http://www.apache.org/licenses/LICENSE-2.0
12+
*
13+
* Unless required by applicable law or agreed to in writing, software
14+
* distributed under the License is distributed on an "AS IS" BASIS,
15+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16+
* See the License for the specific language governing permissions and
17+
* limitations under the License.
18+
* =LICENSEEND=
19+
*/
20+
21+
package land.oras.utils;
22+
23+
import java.nio.file.Files;
24+
import java.nio.file.Path;
25+
import org.jspecify.annotations.NullMarked;
26+
import org.slf4j.Logger;
27+
import org.slf4j.LoggerFactory;
28+
import org.testcontainers.containers.GenericContainer;
29+
import org.testcontainers.containers.output.Slf4jLogConsumer;
30+
import org.testcontainers.containers.wait.strategy.Wait;
31+
import org.testcontainers.utility.MountableFile;
32+
33+
@NullMarked
34+
public class ZotUnsecureContainer extends GenericContainer<ZotUnsecureContainer> {
35+
36+
/**
37+
* Logger
38+
*/
39+
private Logger LOG = LoggerFactory.getLogger(ZotUnsecureContainer.class);
40+
41+
// myuser:mypass
42+
public static final int ZOT_PORT = 5001;
43+
44+
/**
45+
* Create a new registry container
46+
*/
47+
public ZotUnsecureContainer() {
48+
super("ghcr.io/project-zot/zot-linux-amd64:v2.1.5");
49+
addExposedPort(ZOT_PORT);
50+
setWaitStrategy(Wait.forHttp("/v2/_catalog").forPort(ZOT_PORT).forStatusCode(200));
51+
52+
try {
53+
// Zot config file
54+
Path configFile = Files.createTempFile("zot-config", ".json");
55+
String configJson =
56+
"""
57+
{
58+
"storage": { "rootDirectory": "/var/lib/registry" },
59+
"http": {
60+
"address": "0.0.0.0",
61+
"port": %s
62+
},
63+
"extensions": {
64+
"search": { "enable": true }
65+
}
66+
}
67+
"""
68+
.formatted(ZOT_PORT);
69+
70+
Files.writeString(configFile, configJson);
71+
72+
// Copy it into the container
73+
withCopyFileToContainer(
74+
MountableFile.forHostPath(configFile.toAbsolutePath().toString()), "/etc/zot/config.json");
75+
76+
} catch (Exception e) {
77+
throw new RuntimeException("Failed to create auth.htpasswd", e);
78+
}
79+
}
80+
81+
/**
82+
* Get the registry URL
83+
* @return The registry URL
84+
*/
85+
public String getRegistry() {
86+
return getHost() + ":" + getMappedPort(ZOT_PORT);
87+
}
88+
89+
public ZotUnsecureContainer withFollowOutput() {
90+
followOutput(new Slf4jLogConsumer(LOG));
91+
return this;
92+
}
93+
}

updatecli/updatecli.d/zot.yaml

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,15 @@ targets:
4141
matchPattern: "ghcr.io/project-zot/zot-linux-amd64:v(\\d.\\d.\\d{1,2})"
4242
replacePattern: 'ghcr.io/project-zot/zot-linux-amd64:{{ source "zotLatestVersion" }}'
4343
scmid: default
44+
updateZotUnsecureContainer:
45+
name: "Update the value in the ZotUnsecureContainer.java file"
46+
kind: file
47+
sourceid: zotLatestVersion
48+
spec:
49+
file: src/test/java/land/oras/utils/ZotUnsecureContainer.java
50+
matchPattern: "ghcr.io/project-zot/zot-linux-amd64:v(\\d.\\d.\\d{1,2})"
51+
replacePattern: 'ghcr.io/project-zot/zot-linux-amd64:{{ source "zotLatestVersion" }}'
52+
scmid: default
4453

4554
actions:
4655
default:

0 commit comments

Comments
 (0)