-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add Docker container removal functionality
The commit adds functionality to remove Docker containers. It specifically introduces a new action "docker-remove" in the action map, which results in removal of Docker container with the specified container ID. Moreover, a 'RemoveContainer' function has been added to the DockerContainer.go file, allowing the removal of Docker containers from within the application.
- Loading branch information
1 parent
efe9f23
commit e08396c
Showing
3 changed files
with
93 additions
and
9 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
package docker | ||
|
||
import ( | ||
"context" | ||
"github.com/PiotrFerenc/mash2/cmd/worker/actions" | ||
"github.com/PiotrFerenc/mash2/internal/Container" | ||
"github.com/PiotrFerenc/mash2/internal/types" | ||
) | ||
|
||
type dockerRemoveContainer struct { | ||
containerId actions.Property | ||
} | ||
|
||
func CreateDockerRemove() actions.Action { | ||
return &dockerRemoveContainer{ | ||
containerId: actions.Property{ | ||
Name: "id", | ||
Type: actions.Text, | ||
Description: "The unique identifier for the Docker container to be removed", | ||
DisplayName: "Container ID", | ||
Validation: "required", | ||
}, | ||
} | ||
} | ||
|
||
func (d *dockerRemoveContainer) GetCategoryName() string { | ||
return "docker" | ||
} | ||
|
||
func (d *dockerRemoveContainer) Inputs() []actions.Property { | ||
return []actions.Property{ | ||
d.containerId, | ||
} | ||
} | ||
|
||
func (d *dockerRemoveContainer) Outputs() []actions.Property { | ||
return []actions.Property{} | ||
} | ||
|
||
func (d *dockerRemoveContainer) Execute(process types.Process) (types.Process, error) { | ||
ctx := context.Background() | ||
|
||
containerId, err := d.containerId.GetStringFrom(&process) | ||
if err != nil { | ||
return process, err | ||
} | ||
|
||
err = Container.RemoveContainer(containerId, ctx) | ||
if err != nil { | ||
return process, err | ||
} | ||
|
||
return process, nil | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters