Skip to content

Commit e0321d9

Browse files
authored
Add container implementation for Typesense (#9454)
1 parent c1ad4b8 commit e0321d9

File tree

12 files changed

+177
-0
lines changed

12 files changed

+177
-0
lines changed

.github/ISSUE_TEMPLATE/bug_report.yaml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,7 @@ body:
6464
- Timeplus
6565
- ToxiProxy
6666
- Trino
67+
- Typesense
6768
- Vault
6869
- Weaviate
6970
- YugabyteDB

.github/ISSUE_TEMPLATE/enhancement.yaml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,7 @@ body:
6464
- Timeplus
6565
- ToxiProxy
6666
- Trino
67+
- Typesense
6768
- Vault
6869
- Weaviate
6970
- YugabyteDB

.github/ISSUE_TEMPLATE/feature.yaml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,7 @@ body:
6464
- Timeplus
6565
- ToxiProxy
6666
- Trino
67+
- Typesense
6768
- Vault
6869
- Weaviate
6970
- YugabyteDB

.github/dependabot.yml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -361,6 +361,11 @@ updates:
361361
schedule:
362362
interval: "weekly"
363363
open-pull-requests-limit: 10
364+
- package-ecosystem: "gradle"
365+
directory: "/modules/typesense"
366+
schedule:
367+
interval: "weekly"
368+
open-pull-requests-limit: 10
364369
- package-ecosystem: "gradle"
365370
directory: "/modules/vault"
366371
schedule:

.github/labeler.yml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -232,6 +232,10 @@
232232
- changed-files:
233233
- any-glob-to-any-file:
234234
- modules/trino/**/*
235+
"modules/typesense":
236+
- changed-files:
237+
- any-glob-to-any-file:
238+
- modules/typesense/**/*
235239
"modules/vault":
236240
- changed-files:
237241
- any-glob-to-any-file:

.github/settings.yml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -262,6 +262,9 @@ labels:
262262
- name: modules/trino
263263
color: '#006b75'
264264

265+
- name: modules/typesense
266+
color: '#006b75'
267+
265268
- name: modules/vault
266269
color: '#006b75'
267270

docs/modules/typesense.md

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
# Typesense
2+
3+
Testcontainers module for [Typesense](https://hub.docker.com/r/typesense/typesense).
4+
5+
## TypesenseContainer's usage examples
6+
7+
You can start an Typesense container instance from any Java application by using:
8+
9+
<!--codeinclude-->
10+
[Typesense container](../../modules/typesense/src/test/java/org/testcontainers/typesense/TypesenseContainerTest.java) inside_block:container
11+
<!--/codeinclude-->
12+
13+
## Adding this module to your project dependencies
14+
15+
Add the following dependency to your `pom.xml`/`build.gradle` file:
16+
17+
=== "Gradle"
18+
```groovy
19+
testImplementation "org.testcontainers:typesense:{{latest_version}}"
20+
```
21+
22+
=== "Maven"
23+
```xml
24+
<dependency>
25+
<groupId>org.testcontainers</groupId>
26+
<artifactId>typesense</artifactId>
27+
<version>{{latest_version}}</version>
28+
<scope>test</scope>
29+
</dependency>
30+
```

mkdocs.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -102,6 +102,7 @@ nav:
102102
- modules/solace.md
103103
- modules/solr.md
104104
- modules/toxiproxy.md
105+
- modules/typesense.md
105106
- modules/vault.md
106107
- modules/weaviate.md
107108
- modules/webdriver_containers.md

modules/typesense/build.gradle

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
description = "Testcontainers :: Typesense"
2+
3+
dependencies {
4+
api project(':testcontainers')
5+
6+
testImplementation 'org.assertj:assertj-core:3.26.3'
7+
testImplementation 'org.typesense:typesense-java:0.9.0'
8+
}
Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
package org.testcontainers.typesense;
2+
3+
import org.testcontainers.containers.GenericContainer;
4+
import org.testcontainers.containers.wait.strategy.Wait;
5+
import org.testcontainers.utility.DockerImageName;
6+
7+
/**
8+
* Testcontainers implementation for Typesense.
9+
* <p>
10+
* Supported image: {@code typesense/typesense}
11+
* <p>
12+
* Exposed ports: 8108
13+
*/
14+
public class TypesenseContainer extends GenericContainer<TypesenseContainer> {
15+
16+
private static final DockerImageName DEFAULT_IMAGE_NAME = DockerImageName.parse("typesense/typesense");
17+
18+
private static final int PORT = 8108;
19+
20+
private static final String DEFAULT_API_KEY = "testcontainers";
21+
22+
private String apiKey = DEFAULT_API_KEY;
23+
24+
public TypesenseContainer(String dockerImageName) {
25+
this(DockerImageName.parse(dockerImageName));
26+
}
27+
28+
public TypesenseContainer(DockerImageName dockerImageName) {
29+
super(dockerImageName);
30+
dockerImageName.assertCompatibleWith(DEFAULT_IMAGE_NAME);
31+
withExposedPorts(PORT);
32+
withEnv("TYPESENSE_DATA_DIR", "/tmp");
33+
waitingFor(
34+
Wait
35+
.forHttp("/health")
36+
.forStatusCode(200)
37+
.forResponsePredicate(response -> response.contains("\"ok\":true"))
38+
);
39+
}
40+
41+
@Override
42+
protected void configure() {
43+
withEnv("TYPESENSE_API_KEY", this.apiKey);
44+
}
45+
46+
public TypesenseContainer withApiKey(String apiKey) {
47+
this.apiKey = apiKey;
48+
return this;
49+
}
50+
51+
public String getHttpPort() {
52+
return String.valueOf(getMappedPort(PORT));
53+
}
54+
55+
public String getApiKey() {
56+
return this.apiKey;
57+
}
58+
}

0 commit comments

Comments
 (0)