ruby_llm-docker 0.2.5 → 0.3.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -2,113 +2,79 @@
2
2
 
3
3
  module RubyLLM
4
4
  module Docker
5
- # RubyLLM tool for recreating Docker containers with the same configuration.
5
+ # MCP tool for recreating Docker containers.
6
6
  #
7
- # This tool provides a convenient way to recreate containers while preserving
8
- # their original configuration. It stops and removes the existing container,
9
- # then creates a new one with identical settings. This is useful for applying
10
- # image updates, clearing container state, or resolving container issues.
7
+ # This tool provides a complete container recreation process that stops
8
+ # the existing container, removes it, and creates a new container with
9
+ # the same configuration. This is useful for applying image updates,
10
+ # clearing container state, or resolving container corruption issues.
11
11
  #
12
12
  # == Features
13
13
  #
14
- # - Preserves complete container configuration
15
- # - Maintains original name and settings
16
- # - Handles running containers gracefully
17
- # - Restores running state after recreation
18
- # - Configurable stop timeout
19
- # - Comprehensive error handling
14
+ # - Complete container recreation with preserved configuration
15
+ # - Automatic stop, remove, and recreate sequence
16
+ # - Preserves original container configuration and settings
17
+ # - Configurable stop timeout for graceful shutdown
18
+ # - Handles both running and stopped containers
19
+ # - Maintains container networking and volume configurations
20
20
  #
21
- # == Process Overview
22
- #
23
- # 1. Retrieve existing container configuration
24
- # 2. Stop container gracefully (if running)
25
- # 3. Remove the old container
26
- # 4. Create new container with identical config
27
- # 5. Start new container (if original was running)
21
+ # == Security Considerations
28
22
  #
29
- # == ⚠️ Data Loss Warning ⚠️
23
+ # Container recreation involves several security considerations:
24
+ # - **Service Downtime**: Temporary service interruption during recreation
25
+ # - **Data Loss**: Container file system changes are lost (volumes preserved)
26
+ # - **Resource Allocation**: New container may have different resource usage
27
+ # - **Network Reconfiguration**: IP addresses may change
28
+ # - **State Reset**: Application state within container is lost
30
29
  #
31
- # **DESTRUCTIVE OPERATION - DATA LOSS POSSIBLE**
30
+ # Plan recreations carefully and coordinate with dependent services.
32
31
  #
33
- # This operation can cause permanent data loss:
34
- # - Container filesystem changes are lost
35
- # - Temporary data and logs are deleted
36
- # - Container state is reset completely
37
- # - Network connections are interrupted
38
- # - Anonymous volumes may be recreated empty
32
+ # == Parameters
39
33
  #
40
- # == Security Considerations
34
+ # - **id**: Container ID or name to recreate (required)
35
+ # - **timeout**: Seconds to wait before killing container when stopping (optional, default: 10)
41
36
  #
42
- # - Original configuration is preserved exactly
43
- # - Sensitive environment variables are maintained
44
- # - Port mappings and volume mounts are restored
45
- # - Network access patterns remain the same
37
+ # == Process Flow
46
38
  #
47
- # Ensure original configuration is still secure:
48
- # - Review exposed ports and volumes
49
- # - Validate environment variables
50
- # - Check image security updates
51
- # - Verify network policies
39
+ # 1. Inspect existing container to capture configuration
40
+ # 2. Stop the running container (if running)
41
+ # 3. Remove the stopped container
42
+ # 4. Create new container with captured configuration
43
+ # 5. Return new container information
52
44
  #
53
45
  # == Example Usage
54
46
  #
55
47
  # # Recreate with default timeout
56
- # RecreateContainer.call(
48
+ # response = RecreateContainer.call(
57
49
  # server_context: context,
58
50
  # id: "web-server"
59
51
  # )
60
52
  #
61
- # # Recreate with longer stop timeout
62
- # RecreateContainer.call(
53
+ # # Recreate with extended timeout
54
+ # response = RecreateContainer.call(
63
55
  # server_context: context,
64
56
  # id: "database",
65
57
  # timeout: 30
66
58
  # )
67
59
  #
68
- # @see CreateContainer
69
- # @see StopContainer
70
- # @see RemoveContainer
71
- # @see Docker::Container.create
60
+ # @see ::Docker::Container#stop
61
+ # @see ::Docker::Container#remove
62
+ # @see ::Docker::Container.create
72
63
  # @since 0.1.0
73
- class RecreateContainer < RubyLLM::Tool
64
+ RECREATE_CONTAINER_DEFINITION = ToolForge.define(:recreate_container) do
74
65
  description 'Recreate a Docker container (stops, removes, and recreates with same configuration)'
75
66
 
76
- param :id, type: :string, desc: 'Container ID or name to recreate'
77
- param :timeout, type: :integer,
78
- desc: 'Seconds to wait before killing the container when stopping (default: 10)',
79
- required: false
67
+ param :id,
68
+ type: :string,
69
+ description: 'Container ID or name to recreate'
80
70
 
81
- # Recreate a Docker container with identical configuration.
82
- #
83
- # This method performs a complete container recreation cycle while
84
- # preserving all configuration settings. The new container will have
85
- # the same name, environment, port mappings, volumes, and other
86
- # settings as the original.
87
- #
88
- # @param id [String] container ID (full or short) or container name
89
- # @param server_context [Object] RubyLLM context (unused but required)
90
- # @param timeout [Integer] seconds to wait before force killing during stop (default: 10)
91
- #
92
- # @return [RubyLLM::Tool::Response] recreation results with new container ID
93
- #
94
- # @raise [Docker::Error::NotFoundError] if container doesn't exist
95
- # @raise [StandardError] for recreation failures
96
- #
97
- # @example Recreate application container
98
- # response = RecreateContainer.call(
99
- # server_context: context,
100
- # id: "my-app"
101
- # )
102
- #
103
- # @example Recreate database with extended timeout
104
- # response = tool.execute(
105
- # id: "postgres-main",
106
- # timeout: 60 # Allow time for DB shutdown
107
- # )
108
- #
109
- # @see Docker::Container.get
110
- # @see Docker::Container.create
111
- def execute(id:, timeout: 10)
71
+ param :timeout,
72
+ type: :integer,
73
+ description: 'Seconds to wait before killing the container when stopping (default: 10)',
74
+ required: false,
75
+ default: 10
76
+
77
+ execute do |id:, timeout: 10|
112
78
  # Get the existing container
113
79
  old_container = ::Docker::Container.get(id)
114
80
  config = old_container.json
@@ -147,5 +113,7 @@ module RubyLLM
147
113
  "Error recreating container: #{e.message}"
148
114
  end
149
115
  end
116
+
117
+ RecreateContainer = RECREATE_CONTAINER_DEFINITION.to_ruby_llm_tool
150
118
  end
151
119
  end
@@ -2,110 +2,80 @@
2
2
 
3
3
  module RubyLLM
4
4
  module Docker
5
- # RubyLLM tool for removing Docker containers.
5
+ # MCP tool for removing Docker containers.
6
6
  #
7
- # This tool provides the ability to permanently delete Docker containers
8
- # from the system. It supports both graceful removal of stopped containers
9
- # and forced removal of running containers. Optionally, it can also remove
10
- # associated anonymous volumes.
7
+ # This tool permanently removes a Docker container from the system,
8
+ # including its file system, configuration, and metadata. This is a
9
+ # destructive operation that cannot be undone. The container must
10
+ # be stopped before removal unless force is specified.
11
11
  #
12
12
  # == Features
13
13
  #
14
- # - Remove stopped containers safely
15
- # - Force removal of running containers
14
+ # - Permanent container removal from system
15
+ # - Supports forced removal of running containers
16
16
  # - Optional removal of associated volumes
17
- # - Comprehensive error handling
18
- # - Works with containers by ID or name
17
+ # - Handles container identification by ID or name
18
+ # - Provides comprehensive error handling
19
+ # - Frees all associated system resources
19
20
  #
20
- # == Data Loss Warning
21
- #
22
- # ⚠️ **DESTRUCTIVE OPERATION** ⚠️
21
+ # == Security Considerations
23
22
  #
