with docker action
This commit is contained in:
@@ -30,6 +30,17 @@ func (a *Action) Execute(ctx context.Context, area *storage.Area) error {
|
||||
|
||||
zap.L().Debug("Execution done")
|
||||
|
||||
case "docker-build":
|
||||
runCmd, err := builders.NewDockerBuild(zap.L()).Build(ctx, a.SchemaPath, action.Entry)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
err = runCmd(ctx, area.Path)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
return nil
|
||||
|
||||
default:
|
||||
return errors.New("could not determine action type")
|
||||
}
|
||||
|
44
internal/actions/builders/docker.go
Normal file
44
internal/actions/builders/docker.go
Normal file
@@ -0,0 +1,44 @@
|
||||
package builders
|
||||
|
||||
import (
|
||||
"context"
|
||||
"errors"
|
||||
"fmt"
|
||||
"os"
|
||||
"os/exec"
|
||||
|
||||
"go.uber.org/zap"
|
||||
)
|
||||
|
||||
type DockerBuild struct {
|
||||
logger *zap.Logger
|
||||
}
|
||||
|
||||
func NewDockerBuild(logger *zap.Logger) *Go {
|
||||
return &Go{logger: logger}
|
||||
}
|
||||
|
||||
type DockerRunCommand func(ctx context.Context, victimPath string) error
|
||||
|
||||
func (g *DockerBuild) Build(ctx context.Context, modulePath, entryPath string) (DockerRunCommand, error) {
|
||||
g.logger.Debug("Building docker image", zap.String("actiondir", modulePath), zap.String("entry", entryPath))
|
||||
|
||||
if _, err := os.Stat(fmt.Sprintf("%s/%s", modulePath, entryPath)); os.IsNotExist(err) {
|
||||
return nil, errors.New("could not find entry")
|
||||
}
|
||||
|
||||
g.logger.Debug("Go binary built!")
|
||||
|
||||
return func(ctx context.Context, victimPath string) error {
|
||||
g.logger.Debug("Executing script", zap.String("victim", victimPath))
|
||||
|
||||
cmd := exec.CommandContext(
|
||||
ctx,
|
||||
"/bin/bash",
|
||||
"-c",
|
||||
fmt.Sprintf("(cd %s; docker build)", modulePath),
|
||||
)
|
||||
|
||||
return cmd.Run()
|
||||
}, nil
|
||||
}
|
Reference in New Issue
Block a user