-
Notifications
You must be signed in to change notification settings - Fork 150
feat: docker-compose support #774
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
base: main
Are you sure you want to change the base?
Conversation
Initial attempt to introduce docker-compose support. Status: work-in-progress
✅ Deploy Preview for testcontainers-rust ready!
To edit notification comments on pull requests, go to your Netlify site configuration. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You can notice there is a code extracted into RawContainer
- it's not strong opinion, but attempt to expose the same functionality for containers created by compose wrapper (e.g logs, exec commands and etc) and for currently existing async-container.
Worth noting that it's still open question if RawContainer
should be pub
, we can just utilize delegation and have two different wrappers - existing AsyncContainer
, and something like ComposeContainer
.
We also could consider adding a trait (e.g compose.get_container("service-name") -> impl ContainerOperations
), but we can achieve backward compatibility for AsyncContainer
via delegation.
impl<I: Image> Deref for ContainerAsync<I> { | ||
type Target = raw::RawContainer; | ||
|
||
fn deref(&self) -> &Self::Target { | ||
&self.raw | ||
} | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
That was for prototyping, final solution is to be made: https://github.com/testcontainers/testcontainers-rs/pull/774/files#r1980314190
// #[tokio::test] | ||
// async fn test_containerised_docker_compose() { | ||
// let path_to_compose = PathBuf::from(format!( | ||
// "{}/tests/test-compose.yml", | ||
// env!("CARGO_MANIFEST_DIR") | ||
// )); | ||
// let docker_compose = | ||
// DockerCompose::with_containerised_client(&[path_to_compose.as_path()]).await; | ||
// docker_compose.up().await; | ||
// tokio::time::sleep(std::time::Duration::from_secs(1)).await; | ||
// let res = reqwest::get("http://localhost:8081/").await.unwrap(); | ||
// assert!(res.status().is_success()); | ||
// } | ||
|
||
#[tokio::test] | ||
async fn test_local_docker_compose() { | ||
let path_to_compose = PathBuf::from(format!( | ||
"{}/tests/test-compose.yml", | ||
env!("CARGO_MANIFEST_DIR") | ||
)); | ||
let docker_compose = DockerCompose::with_local_client(&[path_to_compose.as_path()]); | ||
docker_compose.up().await; | ||
let client = reqwest::get("http://localhost:8081").await.unwrap(); | ||
tokio::time::sleep(std::time::Duration::from_secs(15)).await; | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Both tests work already, but they should be "serial" to avoid a port conflict.
Just not finished because there is no stable interface to access containers from compose
} | ||
|
||
impl ComposeInterface for ComposeClient { | ||
async fn up(&self, command: UpCommand) -> Result<(), std::io::Error> { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
As an option, it should return a list of "raw" containers.
So we can expose method compose.get_container(service_name) -> &RawContainer
(or something like that)
async fn up(&self, command: UpCommand) -> Result<(), std::io::Error> { | |
async fn up(&self, command: UpCommand) -> Result<Vec<RawContainer>, std::io::Error> { |
Description
Initial attempt to introduce docker-compose support.
See #59
Status