Skip to content

Commit e8d23d2

Browse files
bors[bot]meili-botalallema
authored
Merge #399
399: Improve Docker configuration in the package r=alallema a=meili-bot _This PR is auto-generated._ Add a basic Docker configuration based on this [integration-guides issue](meilisearch/integration-guides#199). Co-authored-by: meili-bot <[email protected]> Co-authored-by: alallema <[email protected]> Co-authored-by: Amélie <[email protected]>
2 parents 08b720f + 0d7bdca commit e8d23d2

File tree

4 files changed

+64
-16
lines changed

4 files changed

+64
-16
lines changed

CONTRIBUTING.md

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,22 @@ First of all, thank you for contributing to Meilisearch! The goal of this docume
2626

2727
## Development Workflow
2828

29+
### Setup <!-- omit in TOC -->
30+
31+
You can set up your local environment natively or using `docker`, check out the [`docker-compose.yml`](/docker-compose.yml).
32+
33+
Example of running all the checks with docker:
34+
```bash
35+
docker-compose run --rm package bash -c "./gradlew build && ./gradlew test IntegrationTest"
36+
```
37+
38+
To install dependencies:
39+
40+
```bash
41+
./gradlew build
42+
```
43+
44+
2945
### Tests <!-- omit in TOC -->
3046

3147
Integration and unit tests will be run in your PR to check everything is OK. Each PR should pass all the tests to be accepted.

docker-compose.yml

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
version: "3.8"
2+
3+
services:
4+
package:
5+
image: gradle:7.4.2-jdk8
6+
tty: true
7+
stdin_open: true
8+
working_dir: /home/package
9+
environment:
10+
- MEILISEARCH_HOST=http://meilisearch:7700
11+
depends_on:
12+
- meilisearch
13+
links:
14+
- meilisearch
15+
volumes:
16+
- ./:/home/package
17+
18+
meilisearch:
19+
image: getmeili/meilisearch:latest
20+
ports:
21+
- "7700"
22+
environment:
23+
- MEILI_MASTER_KEY=masterKey
24+
- MEILI_NO_ANALYTICS=true

src/test/java/com/meilisearch/integration/TenantTokenTest.java

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -45,14 +45,14 @@ public void testGenerateTenantTokenWithOnlySearchRules() throws Exception {
4545
Index index = createEmptyIndex(indexUid);
4646
Key key = getPrivateKey();
4747

48-
Client privateClient = new Client(new Config("http://localhost:7700", key.getKey()));
48+
Client privateClient = new Client(new Config(getMeilisearchHost(), key.getKey()));
4949

5050
Map<String, Object> rules = new HashMap<String, Object>();
5151
rules.put("*", new HashMap<String, Object>());
5252

5353
String jwtToken = privateClient.generateTenantToken(rules);
5454

55-
Client tokenClient = new Client(new Config("http://localhost:7700", jwtToken));
55+
Client tokenClient = new Client(new Config(getMeilisearchHost(), jwtToken));
5656

5757
assertDoesNotThrow(() -> tokenClient.index(indexUid).search(""));
5858
}
@@ -64,14 +64,14 @@ public void testGenerateTenantTokenOnOneIndex() throws Exception {
6464
Index index = createEmptyIndex(indexUid);
6565
Key key = getPrivateKey();
6666

67-
Client privateClient = new Client(new Config("http://localhost:7700", key.getKey()));
67+
Client privateClient = new Client(new Config(getMeilisearchHost(), key.getKey()));
6868

6969
Map<String, Object> rules = new HashMap<String, Object>();
7070
rules.put(indexUid, new HashMap<String, Object>());
7171

7272
String jwtToken = privateClient.generateTenantToken(rules);
7373

74-
Client tokenClient = new Client(new Config("http://localhost:7700", jwtToken));
74+
Client tokenClient = new Client(new Config(getMeilisearchHost(), jwtToken));
7575

7676
assertDoesNotThrow(() -> tokenClient.index(indexUid).search(""));
7777
}
@@ -82,7 +82,7 @@ public void testGenerateTenantTokenWithFilter() throws Exception {
8282
Key key = getPrivateKey();
8383
String indexUid = "GenerateTokenwithFilter";
8484

85-
Client privateClient = new Client(new Config("http://localhost:7700", key.getKey()));
85+
Client privateClient = new Client(new Config(getMeilisearchHost(), key.getKey()));
8686

8787
Map<String, Object> filters = new HashMap<String, Object>();
8888
filters.put("filter", "id > 1");
@@ -91,7 +91,7 @@ public void testGenerateTenantTokenWithFilter() throws Exception {
9191

9292
String jwtToken = privateClient.generateTenantToken(rules);
9393

94-
Client tokenClient = new Client(new Config("http://localhost:7700", jwtToken));
94+
Client tokenClient = new Client(new Config(getMeilisearchHost(), jwtToken));
9595

9696
Index index = client.index(indexUid);
9797
TestData<Movie> testData = this.getTestData(MOVIES_INDEX, Movie.class);
@@ -116,7 +116,7 @@ public void testGenerateTenantTokenWithExpiresAt() throws Exception {
116116
Index index = createEmptyIndex(indexUid);
117117
Key key = getPrivateKey();
118118

119-
Client privateClient = new Client(new Config("http://localhost:7700", key.getKey()));
119+
Client privateClient = new Client(new Config(getMeilisearchHost(), key.getKey()));
120120

121121
Map<String, Object> rules = new HashMap<String, Object>();
122122
rules.put("*", new HashMap<String, Object>());
@@ -129,7 +129,7 @@ public void testGenerateTenantTokenWithExpiresAt() throws Exception {
129129

130130
String jwtToken = privateClient.generateTenantToken(rules, options);
131131

132-
Client tokenClient = new Client(new Config("http://localhost:7700", jwtToken));
132+
Client tokenClient = new Client(new Config(getMeilisearchHost(), jwtToken));
133133

134134
assertDoesNotThrow(() -> tokenClient.index(indexUid).search(""));
135135
}
@@ -149,7 +149,7 @@ public void testGenerateTenantTokenWithApiKey() throws Exception {
149149

150150
String jwtToken = client.generateTenantToken(rules, options);
151151

152-
Client tokenClient = new Client(new Config("http://localhost:7700", jwtToken));
152+
Client tokenClient = new Client(new Config(getMeilisearchHost(), jwtToken));
153153

154154
assertDoesNotThrow(() -> tokenClient.index(indexUid).search(""));
155155
}
@@ -173,7 +173,7 @@ public void testGenerateTenantTokenWithAllOptions() throws Exception {
173173

174174
String jwtToken = client.generateTenantToken(rules, options);
175175

176-
Client tokenClient = new Client(new Config("http://localhost:7700", jwtToken));
176+
Client tokenClient = new Client(new Config(getMeilisearchHost(), jwtToken));
177177

178178
assertDoesNotThrow(() -> tokenClient.index(indexUid).search(""));
179179
}
@@ -184,7 +184,7 @@ public void testGenerateTenantTokenWithNoSearchRules() throws Exception {
184184
String indexUid = "GenerateTokenWithNoSearchRules";
185185
Key key = getPrivateKey();
186186

187-
Client privateClient = new Client(new Config("http://localhost:7700", key.getKey()));
187+
Client privateClient = new Client(new Config(getMeilisearchHost(), key.getKey()));
188188

189189
assertThrows(MeiliSearchException.class, () -> privateClient.generateTenantToken(null));
190190
}
@@ -195,7 +195,7 @@ public void testGenerateTenantTokenWithBadExpiresAt() throws Exception {
195195
String indexUid = "GenerateTenantTokenWithBadExpiresAt";
196196
Key key = getPrivateKey();
197197

198-
Client privateClient = new Client(new Config("http://localhost:7700", key.getKey()));
198+
Client privateClient = new Client(new Config(getMeilisearchHost(), key.getKey()));
199199

200200
Map<String, Object> rules = new HashMap<String, Object>();
201201
rules.put("*", new HashMap<String, Object>());
@@ -217,7 +217,7 @@ public void testGenerateTenantTokenWithBadExpiresAt() throws Exception {
217217
public void testGenerateTenantTokenWithEmptyApiKey() throws Exception {
218218
String indexUid = "GenerateTenantTokenWithEmptyApiKey";
219219

220-
Client privateClient = new Client(new Config("http://localhost:7700"));
220+
Client privateClient = new Client(new Config(getMeilisearchHost()));
221221

222222
Map<String, Object> rules = new HashMap<String, Object>();
223223
rules.put("*", new HashMap<String, Object>());

src/test/java/com/meilisearch/integration/classes/AbstractIT.java

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -34,13 +34,21 @@ public AbstractIT() {
3434
}
3535

3636
public void setUp() {
37-
if (client == null) client = new Client(new Config("http://localhost:7700", "masterKey"));
37+
if (client == null) client = new Client(new Config(getMeilisearchHost(), "masterKey"));
3838
}
3939

4040
public static void cleanup() {
4141
deleteAllIndexes();
4242
}
4343

44+
public static String getMeilisearchHost() {
45+
String meilisearchHost = System.getenv("MEILISEARCH_HOST");
46+
if (meilisearchHost != null) {
47+
return meilisearchHost;
48+
}
49+
return "http://localhost:7700";
50+
}
51+
4452
public Index createEmptyIndex(String indexUid) throws Exception {
4553
Task task = client.createIndex(indexUid);
4654
client.waitForTask(task.getUid());
@@ -84,7 +92,7 @@ public Key getPrivateKey() throws Exception {
8492

8593
public static void deleteAllIndexes() {
8694
try {
87-
Client ms = new Client(new Config("http://localhost:7700", "masterKey"));
95+
Client ms = new Client(new Config(getMeilisearchHost(), "masterKey"));
8896
Index[] indexes = ms.getIndexList();
8997
for (Index index : indexes) {
9098
ms.deleteIndex(index.getUid());
@@ -96,7 +104,7 @@ public static void deleteAllIndexes() {
96104

97105
public static void deleteAllKeys() {
98106
try {
99-
Client ms = new Client(new Config("http://localhost:7700", "masterKey"));
107+
Client ms = new Client(new Config(getMeilisearchHost(), "masterKey"));
100108
Key[] keys = ms.getKeys();
101109
for (Key key : keys) {
102110
if ((key.getDescription() == null) || (key.getDescription().contains("test"))) {

0 commit comments

Comments
 (0)