24
- # This operation permanently deletes containers and potentially data:
25
- # - Container filesystem changes are lost forever
26
- # - Running processes are killed immediately (with force)
27
- # - Associated volumes may be removed if specified
28
- # - Container logs and metadata are deleted
29
- # - Operation cannot be undone
23
+ # Container removal is a destructive operation with implications:
24
+ # - **Data Loss**: Permanently destroys container file system
25
+ # - **Configuration Loss**: Removes container settings and metadata
26
+ # - **Service Disruption**: Eliminates containerized services
27
+ # - **Resource Recovery**: Frees storage, memory, and system resources
28
+ # - **Audit Trail**: May remove forensic evidence if needed
30
29
  #
31
- # == Security Considerations
30
+ # Implement proper backup and approval workflows for production systems.
32
31
  #
33
- # - Forced removal can cause data corruption
34
- # - Volume removal may affect other containers
35
- # - Running container removal terminates services abruptly
36
- # - Sensitive data in container memory is not securely wiped
32
+ # == Parameters
37
33
  #
38
- # Best practices:
39
- # - Stop containers gracefully before removal
40
- # - Backup important data before removing
41
- # - Verify volume dependencies before volume removal
42
- # - Use force removal only when necessary
34
+ # - **id**: Container ID or name (required)
35
+ # - Accepts full container IDs
36
+ # - Accepts short container IDs (first 12+ characters)
37
+ # - Accepts custom container names
38
+ # - **force**: Force removal of running container (optional, default: false)
39
+ # - **volumes**: Remove associated volumes (optional, default: false)
43
40
  #
44
41
  # == Example Usage
45
42
  #
46
43
  # # Remove stopped container
47
- # RemoveContainer.call(
44
+ # response = RemoveContainer.call(
48
45
  # server_context: context,
49
- # id: "old-container"
46
+ # id: "old-web-server"
50
47
  # )
51
48
  #
52
49
  # # Force remove running container with volumes
53
- # RemoveContainer.call(
50
+ # response = RemoveContainer.call(
54
51
  # server_context: context,
55
52
  # id: "problematic-container",
56
53
  # force: true,
57
54
  # volumes: true
58
55
  # )
59
56
  #
60
- # @see StopContainer
61
- # @see CreateContainer
62
- # @see Docker::Container#delete
57
+ # @see ::Docker::Container#remove
63
58
  # @since 0.1.0
64
- class RemoveContainer < RubyLLM::Tool
59
+ REMOVE_CONTAINER_DEFINITION = ToolForge.define(:remove_container) do
65
60
  description 'Remove a Docker container'
66
61
 
67
- param :id, desc: 'Container ID or name'
68
- param :force, type: :boolean, desc: 'Force removal of running container (default: false)', required: false
69
- param :volumes, type: :boolean, desc: 'Remove associated volumes (default: false)', required: false
62
+ param :id,
63
+ type: :string,
64
+ description: 'Container ID or name'
70
65
 
71
- # Remove a Docker container permanently.
72
- #
73
- # This method deletes a container from the Docker system. By default,
74
- # it only removes stopped containers. The force option allows removal
75
- # of running containers, and the volumes option removes associated
76
- # anonymous volumes.
77
- #
78
- # @param id [String] container ID (full or short) or container name
79
- # @param server_context [Object] RubyLLM context (unused but required)
80
- # @param force [Boolean] whether to force remove running containers (default: false)
81
- # @param volumes [Boolean] whether to remove associated volumes (default: false)
82
- #
83
- # @return [RubyLLM::Tool::Response] removal operation results
84
- #
85
- # @raise [Docker::Error::NotFoundError] if container doesn't exist
86
- # @raise [StandardError] for other removal failures
87
- #
88
- # @example Remove stopped container
89
- # response = RemoveContainer.call(
90
- # server_context: context,
91
- # id: "finished-job"
92
- # )
93
- #
94
- # @example Force remove running container
95
- # response = RemoveContainer.call(
96
- # server_context: context,
97
- # id: "stuck-container",
98
- # force: true
99
- # )
100
- #
101
- # @example Remove container and its volumes
102
- # response = tool.execute(
103
- # id: "temp-container",
104
- # volumes: true
105
- # )
106
- #
107
- # @see Docker::Container#delete
108
- def execute(id:, force: false, volumes: false)
66
+ param :force,
67
+ type: :boolean,
68
+ description: 'Force removal of running container (default: false)',
69
+ required: false,
70
+ default: false
71
+
72
+ param :volumes,
73
+ type: :boolean,
74
+ description: 'Remove associated volumes (default: false)',
75
+ required: false,
76
+ default: false
77
+
78
+ execute do |id:, force: false, volumes: false|
109
79
  container = ::Docker::Container.get(id)
