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

[Enhancement]: Properly define the execution order for container lifecycle hooks #1919

Closed
mdelapenya opened this issue Nov 15, 2023 · 0 comments · Fixed by #1922
Closed

[Enhancement]: Properly define the execution order for container lifecycle hooks #1919

mdelapenya opened this issue Nov 15, 2023 · 0 comments · Fixed by #1922
Assignees
Labels
enhancement New feature or request

Comments

@mdelapenya
Copy link
Collaborator

Proposal

At this moment, user-defined hooks are enqueued after the library-defined hooks (default logging, file copying). This is fine until we added the ability to add startup commands to the modules API, to run code right after the container is started.

It could be the case a user wants to add a startup command, and wait for something caused by that command, but because wait strategies are executed before the user-defined hooks (see

testcontainers-go/docker.go

Lines 1031 to 1056 in 1818971

PostStarts: []ContainerHook{
// first post-start hook is to wait for the container to be ready
func(ctx context.Context, c Container) error {
dockerContainer := c.(*DockerContainer)
// if a Wait Strategy has been specified, wait before returning
if dockerContainer.WaitingFor != nil {
dockerContainer.logger.Printf(
"🚧 Waiting for container id %s image: %s. Waiting for: %+v",
dockerContainer.ID[:12], dockerContainer.Image, dockerContainer.WaitingFor,
)
if err := dockerContainer.WaitingFor.WaitUntilReady(ctx, c); err != nil {
return err
}
}
dockerContainer.isRunning = true
return nil
},
},
},
}
// always prepend default lifecycle hooks to user-defined hooks
req.LifecycleHooks = append(defaultHooks, req.LifecycleHooks...)
) then it will be impossible for users to achieve that.

We propose define the following schema:

  • make a distinction between user-defined hooks, and library hooks, where:
    • library hooks are mandatory (default logging, file copying)
    • user-defined hooks are optional, defined in the container request
    • Pre hooks: always run library hooks before user-defined hooks
    • Post hooks: always run library hooks after user-defined hooks
This issue was closed.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
1 participant