Skip to content
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

Deprecate support for docker.elastic.co/elasticsearch/elasticsearch-oss #4574

Merged
merged 6 commits into from
Nov 30, 2023
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
9 changes: 0 additions & 9 deletions docs/modules/elasticsearch.md
Original file line number Diff line number Diff line change
Expand Up @@ -28,15 +28,6 @@ You can turn on security by providing a password:
[HttpClient](../../modules/elasticsearch/src/test/java/org/testcontainers/elasticsearch/ElasticsearchContainerTest.java) inside_block:httpClientSecuredContainer
<!--/codeinclude-->

## Choose your Elasticsearch license

If you prefer to start a Docker image with the pure OSS version (which means with no security in older versions or
other new and advanced features), you can use this instead:

<!--codeinclude-->
[Elasticsearch OSS](../../modules/elasticsearch/src/test/java/org/testcontainers/elasticsearch/ElasticsearchContainerTest.java) inside_block:ossContainer
<!--/codeinclude-->

## Adding this module to your project dependencies

Add the following dependency to your `pom.xml`/`build.gradle` file:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,14 +32,12 @@ public class ElasticsearchContainer extends GenericContainer<ElasticsearchContai
* Elasticsearch Docker base image
*/
private static final DockerImageName DEFAULT_IMAGE_NAME = DockerImageName.parse("docker.elastic.co/elasticsearch/elasticsearch");
private static final DockerImageName DEFAULT_OSS_IMAGE_NAME = DockerImageName.parse("docker.elastic.co/elasticsearch/elasticsearch-oss");

/**
* Elasticsearch Default version
*/
@Deprecated
protected static final String DEFAULT_TAG = "7.9.2";
private boolean isOss = false;
protected static final String DEFAULT_TAG = "7.15.0";
eddumelendez marked this conversation as resolved.
Show resolved Hide resolved

/**
* @deprecated use {@link ElasticsearchContainer(DockerImageName)} instead
Expand All @@ -51,24 +49,20 @@ public ElasticsearchContainer() {

/**
* Create an Elasticsearch Container by passing the full docker image name
* @param dockerImageName Full docker image name as a {@link String}, like: docker.elastic.co/elasticsearch/elasticsearch:7.9.2
* @param dockerImageName Full docker image name as a {@link String}, like: docker.elastic.co/elasticsearch/elasticsearch:7.15.0
eddumelendez marked this conversation as resolved.
Show resolved Hide resolved
*/
public ElasticsearchContainer(String dockerImageName) {
this(DockerImageName.parse(dockerImageName));
}

/**
* Create an Elasticsearch Container by passing the full docker image name
* @param dockerImageName Full docker image name as a {@link DockerImageName}, like: DockerImageName.parse("docker.elastic.co/elasticsearch/elasticsearch:7.9.2")
* @param dockerImageName Full docker image name as a {@link DockerImageName}, like: DockerImageName.parse("docker.elastic.co/elasticsearch/elasticsearch:7.15.0")
eddumelendez marked this conversation as resolved.
Show resolved Hide resolved
*/
public ElasticsearchContainer(final DockerImageName dockerImageName) {
super(dockerImageName);

dockerImageName.assertCompatibleWith(DEFAULT_IMAGE_NAME, DEFAULT_OSS_IMAGE_NAME);

if (dockerImageName.isCompatibleWith(DEFAULT_OSS_IMAGE_NAME)) {
this.isOss = true;
}
dockerImageName.assertCompatibleWith(DEFAULT_IMAGE_NAME);

logger().info("Starting an elasticsearch container using [{}]", dockerImageName);
withNetworkAliases("elasticsearch-" + Base58.randomString(6));
Expand All @@ -82,16 +76,12 @@ public ElasticsearchContainer(final DockerImageName dockerImageName) {

/**
* Define the Elasticsearch password to set. It enables security behind the scene.
* It's not possible to use security with the oss image.
* @param password Password to set
* @return this
*/
public ElasticsearchContainer withPassword(String password) {
if (isOss) {
throw new IllegalArgumentException("You can not activate security on Elastic OSS Image. " +
"Please switch to the default distribution");
}
withEnv("ELASTIC_PASSWORD", password);
// In version 8.0, security will be enabled by default
dadoonet marked this conversation as resolved.
Show resolved Hide resolved
withEnv("xpack.security.enabled", "true");
return this;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ public class ElasticsearchContainerTest {
/**
* Elasticsearch version which should be used for the Tests
*/
private static final String ELASTICSEARCH_VERSION = "7.9.2";
private static final String ELASTICSEARCH_VERSION = "7.15.0";
eddumelendez marked this conversation as resolved.
Show resolved Hide resolved
private static final DockerImageName ELASTICSEARCH_IMAGE =
DockerImageName
.parse("docker.elastic.co/elasticsearch/elasticsearch")
Expand Down Expand Up @@ -136,27 +136,6 @@ public void elasticsearchVersion() throws IOException {
}
}

@Test
public void elasticsearchOssImage() throws IOException {
try (ElasticsearchContainer container =
// ossContainer {
new ElasticsearchContainer(
DockerImageName
.parse("docker.elastic.co/elasticsearch/elasticsearch-oss")
.withTag(ELASTICSEARCH_VERSION)
)
// }
) {
container.start();
Response response = getClient(container).performRequest(new Request("GET", "/"));
assertThat(response.getStatusLine().getStatusCode(), is(200));
// The OSS image does not have any feature under Elastic License
assertThrows("We should not have /_xpack endpoint with an OSS License",
ResponseException.class,
() -> getClient(container).performRequest(new Request("GET", "/_xpack/")));
}
}

@Test
public void restClientClusterHealth() throws IOException {
// httpClientContainer {
Expand Down Expand Up @@ -236,19 +215,6 @@ public void transportClientClusterHealth() {
// }
}

@Test
public void incompatibleSettingsTest() {
// The OSS image can not use security feature
assertThrows("We should not be able to activate security with an OSS License",
IllegalArgumentException.class,
() -> new ElasticsearchContainer(
DockerImageName
.parse("docker.elastic.co/elasticsearch/elasticsearch-oss")
.withTag(ELASTICSEARCH_VERSION))
.withPassword("foo")
);
}

private RestClient getClient(ElasticsearchContainer container) {
if (client == null) {
final CredentialsProvider credentialsProvider = new BasicCredentialsProvider();
Expand Down