octopush/internal/actions/action.go

52 lines
1.0 KiB
Go
Raw Normal View History

2022-09-13 22:54:49 +02:00
package actions
import (
"context"
"errors"
2022-09-13 22:54:49 +02:00
"git.front.kjuulh.io/kjuulh/kraken/internal/actions/builders"
2022-09-13 22:54:49 +02:00
"git.front.kjuulh.io/kjuulh/kraken/internal/schema"
"git.front.kjuulh.io/kjuulh/kraken/internal/services/storage"
"go.uber.org/zap"
2022-09-13 22:54:49 +02:00
)
type Action struct {
Schema *schema.KrakenSchema
SchemaPath string
2022-09-13 22:54:49 +02:00
}
func (a *Action) Execute(ctx context.Context, area *storage.Area) error {
for _, action := range a.Schema.Actions {
switch action.Type {
case "go":
exe, err := builders.NewGo(zap.L()).Build(ctx, a.SchemaPath, action.Entry)
if err != nil {
return err
}
err = exe(ctx, area.Path)
if err != nil {
return err
}
zap.L().Debug("Execution done")
2022-09-18 00:21:23 +02:00
case "docker-build":
2022-09-18 00:53:41 +02:00
zap.L().Debug("Building docker-build")
2022-09-18 00:21:23 +02:00
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")
}
}
2022-09-13 22:54:49 +02:00
return nil
}