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 4 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
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,13 +32,17 @@ public class ElasticsearchContainer extends GenericContainer<ElasticsearchContai
* Elasticsearch Docker base image
*/
private static final DockerImageName DEFAULT_IMAGE_NAME = DockerImageName.parse("docker.elastic.co/elasticsearch/elasticsearch");

@Deprecated
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";
protected static final String DEFAULT_TAG = "7.15.0";
eddumelendez marked this conversation as resolved.
Show resolved Hide resolved

@Deprecated
private boolean isOss = false;

/**
Expand All @@ -51,15 +55,15 @@ 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);
Expand All @@ -68,6 +72,9 @@ public ElasticsearchContainer(final DockerImageName dockerImageName) {

if (dockerImageName.isCompatibleWith(DEFAULT_OSS_IMAGE_NAME)) {
this.isOss = true;
logger().warn("The -oss version is not supported anymore after 7.10.2. Please switch to {}:{}",
DEFAULT_IMAGE_NAME.getUnversionedPart(),
dockerImageName.getVersionPart());
}

logger().info("Starting an elasticsearch container using [{}]", dockerImageName);
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 @@ -138,15 +138,7 @@ 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)
)
// }
) {
try (ElasticsearchContainer container = new ElasticsearchContainer("docker.elastic.co/elasticsearch/elasticsearch-oss:7.10.2")) {
container.start();
Response response = getClient(container).performRequest(new Request("GET", "/"));
assertThat(response.getStatusLine().getStatusCode(), is(200));
Expand Down Expand Up @@ -211,6 +203,32 @@ public void restClientSecuredClusterHealth() throws IOException {
// }
}

@Test
public void restClientSecuredClusterHealthWith8_0_0() throws IOException {
// Create the elasticsearch container.
try (ElasticsearchContainer container = new ElasticsearchContainer("docker.elastic.co/elasticsearch/elasticsearch:8.0.0-alpha2")
// With a password
.withPassword(ELASTICSEARCH_PASSWORD)) {
// Start the container. This step might take some time...
container.start();

// Create the secured client.
final CredentialsProvider credentialsProvider = new BasicCredentialsProvider();
credentialsProvider.setCredentials(AuthScope.ANY,
new UsernamePasswordCredentials(ELASTICSEARCH_USERNAME, ELASTICSEARCH_PASSWORD));

client = RestClient.builder(HttpHost.create(container.getHttpHostAddress()))
.setHttpClientConfigCallback(httpClientBuilder -> httpClientBuilder.setDefaultCredentialsProvider(credentialsProvider))
.build();

Response response = client.performRequest(new Request("GET", "/_cluster/health"));
// }}
assertThat(response.getStatusLine().getStatusCode(), is(200));
assertThat(EntityUtils.toString(response.getEntity()), containsString("cluster_name"));
}
// }
}

eddumelendez marked this conversation as resolved.
Show resolved Hide resolved
@SuppressWarnings("deprecation") // The TransportClient will be removed in Elasticsearch 8.
@Test
public void transportClientClusterHealth() {
Expand Down Expand Up @@ -241,11 +259,7 @@ 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")
() -> new ElasticsearchContainer("docker.elastic.co/elasticsearch/elasticsearch-oss:7.10.2").withPassword("foo")
);
}

Expand Down