110
80
  container.delete(force: force, v: volumes)
111
81
 
@@ -116,5 +86,7 @@ module RubyLLM
116
86
  "Error removing container: #{e.message}"
117
87
  end
118
88
  end
89
+
90
+ RemoveContainer = REMOVE_CONTAINER_DEFINITION.to_ruby_llm_tool
119
91
  end
120
92
  end
@@ -2,132 +2,88 @@
2
2
 
3
3
  module RubyLLM
4
4
  module Docker
5
- # RubyLLM tool for removing Docker images.
5
+ # MCP tool for removing Docker images.
6
6
  #
7
- # This tool provides the ability to permanently delete Docker images from
8
- # the local system to free up disk space and remove unused images. It
9
- # supports both regular and forced removal with options for parent image
10
- # handling.
7
+ # This tool provides the ability to delete Docker images from the
8
+ # local Docker daemon. It supports various removal options including
9
+ # forced removal and parent image cleanup management.
11
10
  #
12
11
  # == Features
13
12
  #
14
- # - Remove images by ID, name, or name:tag
13
+ # - Remove images by ID, name, or tag
15
14
  # - Force removal of images in use
16
- # - Control parent image cleanup
15
+ # - Control untagged parent image cleanup
17
16
  # - Comprehensive error handling
17
+ # - Validation of image existence
18
18
  # - Safe removal with dependency checking
19
19
  #
20
- # == ⚠️ Data Loss Warning ⚠️
21
- #
22
- # **DESTRUCTIVE OPERATION - PERMANENT DATA LOSS**
23
- #
24
- # This operation permanently deletes images and associated data:
25
- # - Image layers are deleted from disk
26
- # - All tags pointing to the image are removed
27
- # - Operation cannot be undone
28
- # - Dependent containers may become unusable
29
- # - Custom modifications to images are lost
30
- #
31
- # == Dependency Management
32
- #
33
- # Docker images have complex dependency relationships:
34
- # - **Child Images**: Images built FROM this image
35
- # - **Parent Images**: Base images this image depends on
36
- # - **Running Containers**: Containers using this image
37
- # - **Stopped Containers**: Containers that could be restarted
38
- #
39
20
  # == Security Considerations
40
21
  #
41
- # Image removal affects system security posture:
42
- # - Removes potentially vulnerable software
43
- # - May break running applications
44
- # - Could remove security patches
45
- # - Affects rollback capabilities
46
- #
47
- # Best practices:
48
- # - Verify no critical containers depend on the image
22
+ # Image removal involves important considerations:
23
+ # - **Data Loss**: Removed images cannot be recovered locally
24
+ # - **Service Disruption**: Removing images used by running containers
25
+ # - **Storage Cleanup**: Improper cleanup can leave orphaned layers
26
+ # - **Registry Impact**: Local removal doesn't affect registry copies
27
+ # - **Dependency Conflicts**: Force removal can break container dependencies
28
+ #
29
+ # **Security Recommendations**:
30
+ # - Verify image is not in use before removal
31
+ # - Use force option only when necessary
32
+ # - Consider impact on running containers
49
33
  # - Backup important images before removal
50
- # - Use force removal judiciously
51
- # - Monitor disk space after removal
52
- # - Maintain image inventory documentation
34
+ # - Monitor disk space after removal operations
35
+ # - Implement image lifecycle policies
53
36
  #
54
- # == Removal Options
37
+ # == Parameters
55
38
  #
56
- # - **Normal Removal**: Only removes if no containers use the image
57
- # - **Force Removal**: Removes even if containers depend on it
58
- # - **Prune Parents**: Automatically removes unused parent images
59
- # - **No Prune**: Keeps parent images even if unused
39
+ # - **id**: Image ID, name, or name:tag (required)
40
+ # - **force**: Force removal of the image (optional, default: false)
41
+ # - **noprune**: Do not delete untagged parents (optional, default: false)
60
42
  #
