Skip to content
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

feat(core): DockerCompose.stop now stops only services that it starts (does not stop the other services) #620

Merged
merged 1 commit into from
Jun 27, 2024

Conversation

aksel
Copy link
Contributor

@aksel aksel commented Jun 27, 2024

The command would otherwise stop/down all services, not just the services the instance itself started.

Useful for e.g. one fixture per service, and you want different scopes for the services.

…esent.

The command would otherwise stop/down all services, not just the services the instance itself started.
Useful for e.g. one fixture per service, and you want different scopes for the services.
@aksel
Copy link
Contributor Author

aksel commented Jun 27, 2024

Apologies if my PR breaks any conventions or contribution guidelines. I was a bit confused by the docs, as they seemed to be targeted towards contributing features, which I don't think this is.

Let me know if I should close, resubmit, or change anything

Thanks! 😄

@alexanderankin alexanderankin changed the title DockerCompose.stop: Append self.services to stop/down command when present. feat(core): DockerCompose.stop: Append self.services to stop/down command when present. Jun 27, 2024
@aksel
Copy link
Contributor Author

aksel commented Jun 27, 2024

My specific use case is this:

import pytest
from testcontainers.compose import DockerCompose


@pytest.fixture(scope="session")
async def aws() -> DockerCompose:
    with DockerCompose(
        ".",
        compose_file_name="docker-compose.yaml",
        pull=True,
        build=True,
        services=["aws"],
        # Wait for localstack to be healthy
        wait=True,
    ) as compose:
        yield compose


@pytest.fixture(scope="module")
async def db(aws) -> DockerCompose:
    with DockerCompose(
        ".",
        compose_file_name="docker-compose.yaml",
        pull=True,
        build=True,
        # Only start the DB
        services=["db"],
        # Wait for the DB to be healthy
        wait=True,
    ) as compose:
        yield compose

Starting up aws takes a while, maybe around 20 seconds, but it can be session scoped and only done once. Until now, both have been session scoped. But now I want to get a clean DB in between modules (or packages, more likely). Nicer isolation and all that. But I couldn't figure out a way to stop only db, while keeping aws running. At first glance, seemed like an oversight, so I thought I might as well submit a PR with the two-line change.

Copy link

codecov bot commented Jun 27, 2024

Codecov Report

All modified and coverable lines are covered by tests ✅

Please upload report for BASE (main@27f2a6b). Learn more about missing BASE report.

Additional details and impacted files
@@           Coverage Diff           @@
##             main     #620   +/-   ##
=======================================
  Coverage        ?   80.29%           
=======================================
  Files           ?       11           
  Lines           ?      604           
  Branches        ?       86           
=======================================
  Hits            ?      485           
  Misses          ?       92           
  Partials        ?       27           

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@alexanderankin alexanderankin changed the title feat(core): DockerCompose.stop: Append self.services to stop/down command when present. feat(core): DockerCompose.stop now stops only services that it starts (does not stop the other services) Jun 27, 2024
@alexanderankin alexanderankin merged commit e711800 into testcontainers:main Jun 27, 2024
11 of 13 checks passed
@aksel aksel deleted the stop-services branch June 27, 2024 15:33
alexanderankin pushed a commit that referenced this pull request Jun 28, 2024
🤖 I have created a release *beep* *boop*
---


##
[4.7.0](testcontainers-v4.6.0...testcontainers-v4.7.0)
(2024-06-28)


### Features

* **core:** Added Generic module
([#612](#612))
([e575b28](e575b28))
* **core:** allow custom dockerfile path for image build and bypassing
build cache
([#615](#615))
([ead0f79](ead0f79)),
closes
[#610](#610)
* **core:** DockerCompose.stop now stops only services that it starts
(does not stop the other services)
([#620](#620))
([e711800](e711800))


### Bug Fixes

* **ollama:** Add support for ollama module
([#618](#618))
([5442d05](5442d05))
* **cosmosdb:** Add support for the CosmosDB Emulator
([#579](#579))
([8045a80](8045a80))
* improve ollama docs, s/ollama_dir/ollama_home/g
([#619](#619))
([27f2a6b](27f2a6b))
* **kafka:** Add Kraft to Kafka containers
([#611](#611))
([762d2a2](762d2a2))


### Documentation

* **contributing:** add contribution and new-container guide
([#460](#460))
([3519f4b](3519f4b))

---
This PR was generated with [Release
Please](https://github.com/googleapis/release-please). See
[documentation](https://github.com/googleapis/release-please#release-please).

Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com>
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.

None yet

2 participants