Skip to content

Commit 18f40ec

Browse files
authored
removes autoremove on run (#128)
Signed-off-by: ChrisJBurns <29541485+ChrisJBurns@users.noreply.github.com>
1 parent 966e66c commit 18f40ec

File tree

10 files changed

+1
-50
lines changed

10 files changed

+1
-50
lines changed

cmd/thv/run.go

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -40,11 +40,9 @@ var (
4040
runVolumes []string
4141
runSecrets []string
4242
runAuthzConfig string
43-
autoRemove bool
4443
)
4544

4645
func init() {
47-
runCmd.Flags().BoolVar(&autoRemove, "rm", false, "Auto-remove the server container when the server has been stopped")
4846
runCmd.Flags().StringVar(&runTransport, "transport", "stdio", "Transport mode (sse or stdio)")
4947
runCmd.Flags().StringVar(&runName, "name", "", "Name of the MCP server (auto-generated from image if not provided)")
5048
runCmd.Flags().IntVar(&runPort, "port", 0, "Port for the HTTP proxy to listen on (host port)")
@@ -122,7 +120,6 @@ func runCmdFunc(cmd *cobra.Command, args []string) error {
122120
cmdArgs,
123121
runName,
124122
debugMode,
125-
autoRemove,
126123
runVolumes,
127124
runSecrets,
128125
runAuthzConfig,

cmd/thv/run_common.go

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -71,10 +71,6 @@ func detachProcess(cmd *cobra.Command, options *runner.RunConfig) error {
7171
detachedArgs = append(detachedArgs, "--debug")
7272
}
7373

74-
if options.AutoRemove {
75-
detachedArgs = append(detachedArgs, "--rm")
76-
}
77-
7874
// Use Name if available
7975
if options.Name != "" {
8076
detachedArgs = append(detachedArgs, "--name", options.Name)

pkg/container/docker/client.go

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -238,7 +238,6 @@ func (c *Client) CreateContainer(
238238

239239
// Create host configuration
240240
hostConfig := &container.HostConfig{
241-
AutoRemove: false,
242241
Mounts: convertMounts(permissionConfig.Mounts),
243242
NetworkMode: container.NetworkMode(permissionConfig.NetworkMode),
244243
CapAdd: permissionConfig.CapAdd,

pkg/runner/config.go

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -62,9 +62,6 @@ type RunConfig struct {
6262
// Debug indicates whether debug mode is enabled
6363
Debug bool `json:"debug,omitempty" yaml:"debug,omitempty"`
6464

65-
// AutoRemove indicates whether the container should be removed when the server has been stopped
66-
AutoRemove bool `json:"auto_remove,omitempty" yaml:"auto_remove,omitempty"`
67-
6865
// Volumes are the directory mounts to pass to the container
6966
// Format: "host-path:container-path[:ro]"
7067
Volumes []string `json:"volumes,omitempty" yaml:"volumes,omitempty"`
@@ -120,7 +117,6 @@ func NewRunConfigFromFlags(
120117
cmdArgs []string,
121118
name string,
122119
debug bool,
123-
autoRemove bool,
124120
volumes []string,
125121
secretsList []string,
126122
authzConfigPath string,
@@ -136,7 +132,6 @@ func NewRunConfigFromFlags(
136132
CmdArgs: cmdArgs,
137133
Name: name,
138134
Debug: debug,
139-
AutoRemove: autoRemove,
140135
Volumes: volumes,
141136
Secrets: secretsList,
142137
AuthzConfigPath: authzConfigPath,

pkg/runner/config_test.go

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -801,7 +801,6 @@ func TestNewRunConfigFromFlags(t *testing.T) {
801801
cmdArgs := []string{"arg1", "arg2"}
802802
name := "test-server"
803803
debug := true
804-
autoRemove := true
805804
volumes := []string{"/host:/container"}
806805
secretsList := []string{"secret1,target=ENV_VAR1"}
807806
authzConfigPath := "/path/to/authz.json"
@@ -817,7 +816,6 @@ func TestNewRunConfigFromFlags(t *testing.T) {
817816
cmdArgs,
818817
name,
819818
debug,
820-
autoRemove,
821819
volumes,
822820
secretsList,
823821
authzConfigPath,

pkg/runner/runner.go

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,6 @@ func (r *Runner) Run(ctx context.Context) error {
4343
TargetHost: r.Config.TargetHost,
4444
Runtime: r.Config.Runtime,
4545
Debug: r.Config.Debug,
46-
AutoRemove: r.Config.AutoRemove,
4746
}
4847

4948
// Add OIDC middleware if OIDC validation is enabled

pkg/transport/factory.go

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,15 +19,14 @@ func NewFactory() *Factory {
1919
func (*Factory) Create(config types.Config) (types.Transport, error) {
2020
switch config.Type {
2121
case types.TransportTypeStdio:
22-
return NewStdioTransport(config.Port, config.Runtime, config.Debug, config.AutoRemove, config.Middlewares...), nil
22+
return NewStdioTransport(config.Port, config.Runtime, config.Debug, config.Middlewares...), nil
2323
case types.TransportTypeSSE:
2424
return NewSSETransport(
2525
config.Host,
2626
config.Port,
2727
config.TargetPort,
2828
config.Runtime,
2929
config.Debug,
30-
config.AutoRemove,
3130
config.TargetHost,
3231
config.Middlewares...,
3332
), nil

pkg/transport/sse.go

Lines changed: 0 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,6 @@ type SSETransport struct {
3030
containerName string
3131
runtime rt.Runtime
3232
debug bool
33-
autoRemove bool
3433
middlewares []types.Middleware
3534

3635
// Mutex for protecting shared state
@@ -54,7 +53,6 @@ func NewSSETransport(
5453
targetPort int,
5554
runtime rt.Runtime,
5655
debug bool,
57-
autoRemove bool,
5856
targetHost string,
5957
middlewares ...types.Middleware,
6058
) *SSETransport {
@@ -75,7 +73,6 @@ func NewSSETransport(
7573
targetHost: targetHost,
7674
runtime: runtime,
7775
debug: debug,
78-
autoRemove: autoRemove,
7976
shutdownCh: make(chan struct{}),
8077
}
8178
}
@@ -249,17 +246,6 @@ func (t *SSETransport) Stop(ctx context.Context) error {
249246
if err := t.runtime.StopContainer(ctx, t.containerID); err != nil {
250247
return fmt.Errorf("failed to stop container: %w", err)
251248
}
252-
253-
// Remove the container if auto-remove is enabled
254-
if t.autoRemove {
255-
logger.Log.Info(fmt.Sprintf("Removing container %s...", t.containerName))
256-
if err := t.runtime.RemoveContainer(ctx, t.containerID); err != nil {
257-
logger.Log.Warn(fmt.Sprintf("Warning: Failed to remove container: %v", err))
258-
}
259-
logger.Log.Info(fmt.Sprintf("Container %s removed", t.containerName))
260-
} else {
261-
logger.Log.Info(fmt.Sprintf("Auto-remove disabled, container %s not removed", t.containerName))
262-
}
263249
}
264250

265251
return nil

pkg/transport/stdio.go

Lines changed: 0 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,6 @@ type StdioTransport struct {
2929
containerName string
3030
runtime rt.Runtime
3131
debug bool
32-
autoRemove bool
3332
middlewares []types.Middleware
3433

3534
// Mutex for protecting shared state
@@ -55,14 +54,12 @@ func NewStdioTransport(
5554
port int,
5655
runtime rt.Runtime,
5756
debug bool,
58-
autoRemove bool,
5957
middlewares ...types.Middleware,
6058
) *StdioTransport {
6159
return &StdioTransport{
6260
port: port,
6361
runtime: runtime,
6462
debug: debug,
65-
autoRemove: autoRemove,
6663
middlewares: middlewares,
6764
shutdownCh: make(chan struct{}),
6865
}
@@ -238,18 +235,6 @@ func (t *StdioTransport) Stop(ctx context.Context) error {
238235
logger.Log.Warn(fmt.Sprintf("Warning: Failed to stop container: %v", err))
239236
}
240237
}
241-
242-
// Remove the container if auto-remove is enabled
243-
if t.autoRemove {
244-
logger.Log.Info(fmt.Sprintf("Removing container %s...", t.containerName))
245-
if err := t.runtime.RemoveContainer(ctx, t.containerID); err != nil {
246-
logger.Log.Error(fmt.Sprintf("Warning: Failed to remove container: %v", err))
247-
} else {
248-
logger.Log.Info(fmt.Sprintf("Container %s removed", t.containerName))
249-
}
250-
} else {
251-
logger.Log.Info(fmt.Sprintf("Auto-remove disabled, container %s not removed", t.containerName))
252-
}
253238
}
254239

255240
return nil

pkg/transport/types/transport.go

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -123,9 +123,6 @@ type Config struct {
123123
// If debug mode is enabled, containers will not be removed when stopped.
124124
Debug bool
125125

126-
// AutoRemove indicates whether the container should be removed when the server has been stopped.
127-
AutoRemove bool
128-
129126
// Middlewares is a list of middleware functions to apply to the transport.
130127
// These are applied in order, with the first middleware being the outermost wrapper.
131128
Middlewares []Middleware

0 commit comments

Comments
 (0)