61
43
  # == Example Usage
62
44
  #
63
- # # Safe removal of unused image
64
- # RemoveImage.call(
45
+ # # Remove specific image
46
+ # response = RemoveImage.call(
65
47
  # server_context: context,
66
- # id: "old-app:v1.0"
48
+ # id: "myapp:old-version"
67
49
  # )
68
50
  #
69
- # # Force removal of image in use
70
- # RemoveImage.call(
51
+ # # Force remove image in use
52
+ # response = RemoveImage.call(
71
53
  # server_context: context,
72
- # id: "broken-image:latest",
54
+ # id: "abc123def456",
73
55
  # force: true
74
56
  # )
75
57
  #
76
- # # Remove image but keep parent layers
77
- # RemoveImage.call(
58
+ # # Remove without cleaning parent images
59
+ # response = RemoveImage.call(
78
60
  # server_context: context,
79
- # id: "temp-build:abc123",
61
+ # id: "test-image:latest",
80
62
  # noprune: true
81
63
  # )
82
64
  #
83
- # @see ListImages
84
- # @see BuildImage
85
- # @see Docker::Image#remove
65
+ # @see ::Docker::Image#remove
86
66
  # @since 0.1.0
87
- class RemoveImage < RubyLLM::Tool
67
+ REMOVE_IMAGE_DEFINITION = ToolForge.define(:remove_image) do
88
68
  description 'Remove a Docker image'
89
69
 
90
- param :id, type: :string, desc: 'Image ID, name, or name:tag'
91
- param :force, type: :boolean, desc: 'Force removal of the image (default: false)', required: false
92
- param :noprune, type: :boolean, desc: 'Do not delete untagged parents (default: false)', required: false
70
+ param :id,
71
+ type: :string,
72
+ description: 'Image ID, name, or name:tag'
73
+
74
+ param :force,
75
+ type: :boolean,
76
+ description: 'Force removal of the image (default: false)',
77
+ required: false,
78
+ default: false
93
79
 
94
- # Remove a Docker image from the local system.
95
- #
96
- # This method permanently deletes the specified image from local storage.
97
- # By default, it performs safety checks to prevent removal of images with
98
- # dependent containers. Force removal bypasses these checks.
99
- #
100
- # @param id [String] image ID, name, or name:tag to remove
101
- # @param server_context [Object] RubyLLM context (unused but required)
102
- # @param force [Boolean] whether to force removal despite dependencies (default: false)
103
- # @param noprune [Boolean] whether to preserve parent images (default: false)
104
- #
105
- # @return [RubyLLM::Tool::Response] removal operation results
106
- #
107
- # @raise [Docker::Error::NotFoundError] if image doesn't exist
108
- # @raise [StandardError] for removal failures or dependency conflicts
109
- #
110
- # @example Remove unused image
111
- # response = RemoveImage.call(
112
- # server_context: context,
113
- # id: "old-version:1.0"
114
- # )
115
- #
116
- # @example Force remove problematic image
117
- # response = RemoveImage.call(
118
- # server_context: context,
119
- # id: "corrupted-image",
120
- # force: true
121
- # )
122
- #
123
- # @example Remove while preserving layers
124
- # response = tool.execute(
125
- # id: "temp-image:build-123",
126
- # noprune: true
127
- # )
128
- #
129
- # @see Docker::Image#remove
130
- def execute(id:, force: false, noprune: false)
80
+ param :noprune,
81
+ type: :boolean,
82
+ description: 'Do not delete untagged parents (default: false)',
83
+ required: false,
84
+ default: false
85
+
86
+ execute do |id:, force: false, noprune: false|
131
87
  image = ::Docker::Image.get(id)
132
88
  image.remove(force: force, noprune: noprune)
133
89
 
@@ -138,5 +94,7 @@ module RubyLLM
138
94
  "Error removing image: #{e.message}"
139
95
  end
140
96
  end
97
+
98
+ RemoveImage = REMOVE_IMAGE_DEFINITION.to_ruby_llm_tool
141
99
  end
142
100
  end