Skip to content

Commit

Permalink
docs: documented all ports which containers at least expose (#183)
Browse files Browse the repository at this point in the history
  • Loading branch information
CommanderStorm authored Aug 21, 2024
1 parent 6d3f509 commit 6abbe09
Show file tree
Hide file tree
Showing 9 changed files with 72 additions and 11 deletions.
4 changes: 4 additions & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -116,3 +116,7 @@ required-features = ["mssql_server"]
[[example]]
name = "surrealdb"
required-features = ["surrealdb"]

[[example]]
name = "mongo"
required-features = ["mongo"]
6 changes: 5 additions & 1 deletion src/clickhouse/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,11 @@ use testcontainers::{
const DEFAULT_IMAGE_NAME: &str = "clickhouse/clickhouse-server";
const DEFAULT_IMAGE_TAG: &str = "23.3.8.21-alpine";

const CLICKHOUSE_PORT: ContainerPort = ContainerPort::Tcp(8123);
/// Port that the [`ClickHouse`] container has internally
/// Can be rebound externally via [`testcontainers::core::ImageExt::with_mapped_port`]
///
/// [`ClickHouse`]: https://clickhouse.com/
pub const CLICKHOUSE_PORT: ContainerPort = ContainerPort::Tcp(8123);

/// Module to work with [`ClickHouse`] inside of tests.
///
Expand Down
15 changes: 14 additions & 1 deletion src/elastic_search/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,19 @@ use testcontainers::{

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 {
Expand All @@ -33,7 +46,7 @@ impl Image for ElasticSearch {
}

fn expose_ports(&self) -> &[ContainerPort] {
&[ContainerPort::Tcp(9200), ContainerPort::Tcp(9300)]
&[ELASTICSEARCH_API_PORT, ELASTICSEARCH_INTER_NODE_PORT]
}
}

Expand Down
14 changes: 13 additions & 1 deletion src/k3s/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,14 +13,26 @@ use testcontainers::{

const NAME: &str = "rancher/k3s";
const TAG: &str = "v1.28.8-k3s1";
/// Port that the [`traefik`] part of the container has internally
/// Can be rebound externally via [`testcontainers::core::ImageExt::with_mapped_port`]
///
/// [`traefik`]: https://doc.traefik.io/traefik/
pub const TRAEFIK_HTTP: ContainerPort = ContainerPort::Tcp(80);
/// Port that the [`Kubernetes`] part of the container has internally
/// Can be rebound externally via [`testcontainers::core::ImageExt::with_mapped_port`]
///
/// [`Kubernetes`]: https://kubernetes.io/
pub const KUBE_SECURE_PORT: ContainerPort = ContainerPort::Tcp(6443);
/// Port that the [`Rancher`] part of the container has internally
/// Can be rebound externally via [`testcontainers::core::ImageExt::with_mapped_port`]
///
/// [`Rancher`]: https://rancher.io/
pub const RANCHER_WEBHOOK_PORT: ContainerPort = ContainerPort::Tcp(8443);

/// Module to work with [`K3s`] inside of tests.
///
/// Starts an instance of K3s, a single-node server fully-functional Kubernetes cluster
/// so you are able interact with the cluster using standard [`Kubernetes API`] exposed at [`KUBE_SECURE_PORT`] port
/// so you are able to interact with the cluster using standard [`Kubernetes API`] exposed at [`KUBE_SECURE_PORT`] port
///
/// This module is based on the official [`K3s docker image`].
///
Expand Down
14 changes: 11 additions & 3 deletions src/kafka/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,16 @@ use testcontainers::{

const NAME: &str = "confluentinc/cp-kafka";
const TAG: &str = "6.1.1";

/// Port that the [`Kafka`] part of the container has internally
/// Can be rebound externally via [`testcontainers::core::ImageExt::with_mapped_port`]
///
/// [`Kafka`]: https://kafka.apache.org/
pub const KAFKA_PORT: u16 = 9093;
const ZOOKEEPER_PORT: u16 = 2181;
/// Port that the [`Zookeeper`] part of the container has internally
/// Can be rebound externally via [`testcontainers::core::ImageExt::with_mapped_port`]
///
/// [`Zookeeper`]: https://zookeeper.apache.org/
pub const ZOOKEEPER_PORT: ContainerPort = ContainerPort::Tcp(2181);

#[derive(Debug, Clone)]
pub struct Kafka {
Expand All @@ -22,7 +29,7 @@ impl Default for Kafka {

env_vars.insert(
"KAFKA_ZOOKEEPER_CONNECT".to_owned(),
format!("localhost:{ZOOKEEPER_PORT}"),
format!("localhost:{}", ZOOKEEPER_PORT.as_u16()),
);
env_vars.insert(
"KAFKA_LISTENERS".to_owned(),
Expand Down Expand Up @@ -82,6 +89,7 @@ zookeeper-server-start zookeeper.properties &
. /etc/confluent/docker/bash-config &&
/etc/confluent/docker/configure &&
/etc/confluent/docker/launch"#,
ZOOKEEPER_PORT = ZOOKEEPER_PORT.as_u16()
),
]
}
Expand Down
11 changes: 9 additions & 2 deletions src/kwok/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,13 @@ use testcontainers::{
const NAME: &str = "registry.k8s.io/kwok/cluster";
const TAG: &str = "v0.5.2-k8s.v1.29.2";
const DEFAULT_WAIT: u64 = 3000;
/// Port that the [`Kwok Cluster`] container has internally
/// Can be rebound externally via [`testcontainers::core::ImageExt::with_mapped_port`]
///
/// [`Kwok Cluster`]: https://kwok.sigs.k8s.io/
pub const KWOK_CLUSTER_PORT: ContainerPort = ContainerPort::Tcp(8080);

/// This module provides [Kwok Cluster](https://kwok.sigs.k8s.io/) (Kubernetes WithOut Kubelet).
/// This module provides [`Kwok Cluster`] (Kubernetes WithOut Kubelet).
///
/// Currently pinned to [version `v0.5.2-k8s.v1.29.2`](https://github.com/kubernetes-sigs/kwok/releases/tag/v0.5.2)
///
Expand All @@ -25,6 +30,8 @@ const DEFAULT_WAIT: u64 = 3000;
/// ```
///
/// No environment variables are required.
///
/// [`Kwok Cluster`]: https://kwok.sigs.k8s.io/
#[derive(Debug, Default, Clone)]
pub struct KwokCluster;

Expand All @@ -45,7 +52,7 @@ impl Image for KwokCluster {
}

fn expose_ports(&self) -> &[ContainerPort] {
&[ContainerPort::Tcp(8080)]
&[KWOK_CLUSTER_PORT]
}
}

Expand Down
6 changes: 5 additions & 1 deletion src/meilisearch/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,11 @@ use testcontainers::{

const NAME: &str = "getmeili/meilisearch";
const TAG: &str = "v1.8.3";
const MEILISEARCH_PORT: ContainerPort = ContainerPort::Tcp(7700);
/// Port that the [`Meilisearch`] container has internally
/// Can be rebound externally via [`testcontainers::core::ImageExt::with_mapped_port`]
///
/// [`Meilisearch`]: https://www.meilisearch.com
pub const MEILISEARCH_PORT: ContainerPort = ContainerPort::Tcp(7700);

/// Module to work with [`Meilisearch`] inside of tests.
///
Expand Down
7 changes: 6 additions & 1 deletion src/oracle/free.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,11 @@ use testcontainers::{

const DEFAULT_IMAGE_NAME: &str = "gvenzl/oracle-free";
const DEFAULT_IMAGE_TAG: &str = "23-slim-faststart";
/// Port that the [`Oracle Database Free`] container has internally
/// Can be rebound externally via [`testcontainers::core::ImageExt::with_mapped_port`]
///
/// [`Oracle Database Free`]: https://www.oracle.com/database/free/
pub const FREE_PORT: ContainerPort = ContainerPort::Tcp(1521);

/// Module to work with [`Oracle Database Free`] inside of tests.
/// The default image is [`gvenzl/oracle-free:23-slim-faststart`] (unofficial).
Expand Down Expand Up @@ -64,7 +69,7 @@ impl Image for Oracle {
}

fn expose_ports(&self) -> &[ContainerPort] {
&[ContainerPort::Tcp(1521)]
&[FREE_PORT]
}
}

Expand Down
6 changes: 5 additions & 1 deletion src/surrealdb/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,10 @@ use testcontainers::{
const NAME: &str = "surrealdb/surrealdb";
const TAG: &str = "v1.1.1";

/// Port that the [`SurrealDB`] container has internally
/// Can be rebound externally via [`testcontainers::core::ImageExt::with_mapped_port`]
///
/// [`SurrealDB`]: https://surrealdb.com/
pub const SURREALDB_PORT: ContainerPort = ContainerPort::Tcp(8000);

/// Module to work with [`SurrealDB`] inside of tests.
Expand Down Expand Up @@ -130,7 +134,7 @@ mod tests {
opt::auth::Root,
Surreal,
};
use testcontainers::runners::AsyncRunner;
use testcontainers::{runners::AsyncRunner, ImageExt};

use super::*;

Expand Down

0 comments on commit 6abbe09

Please sign in to comment.