Skip to content

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

Draft
wants to merge 1 commit into
base: main
Choose a base branch
from
Draft

feat: docker-compose support #774

wants to merge 1 commit into from

Conversation

DDtKey
Copy link
Collaborator

@DDtKey DDtKey commented Mar 4, 2025

Description

Initial attempt to introduce docker-compose support.

See #59

Status

  • work-in-progress

Initial attempt to introduce docker-compose support.

Status: work-in-progress
Copy link

netlify bot commented Mar 4, 2025

Deploy Preview for testcontainers-rust ready!

Name Link
🔨 Latest commit dd129b4
🔍 Latest deploy log https://app.netlify.com/sites/testcontainers-rust/deploys/67c77529e0dc5f00085e460b
😎 Deploy Preview https://deploy-preview-774--testcontainers-rust.netlify.app
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.

To edit notification comments on pull requests, go to your Netlify site configuration.

Copy link
Collaborator Author

@DDtKey DDtKey Mar 4, 2025

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.

Comment on lines +200 to +206
impl<I: Image> Deref for ContainerAsync<I> {
type Target = raw::RawContainer;

fn deref(&self) -> &Self::Target {
&self.raw
}
}
Copy link
Collaborator Author

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

Comment on lines +107 to +131
// #[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;
}
Copy link
Collaborator Author

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> {
Copy link
Collaborator Author

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)

Suggested change
async fn up(&self, command: UpCommand) -> Result<(), std::io::Error> {
async fn up(&self, command: UpCommand) -> Result<Vec<RawContainer>, std::io::Error> {

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant