testcontainers_modules/elastic_search/
mod.rs

1use std::borrow::Cow;
2
3use testcontainers::{
4    core::{ContainerPort, WaitFor},
5    Image,
6};
7
8const NAME: &str = "docker.elastic.co/elasticsearch/elasticsearch";
9const TAG: &str = "7.16.1";
10/// Port that the [`Elasticsearch`] container has internally
11/// Used **for API calls over http**, including search, aggregation, monitoring, ...
12/// Client libraries have switched to using this to communicate to elastic.
13/// Can be rebound externally via [`testcontainers::core::ImageExt::with_mapped_port`]
14///
15/// [`Elasticsearch`]: https://elastic.co/
16pub const ELASTICSEARCH_API_PORT: ContainerPort = ContainerPort::Tcp(9200);
17/// Port that the [`Elasticsearch`] container has internally.
18/// Used **for nodes to communicate between each other** and handles cluster updates naster elections, nodes leaving/joining, ...
19/// Can be rebound externally via [`testcontainers::core::ImageExt::with_mapped_port`]
20///
21/// [`Elasticsearch`]: https://elastic.co/
22pub const ELASTICSEARCH_INTER_NODE_PORT: ContainerPort = ContainerPort::Tcp(9300);
23
24#[allow(missing_docs)]
25// not having docs here is currently allowed to address the missing docs problem one place at a time. Helping us by documenting just one of these places helps other devs tremendously
26#[derive(Debug, Default, Clone)]
27pub struct ElasticSearch {
28    /// (remove if there is another variable)
29    /// Field is included to prevent this struct to be a unit struct.
30    /// This allows extending functionality (and thus further variables) without breaking changes
31    _priv: (),
32}
33
34impl Image for ElasticSearch {
35    fn name(&self) -> &str {
36        NAME
37    }
38
39    fn tag(&self) -> &str {
40        TAG
41    }
42
43    fn ready_conditions(&self) -> Vec<WaitFor> {
44        vec![WaitFor::message_on_stdout("[YELLOW] to [GREEN]")]
45    }
46
47    fn env_vars(
48        &self,
49    ) -> impl IntoIterator<Item = (impl Into<Cow<'_, str>>, impl Into<Cow<'_, str>>)> {
50        [("discovery.type", "single-node")]
51    }
52
53    fn expose_ports(&self) -> &[ContainerPort] {
54        &[ELASTICSEARCH_API_PORT, ELASTICSEARCH_INTER_NODE_PORT]
55    }
56}
57
58#[cfg(test)]
59mod tests {}