-
-
Notifications
You must be signed in to change notification settings - Fork 585
feat: add more functional options for customising containers #3156
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
Changes from all commits
a2e23fc
8f2ce6a
333be5a
d0f48db
bd847c6
46abd57
96b442c
a07cee6
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -106,14 +106,33 @@ func WithHostPortAccess(ports ...int) CustomizeRequestOption { | |
| } | ||
| } | ||
|
|
||
| // WithName will set the name of the container. | ||
| func WithName(containerName string) CustomizeRequestOption { | ||
| return func(req *GenericContainerRequest) error { | ||
| if containerName == "" { | ||
| return errors.New("container name must be provided") | ||
| } | ||
| req.Name = containerName | ||
| return nil | ||
| } | ||
| } | ||
|
|
||
| // WithNoStart will prevent the container from being started after creation. | ||
| func WithNoStart() CustomizeRequestOption { | ||
| return func(req *GenericContainerRequest) error { | ||
| req.Started = false | ||
| return nil | ||
| } | ||
| } | ||
mdelapenya marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
|
||
| // WithReuseByName will mark a container to be reused if it exists or create a new one if it doesn't. | ||
| // A container name must be provided to identify the container to be reused. | ||
| func WithReuseByName(containerName string) CustomizeRequestOption { | ||
| return func(req *GenericContainerRequest) error { | ||
| if containerName == "" { | ||
| return errors.New("container name must be provided for reuse") | ||
| if err := WithName(containerName)(req); err != nil { | ||
| return err | ||
| } | ||
| req.Name = containerName | ||
|
|
||
| req.Reuse = true | ||
| return nil | ||
| } | ||
|
|
@@ -255,6 +274,17 @@ func WithLogConsumers(consumer ...LogConsumer) CustomizeRequestOption { | |
| } | ||
| } | ||
|
|
||
| // WithLogConsumerConfig sets the log consumer config for a container. | ||
| // Beware that this option completely replaces the existing log consumer config, | ||
| // including the log consumers and the log production options, | ||
| // so it should be used with care. | ||
| func WithLogConsumerConfig(config *LogConsumerConfig) CustomizeRequestOption { | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. question: didn't we deprecate logconsumers? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Nope, we added a log package for the logging of the library, but the logconsumers, and the config, it's still in the core. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Something we should put on the list as the current way this is done is pretty limiting. |
||
| return func(req *GenericContainerRequest) error { | ||
| req.LogConsumerCfg = config | ||
| return nil | ||
| } | ||
| } | ||
|
|
||
| // Executable represents an executable command to be sent to a container, including options, | ||
| // as part of the different lifecycle hooks. | ||
| type Executable interface { | ||
|
|
@@ -376,6 +406,22 @@ func WithImageMount(source string, subpath string, target ContainerMountTarget) | |
| } | ||
| } | ||
|
|
||
| // WithAlwaysPull will pull the image before starting the container | ||
| func WithAlwaysPull() CustomizeRequestOption { | ||
mdelapenya marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| return func(req *GenericContainerRequest) error { | ||
| req.AlwaysPullImage = true | ||
| return nil | ||
| } | ||
| } | ||
|
|
||
| // WithImagePlatform sets the platform for a container | ||
| func WithImagePlatform(platform string) CustomizeRequestOption { | ||
| return func(req *GenericContainerRequest) error { | ||
| req.ImagePlatform = platform | ||
| return nil | ||
| } | ||
| } | ||
|
|
||
| // WithEntrypoint completely replaces the entrypoint of a container | ||
| func WithEntrypoint(entrypoint ...string) CustomizeRequestOption { | ||
| return func(req *GenericContainerRequest) error { | ||
|
|
@@ -429,6 +475,22 @@ func WithLabels(labels map[string]string) CustomizeRequestOption { | |
| } | ||
| } | ||
|
|
||
| // WithLifecycleHooks completely replaces the lifecycle hooks for a container | ||
| func WithLifecycleHooks(hooks ...ContainerLifecycleHooks) CustomizeRequestOption { | ||
| return func(req *GenericContainerRequest) error { | ||
| req.LifecycleHooks = hooks | ||
| return nil | ||
| } | ||
| } | ||
|
|
||
| // WithAdditionalLifecycleHooks appends lifecycle hooks to the existing ones for a container | ||
| func WithAdditionalLifecycleHooks(hooks ...ContainerLifecycleHooks) CustomizeRequestOption { | ||
| return func(req *GenericContainerRequest) error { | ||
| req.LifecycleHooks = append(req.LifecycleHooks, hooks...) | ||
| return nil | ||
| } | ||
| } | ||
|
|
||
| // WithMounts appends the mounts to the mounts for a container | ||
| func WithMounts(mounts ...ContainerMount) CustomizeRequestOption { | ||
| return func(req *GenericContainerRequest) error { | ||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.