Skip to content

Commit 238c0c0

Browse files
authored
Remove default value for TARANTOOL_CLUSTER_COOKIE
- Fix use default value for `TARANTOOL_CLUSTER_COOKIE` - CHANGELOG.md Closes #55
1 parent bc3e7f8 commit 238c0c0

File tree

5 files changed

+57
-11
lines changed

5 files changed

+57
-11
lines changed

CHANGELOG.md

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,13 @@
44

55
## [1.1.1] - 2023-12-13
66

7+
- Remove the default value for `TARANTOOL_CLUSTER_COOKIE` env variable in cartridge container.
8+
Now it works like in cartridge in order of decreasing priority as directed by the user:
9+
`TARANTOOL_CLUSTER_COOKIE > cartridge.cfg > default_cookie`
10+
You can set TARANTOOL_CLUSTER_COOKIE by build-arg on image building or by env arg before container starting
11+
([#55](https://github.com/tarantool/testcontainers-java-tarantool/issues/55))
12+
- **[Breaking change]** Default routerPassword has been changed from `testapp-cluster-cookie` to `secret-cluster-cookie`
13+
([#55](https://github.com/tarantool/testcontainers-java-tarantool/issues/55))
714
- Change private to protected in TarantoolCartridgeContainer
815
- Add support for the `TARANTOOL_VERSION` environment variable to specify the version in the image name
916
`tarantool/tarantool:<TARANTOOL_VERSION>-centos7 when calling the constructor without arguments

src/main/java/org/testcontainers/containers/TarantoolCartridgeContainer.java

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -87,8 +87,8 @@ public class TarantoolCartridgeContainer extends GenericContainer<TarantoolCartr
8787

8888
protected static final String ROUTER_HOST = "localhost";
8989
protected static final int ROUTER_PORT = 3301;
90-
protected static final String CARTRIDGE_USERNAME = "admin";
91-
protected static final String CARTRIDGE_PASSWORD = "testapp-cluster-cookie";
90+
protected static final String CARTRIDGE_DEFAULT_USERNAME = "admin";
91+
protected static final String CARTRIDGE_DEFAULT_PASSWORD = "secret-cluster-cookie";
9292
protected static final String DOCKERFILE = "Dockerfile";
9393
protected static final int API_PORT = 8081;
9494
protected static final String VSHARD_BOOTSTRAP_COMMAND = "return require('cartridge').admin_bootstrap_vshard()";
@@ -107,7 +107,7 @@ public class TarantoolCartridgeContainer extends GenericContainer<TarantoolCartr
107107
public static final String ENV_TARANTOOL_INSTANCES_FILE = "TARANTOOL_INSTANCES_FILE";
108108
public static final String ENV_TARANTOOL_CLUSTER_COOKIE = "TARANTOOL_CLUSTER_COOKIE";
109109
protected static final String healthyCmd = "return require('cartridge').is_healthy()";
110-
protected static final int TWO_MINUTES = 120;
110+
protected static final int TIMEOUT_ROUTER_UP_CARTRIDGE_HEALTH_IN_SECONDS = 60;
111111

112112
protected final CartridgeConfigParser instanceFileParser;
113113
protected final TarantoolContainerClientHelper clientHelper;
@@ -117,8 +117,8 @@ public class TarantoolCartridgeContainer extends GenericContainer<TarantoolCartr
117117
protected String routerHost = ROUTER_HOST;
118118
protected int routerPort = ROUTER_PORT;
119119
protected int apiPort = API_PORT;
120-
protected String routerUsername = CARTRIDGE_USERNAME;
121-
protected String routerPassword = CARTRIDGE_PASSWORD;
120+
protected String routerUsername = CARTRIDGE_DEFAULT_USERNAME;
121+
protected String routerPassword = CARTRIDGE_DEFAULT_PASSWORD;
122122
protected String directoryResourcePath = SCRIPT_RESOURCE_DIRECTORY;
123123
protected String instanceDir = INSTANCE_DIR;
124124
protected String topologyConfigurationFile;
@@ -573,10 +573,10 @@ protected void bootstrapVshard() {
573573
protected void containerIsStarted(InspectContainerResponse containerInfo, boolean reused) {
574574
super.containerIsStarted(containerInfo, reused);
575575

576-
waitUntilRouterIsUp(TWO_MINUTES);
576+
waitUntilRouterIsUp(TIMEOUT_ROUTER_UP_CARTRIDGE_HEALTH_IN_SECONDS);
577577
retryingSetupTopology();
578578
// wait until Roles are configured
579-
waitUntilCartridgeIsHealthy(TWO_MINUTES);
579+
waitUntilCartridgeIsHealthy(TIMEOUT_ROUTER_UP_CARTRIDGE_HEALTH_IN_SECONDS);
580580
bootstrapVshard();
581581

582582
logger().info("Tarantool Cartridge cluster is started");

src/main/resources/Dockerfile

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ ARG TARANTOOL_RUNDIR="/tmp/run"
2222
ARG TARANTOOL_DATADIR="/tmp/data"
2323
ARG TARANTOOL_LOGDIR="/tmp/log"
2424
ARG TARANTOOL_INSTANCES_FILE="./instances.yml"
25-
ARG TARANTOOL_CLUSTER_COOKIE="testapp-cluster-cookie"
25+
ARG TARANTOOL_CLUSTER_COOKIE
2626
ARG START_DELAY="5s"
2727
ENV START_DELAY=$START_DELAY
2828
ENV TARANTOOL_WORKDIR=$TARANTOOL_WORKDIR
@@ -35,5 +35,8 @@ COPY $CARTRIDGE_SRC_DIR $TARANTOOL_WORKDIR
3535
WORKDIR $TARANTOOL_WORKDIR
3636

3737
RUN rm -rf .rocks && cartridge build --verbose
38-
CMD sleep $START_DELAY && cartridge start --run-dir=$TARANTOOL_RUNDIR --data-dir=$TARANTOOL_DATADIR \
39-
--log-dir=$TARANTOOL_LOGDIR --cfg=$TARANTOOL_INSTANCES_FILE
38+
39+
RUN echo 'if [ -z "$TARANTOOL_CLUSTER_COOKIE" ]; then unset TARANTOOL_CLUSTER_COOKIE ; fi ; \
40+
sleep $START_DELAY && cartridge start --run-dir=$TARANTOOL_RUNDIR --data-dir=$TARANTOOL_DATADIR \
41+
--log-dir=$TARANTOOL_LOGDIR --cfg=$TARANTOOL_INSTANCES_FILE' > run.sh && chmod +x run.sh
42+
CMD ./run.sh

src/test/java/org/testcontainers/containers/TarantoolCartridgeBootstrapFromLuaWithFixedPortsTest.java

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
package org.testcontainers.containers;
22

33
import java.time.Duration;
4+
import java.util.List;
5+
import java.util.Map;
46

57
import org.junit.jupiter.api.Test;
68
import org.rnorth.ducttape.RetryCountExceededException;
@@ -11,6 +13,9 @@
1113
import org.testcontainers.junit.jupiter.Testcontainers;
1214
import static org.junit.Assert.assertThrows;
1315
import static org.junit.jupiter.api.Assertions.assertEquals;
16+
import static org.junit.jupiter.api.Assertions.assertFalse;
17+
import static org.junit.jupiter.api.Assertions.assertTrue;
18+
1419

1520
/**
1621
* @author Alexey Kuzin
@@ -38,6 +43,38 @@ public void test_StaticClusterContainer_StartsSuccessfully_ifFilesAreCopied() th
3843
CartridgeContainerTestUtils.executeProfileReplaceSmokeTest(container);
3944
}
4045

46+
@Test
47+
public void testTarantoolClusterCookieDefault() throws Exception {
48+
Map<String, String> env = container.getEnvMap();
49+
assertFalse(env.containsKey(TarantoolCartridgeContainer.ENV_TARANTOOL_CLUSTER_COOKIE));
50+
List<Object> result = container.executeCommandDecoded("return true");
51+
assertEquals(1, result.size());
52+
assertTrue((boolean) result.get(0));
53+
}
54+
55+
@Test
56+
public void testTarantoolClusterCookieWithEnv() throws Exception {
57+
try(TarantoolCartridgeContainer newContainer = new TarantoolCartridgeContainer(
58+
"Dockerfile",
59+
"cartridge",
60+
"cartridge/instances.yml",
61+
"cartridge/replicasets.yml")
62+
.withEnv(TarantoolCartridgeContainer.ENV_TARANTOOL_CLUSTER_COOKIE, "secret")
63+
.withRouterUsername("admin")
64+
.withRouterPassword("secret")
65+
.withStartupTimeout(Duration.ofMinutes(5))
66+
.withLogConsumer(new Slf4jLogConsumer(
67+
LoggerFactory.getLogger(TarantoolCartridgeBootstrapFromYamlTest.class))))
68+
{
69+
newContainer.start();
70+
Map<String, String> env = container.getEnvMap();
71+
assertFalse(env.containsKey(TarantoolCartridgeContainer.ENV_TARANTOOL_CLUSTER_COOKIE));
72+
List<Object> result = container.executeCommandDecoded("return true");
73+
assertEquals(1, result.size());
74+
assertTrue((boolean) result.get(0));
75+
}
76+
}
77+
4178
@Test
4279
public void test_retryingSetupTopology_shouldWork() {
4380
try (TarantoolCartridgeContainer testContainer =

src/test/resources/cartridge/init.lua

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,6 @@ local ok, err = cartridge.cfg({
4141
'app.roles.custom',
4242
'migrator',
4343
},
44-
cluster_cookie = 'testapp-cluster-cookie',
4544
})
4645

4746
assert(ok, tostring(err))

0 commit comments

Comments
 (0)