Thanks to visit codestin.com
Credit goes to github.com

Skip to content

add container configurators for bootstrapping localstack #9050

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

Merged
merged 4 commits into from
Sep 4, 2023

Conversation

thrau
Copy link
Member

@thrau thrau commented Sep 1, 2023

Motivation

With the new Container concept and the ContainerFactory fixture introduced in #8781, we now want an easy and re-usable way to configure containers. For instance, to test extensions, I always want to create a fresh localstack pro container with certain default configurations. The code doing the configuration should ideally be re-usable, have high-level concepts of the localstack container (such as "mount the localstack volume directory", "set gateway listen correctly"), while allowing fine-grained configuration of containers.

In #8994 I introduced a concept that is inspired by the Functional Options Pattern from go. I evolved this into a basic set of configurators that are typical for localstack.

This gives a very neat way of configuring the container together with the container factory, where you can see exactly what configurations are being added to the container:

  container: Container = container_factory(
      configurators=[
          ContainerConfigurators.random_container_name,
          ContainerConfigurators.random_gateway_port,
          ContainerConfigurators.debug,
          ContainerConfigurators.mount_docker_socket,
          ContainerConfigurators.mount_localstack_volume("/tmp/localstack"),
      ]
  )

Furthermore, I wanted a way to stream container logs when running container tests, so I added a fixture that can be used as follows:

def test(container_factory, stream_container_logs)
    container: Container = container_factory(...)
    with container.start() as running_container:
        stream_container_logs(container)

This creates a new background thread that will stream the logs of the container into a logger called container.<container-name>.

Changes

  • Add ContainerConfigurator concept
  • Make Container aware of these configurators
  • Add a default set of container configurators
  • Refactor the configure_container method used by the CLI to use these configurators
  • Add way to determine the gateway URL from a Container
  • Add some tests and a fixture to stream logs
  • Sneaked in a few changes to use VolumeMappings.add instead of append so we can maybe get rid of one of the functions

TODO

@thrau thrau requested a review from simonrw September 1, 2023 21:50
@thrau thrau added the semver: minor Non-breaking changes which can be included in minor releases, but not in patch releases label Sep 1, 2023
@thrau thrau removed the request for review from joe4dev September 1, 2023 22:06
@thrau thrau force-pushed the container-fixture-configurators branch from c84d121 to 55bbc11 Compare September 1, 2023 22:07
@github-actions
Copy link

github-actions bot commented Sep 1, 2023

LocalStack Community integration with Pro

       2 files         2 suites   1h 31m 39s ⏱️
2 152 tests 1 676 ✔️ 476 💤 0
2 153 runs  1 676 ✔️ 477 💤 0

Results for commit fcac5b7.

♻️ This comment has been updated with latest results.

@thrau thrau marked this pull request as draft September 2, 2023 19:46
@thrau thrau force-pushed the container-fixture-configurators branch 2 times, most recently from 7617c1f to 06472e7 Compare September 3, 2023 01:00
@thrau thrau mentioned this pull request Sep 3, 2023
4 tasks
@thrau thrau force-pushed the container-fixture-configurators branch from 06472e7 to c8cb194 Compare September 3, 2023 17:42
@thrau thrau marked this pull request as ready for review September 3, 2023 18:04
@thrau
Copy link
Member Author

thrau commented Sep 3, 2023

testfailures are unrelated to the changes

Copy link
Contributor

@simonrw simonrw left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks like a great set of changes. Just some minor nits.

Copy link
Member

@dfangl dfangl left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM, love the new configuration options and used patterns!

@thrau thrau force-pushed the container-fixture-configurators branch from 5346793 to fcac5b7 Compare September 4, 2023 19:10
@thrau thrau merged commit 3a7c348 into master Sep 4, 2023
@thrau thrau deleted the container-fixture-configurators branch September 4, 2023 20:29
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
semver: minor Non-breaking changes which can be included in minor releases, but not in patch releases
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants