-
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 operations and related action
The DockerContainer.go file has been expanded to include two main operations: starting and building a Docker container. Corresponding documentation and error handling have also been provided. Furthermore, the docker-build.go file introduces the creation of an action for Docker image building, including input/output properties and execution method.
- Loading branch information
1 parent
934b96a
commit 4fc5fb4
Showing
2 changed files
with
145 additions
and
0 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,81 @@ | ||
package docker | ||
|
||
import ( | ||
"context" | ||
"github.com/PiotrFerenc/mash2/cmd/worker/actions" | ||
"github.com/PiotrFerenc/mash2/internal/Container" | ||
"github.com/PiotrFerenc/mash2/internal/types" | ||
) | ||
|
||
func CreateDockerBuild() actions.Action { | ||
return &dockerImage{ | ||
dockerfile: actions.Property{ | ||
Name: "dockerfile", | ||
Type: actions.Text, | ||
Description: "The dockerfile to use for building the image", | ||
DisplayName: "Dockerfile", | ||
Validation: "required", | ||
}, | ||
tags: actions.Property{ | ||
Name: "tags", | ||
Type: actions.Text, | ||
Description: "The tags to apply to the built image", | ||
DisplayName: "Tags", | ||
Validation: "", | ||
}, | ||
imageId: actions.Property{ | ||
Name: "id", | ||
Type: actions.Text, | ||
Description: "The unique identifier for the built Docker image", | ||
DisplayName: "Image ID", | ||
Validation: "", | ||
}, | ||
} | ||
} | ||
|
||
type dockerImage struct { | ||
dockerfile actions.Property | ||
tags actions.Property | ||
imageId actions.Property | ||
} | ||
|
||
func (d *dockerImage) GetCategoryName() string { | ||
return "docker" | ||
} | ||
|
||
func (d *dockerImage) Inputs() []actions.Property { | ||
return []actions.Property{ | ||
d.dockerfile, d.tags, | ||
} | ||
} | ||
|
||
func (d *dockerImage) Outputs() []actions.Property { | ||
return []actions.Property{ | ||
d.imageId, | ||
} | ||
} | ||
|
||
// Execute builds a Docker image using the provided Dockerfile content and tags. | ||
// | ||
// Parameters: | ||
// | ||
// process: The process object containing the Dockerfile content and tags. | ||
// | ||
// Returns: | ||
// | ||
// types.Process: The updated process object with the image ID set. | ||
// error: An error if the image build process fails. | ||
func (d *dockerImage) Execute(process types.Process) (types.Process, error) { | ||
ctx := context.Background() | ||
dockerfile, err := d.dockerfile.GetStringFrom(&process) | ||
if err != nil { | ||
return process, err | ||
} | ||
tags, err := d.tags.GetStringFrom(&process) | ||
if err != nil { | ||
return process, err | ||
} | ||
imageId, err := Container.BuildImage(dockerfile, tags, ctx) | ||
process.SetString(d.imageId.Name, imageId) | ||
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