1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54
use std::borrow::Cow;
use testcontainers::{
core::{ContainerPort, WaitFor},
Image,
};
const NAME: &str = "docker.elastic.co/elasticsearch/elasticsearch";
const TAG: &str = "7.16.1";
/// Port that the [`Elasticsearch`] container has internally
/// Used **for API calls over http**, including search, aggregation, monitoring, ...
/// Client libraries have switched to using this to communicate to elastic.
/// Can be rebound externally via [`testcontainers::core::ImageExt::with_mapped_port`]
///
/// [`Elasticsearch`]: https://elastic.co/
pub const ELASTICSEARCH_API_PORT: ContainerPort = ContainerPort::Tcp(9200);
/// Port that the [`Elasticsearch`] container has internally.
/// Used **for nodes to communicate between each other** and handles cluster updates naster elections, nodes leaving/joining, ...
/// Can be rebound externally via [`testcontainers::core::ImageExt::with_mapped_port`]
///
/// [`Elasticsearch`]: https://elastic.co/
pub const ELASTICSEARCH_INTER_NODE_PORT: ContainerPort = ContainerPort::Tcp(9300);
#[derive(Debug, Default, Clone)]
pub struct ElasticSearch {
_priv: (),
}
impl Image for ElasticSearch {
fn name(&self) -> &str {
NAME
}
fn tag(&self) -> &str {
TAG
}
fn ready_conditions(&self) -> Vec<WaitFor> {
vec![WaitFor::message_on_stdout("[YELLOW] to [GREEN]")]
}
fn env_vars(
&self,
) -> impl IntoIterator<Item = (impl Into<Cow<'_, str>>, impl Into<Cow<'_, str>>)> {
[("discovery.type", "single-node")]
}
fn expose_ports(&self) -> &[ContainerPort] {
&[ELASTICSEARCH_API_PORT, ELASTICSEARCH_INTER_NODE_PORT]
}
}
#[cfg(test)]
mod tests {}