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

chore: support for multiple lifecycles defined by the user #1037

Merged
merged 4 commits into from
Apr 5, 2023

Conversation

mdelapenya
Copy link
Member

  • chore: support for multiple container life cycles
  • chore: define a default logging hook
  • chore: extract copying files to the postCreate hook

What does this PR do?

In this PR we are updating the lifecycle field of the container request to accept an array of lifecycles structs.

With this in mind, a user could define custom lifecycles to be appended to the list of container lifecycles, which the library will execute in the order they are passed.

Therefore, given two lifecycles in a container request this will be the execution order:

  1. lifecycle-1
    1.1 pre-create
    1.2 post-create
    1.3 pre-start
    1.4 post-start
    1.5 pre-stop
    1.6 post-stop
    1.7 pre-terminate
    1.8 post-terminate
  2. lifecycle-2
    2.1 pre-create
    2.2 post-create
    2.3 pre-start
    2.4 post-start
    2.5 pre-stop
    2.6 post-stop
    2.7 pre-terminate
    2.8 post-terminate

Besides that, we are refactoring library code to wrap into into functions to leverage the lifecycle, injecting them at the right lifecycle event:

  • pre-creation hook will be always prepended to the lifecycles at the container request
  • copying the files from the request to a container has been converted into a post-creation hook

Finally, we are providing with a default logger hook, which leverages the internal logger of the container to print out messages on each lifecycle hook.

Why is it important?

Support for multiple lifecycle hook that could be decoupled from the library, and provide a simple to use manner of logging the events.

Examples: a lifecycle that sends OpenTelemetry traces.

Related issues

@mdelapenya mdelapenya requested a review from a team as a code owner April 5, 2023 15:34
@mdelapenya mdelapenya added the chore Changes that do not impact the existing functionality label Apr 5, 2023
@mdelapenya mdelapenya self-assigned this Apr 5, 2023
@netlify
Copy link

netlify bot commented Apr 5, 2023

Deploy Preview for testcontainers-go ready!

Name Link
🔨 Latest commit 9f7ffa0
🔍 Latest deploy log https://app.netlify.com/sites/testcontainers-go/deploys/642db1eab5b2dd00083b0ad1
😎 Deploy Preview https://deploy-preview-1037--testcontainers-go.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 settings.

@sonarcloud
Copy link

sonarcloud bot commented Apr 5, 2023

Kudos, SonarCloud Quality Gate passed!    Quality Gate passed

Bug A 0 Bugs
Vulnerability A 0 Vulnerabilities
Security Hotspot A 0 Security Hotspots
Code Smell A 0 Code Smells

No Coverage information No Coverage information
13.3% 13.3% Duplication

@mdelapenya mdelapenya merged commit e1539bc into testcontainers:main Apr 5, 2023
@mdelapenya mdelapenya deleted the multiple-lifecycles branch April 6, 2023 06:54
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
chore Changes that do not impact the existing functionality
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant