Skip to content

Commit 4ce38e6

Browse files
committed
module 6 - ollama
1 parent d249ced commit 4ce38e6

File tree

2 files changed

+121
-0
lines changed

2 files changed

+121
-0
lines changed

module-6/pom.xml

+64
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<project xmlns="http://maven.apache.org/POM/4.0.0"
3+
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
4+
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd">
5+
<modelVersion>4.0.0</modelVersion>
6+
<groupId>org.testcontainers</groupId>
7+
<artifactId>testcontainers-workshop-6</artifactId>
8+
<version>0.0.1-SNAPSHOT</version>
9+
<name>testcontainers-workshop-6</name>
10+
<description>testcontainers-workshop-6</description>
11+
<properties>
12+
<java.version>17</java.version>
13+
<testcontainers.version>1.19.8</testcontainers.version>
14+
</properties>
15+
<dependencies>
16+
<dependency>
17+
<groupId>org.junit.jupiter</groupId>
18+
<artifactId>junit-jupiter</artifactId>
19+
<version>5.10.2</version>
20+
<scope>test</scope>
21+
</dependency>
22+
<dependency>
23+
<groupId>org.testcontainers</groupId>
24+
<artifactId>ollama</artifactId>
25+
</dependency>
26+
<dependency>
27+
<groupId>org.assertj</groupId>
28+
<artifactId>assertj-core</artifactId>
29+
<version>3.25.3</version>
30+
</dependency>
31+
<dependency>
32+
<groupId>io.rest-assured</groupId>
33+
<artifactId>rest-assured</artifactId>
34+
<version>5.4.0</version>
35+
</dependency>
36+
<dependency>
37+
<groupId>ch.qos.logback</groupId>
38+
<artifactId>logback-classic</artifactId>
39+
<version>1.3.14</version>
40+
</dependency>
41+
</dependencies>
42+
43+
<dependencyManagement>
44+
<dependencies>
45+
<dependency>
46+
<groupId>org.testcontainers</groupId>
47+
<artifactId>testcontainers-bom</artifactId>
48+
<version>${testcontainers.version}</version>
49+
<scope>import</scope>
50+
<type>pom</type>
51+
</dependency>
52+
</dependencies>
53+
</dependencyManagement>
54+
55+
<build>
56+
<plugins>
57+
<plugin>
58+
<artifactId>maven-surefire-plugin</artifactId>
59+
<version>3.2.5</version>
60+
</plugin>
61+
</plugins>
62+
</build>
63+
64+
</project>
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
package org.testcontainers.ollama;
2+
3+
import org.junit.Test;
4+
import org.testcontainers.utility.Base58;
5+
import org.testcontainers.utility.DockerImageName;
6+
7+
import java.io.IOException;
8+
9+
import static io.restassured.RestAssured.given;
10+
import static org.assertj.core.api.Assertions.assertThat;
11+
12+
public class OllamaContainerTest {
13+
14+
@Test
15+
public void withDefaultConfig() {
16+
try (
17+
OllamaContainer ollama = new OllamaContainer("ollama/ollama:0.1.26")
18+
19+
) {
20+
ollama.start();
21+
22+
String version = given().baseUri(ollama.getEndpoint()).get("/api/version").jsonPath().get("version");
23+
assertThat(version).isEqualTo("0.1.26");
24+
}
25+
}
26+
27+
@Test
28+
public void downloadModelAndCommitToImage() throws IOException, InterruptedException {
29+
String newImageName = "tc-ollama-allminilm-" + Base58.randomString(4).toLowerCase();
30+
try (OllamaContainer ollama = new OllamaContainer("ollama/ollama:0.1.26")) {
31+
ollama.start();
32+
ollama.execInContainer("ollama", "pull", "all-minilm");
33+
34+
String modelName = given()
35+
.baseUri(ollama.getEndpoint())
36+
.get("/api/tags")
37+
.jsonPath()
38+
.getString("models[0].name");
39+
assertThat(modelName).contains("all-minilm");
40+
ollama.commitToImage(newImageName);
41+
}
42+
try (
43+
OllamaContainer ollama = new OllamaContainer(
44+
DockerImageName.parse(newImageName)
45+
.asCompatibleSubstituteFor("ollama/ollama")
46+
)
47+
) {
48+
ollama.start();
49+
String modelName = given()
50+
.baseUri(ollama.getEndpoint())
51+
.get("/api/tags")
52+
.jsonPath()
53+
.getString("models[0].name");
54+
assertThat(modelName).contains("all-minilm");
55+
}
56+
}
57+
}

0 commit comments

Comments
 (0)