Skip to content

Remove default value for TARANTOOL_CLUSTER_COOKIE #104

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Dec 14, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,13 @@

## [1.1.1] - 2023-12-13

- Remove the default value for `TARANTOOL_CLUSTER_COOKIE` env variable in cartridge container.
Now it works like in cartridge in order of decreasing priority as directed by the user:
`TARANTOOL_CLUSTER_COOKIE > cartridge.cfg > default_cookie`
You can set TARANTOOL_CLUSTER_COOKIE by build-arg on image building or by env arg before container starting
([#55](https://github.com/tarantool/testcontainers-java-tarantool/issues/55))
- **[Breaking change]** Default routerPassword has been changed from `testapp-cluster-cookie` to `secret-cluster-cookie`
([#55](https://github.com/tarantool/testcontainers-java-tarantool/issues/55))
- Change private to protected in TarantoolCartridgeContainer
- Add support for the `TARANTOOL_VERSION` environment variable to specify the version in the image name
`tarantool/tarantool:<TARANTOOL_VERSION>-centos7 when calling the constructor without arguments
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -87,8 +87,8 @@ public class TarantoolCartridgeContainer extends GenericContainer<TarantoolCartr

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

protected final CartridgeConfigParser instanceFileParser;
protected final TarantoolContainerClientHelper clientHelper;
Expand All @@ -117,8 +117,8 @@ public class TarantoolCartridgeContainer extends GenericContainer<TarantoolCartr
protected String routerHost = ROUTER_HOST;
protected int routerPort = ROUTER_PORT;
protected int apiPort = API_PORT;
protected String routerUsername = CARTRIDGE_USERNAME;
protected String routerPassword = CARTRIDGE_PASSWORD;
protected String routerUsername = CARTRIDGE_DEFAULT_USERNAME;
protected String routerPassword = CARTRIDGE_DEFAULT_PASSWORD;
protected String directoryResourcePath = SCRIPT_RESOURCE_DIRECTORY;
protected String instanceDir = INSTANCE_DIR;
protected String topologyConfigurationFile;
Expand Down Expand Up @@ -573,10 +573,10 @@ protected void bootstrapVshard() {
protected void containerIsStarted(InspectContainerResponse containerInfo, boolean reused) {
super.containerIsStarted(containerInfo, reused);

waitUntilRouterIsUp(TWO_MINUTES);
waitUntilRouterIsUp(TIMEOUT_ROUTER_UP_CARTRIDGE_HEALTH_IN_SECONDS);
retryingSetupTopology();
// wait until Roles are configured
waitUntilCartridgeIsHealthy(TWO_MINUTES);
waitUntilCartridgeIsHealthy(TIMEOUT_ROUTER_UP_CARTRIDGE_HEALTH_IN_SECONDS);
bootstrapVshard();

logger().info("Tarantool Cartridge cluster is started");
Expand Down
9 changes: 6 additions & 3 deletions src/main/resources/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ ARG TARANTOOL_RUNDIR="/tmp/run"
ARG TARANTOOL_DATADIR="/tmp/data"
ARG TARANTOOL_LOGDIR="/tmp/log"
ARG TARANTOOL_INSTANCES_FILE="./instances.yml"
ARG TARANTOOL_CLUSTER_COOKIE="testapp-cluster-cookie"
ARG TARANTOOL_CLUSTER_COOKIE
ARG START_DELAY="5s"
ENV START_DELAY=$START_DELAY
ENV TARANTOOL_WORKDIR=$TARANTOOL_WORKDIR
Expand All @@ -35,5 +35,8 @@ COPY $CARTRIDGE_SRC_DIR $TARANTOOL_WORKDIR
WORKDIR $TARANTOOL_WORKDIR

RUN rm -rf .rocks && cartridge build --verbose
CMD sleep $START_DELAY && cartridge start --run-dir=$TARANTOOL_RUNDIR --data-dir=$TARANTOOL_DATADIR \
--log-dir=$TARANTOOL_LOGDIR --cfg=$TARANTOOL_INSTANCES_FILE

RUN echo 'if [ -z "$TARANTOOL_CLUSTER_COOKIE" ]; then unset TARANTOOL_CLUSTER_COOKIE ; fi ; \
sleep $START_DELAY && cartridge start --run-dir=$TARANTOOL_RUNDIR --data-dir=$TARANTOOL_DATADIR \
--log-dir=$TARANTOOL_LOGDIR --cfg=$TARANTOOL_INSTANCES_FILE' > run.sh && chmod +x run.sh
CMD ./run.sh
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
package org.testcontainers.containers;

import java.time.Duration;
import java.util.List;
import java.util.Map;

import org.junit.jupiter.api.Test;
import org.rnorth.ducttape.RetryCountExceededException;
Expand All @@ -11,6 +13,9 @@
import org.testcontainers.junit.jupiter.Testcontainers;
import static org.junit.Assert.assertThrows;
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertFalse;
import static org.junit.jupiter.api.Assertions.assertTrue;


/**
* @author Alexey Kuzin
Expand Down Expand Up @@ -38,6 +43,38 @@ public void test_StaticClusterContainer_StartsSuccessfully_ifFilesAreCopied() th
CartridgeContainerTestUtils.executeProfileReplaceSmokeTest(container);
}

@Test
public void testTarantoolClusterCookieDefault() throws Exception {
Map<String, String> env = container.getEnvMap();
assertFalse(env.containsKey(TarantoolCartridgeContainer.ENV_TARANTOOL_CLUSTER_COOKIE));
List<Object> result = container.executeCommandDecoded("return true");
assertEquals(1, result.size());
assertTrue((boolean) result.get(0));
}

@Test
public void testTarantoolClusterCookieWithEnv() throws Exception {
try(TarantoolCartridgeContainer newContainer = new TarantoolCartridgeContainer(
"Dockerfile",
"cartridge",
"cartridge/instances.yml",
"cartridge/replicasets.yml")
.withEnv(TarantoolCartridgeContainer.ENV_TARANTOOL_CLUSTER_COOKIE, "secret")
.withRouterUsername("admin")
.withRouterPassword("secret")
.withStartupTimeout(Duration.ofMinutes(5))
.withLogConsumer(new Slf4jLogConsumer(
LoggerFactory.getLogger(TarantoolCartridgeBootstrapFromYamlTest.class))))
{
newContainer.start();
Map<String, String> env = container.getEnvMap();
assertFalse(env.containsKey(TarantoolCartridgeContainer.ENV_TARANTOOL_CLUSTER_COOKIE));
List<Object> result = container.executeCommandDecoded("return true");
assertEquals(1, result.size());
assertTrue((boolean) result.get(0));
}
}

@Test
public void test_retryingSetupTopology_shouldWork() {
try (TarantoolCartridgeContainer testContainer =
Expand Down
1 change: 0 additions & 1 deletion src/test/resources/cartridge/init.lua
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,6 @@ local ok, err = cartridge.cfg({
'app.roles.custom',
'migrator',
},
cluster_cookie = 'testapp-cluster-cookie',
})

assert(ok, tostring(err))