2022-09-13 22:54:49 +02:00
|
|
|
package actions
|
|
|
|
|
|
|
|
import (
|
|
|
|
"context"
|
2022-09-14 23:40:58 +02:00
|
|
|
"errors"
|
2022-09-13 22:54:49 +02:00
|
|
|
|
2022-09-14 23:40:58 +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"
|
2022-09-14 23:40:58 +02:00
|
|
|
"go.uber.org/zap"
|
2022-09-13 22:54:49 +02:00
|
|
|
)
|
|
|
|
|
|
|
|
type Action struct {
|
2022-09-14 23:40:58 +02:00
|
|
|
Schema *schema.KrakenSchema
|
|
|
|
SchemaPath string
|
2022-09-13 22:54:49 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
func (a *Action) Execute(ctx context.Context, area *storage.Area) error {
|
2022-09-14 23:40:58 +02:00
|
|
|
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
|
|
|
|
|
2022-09-14 23:40:58 +02:00
|
|
|
default:
|
|
|
|
return errors.New("could not determine action type")
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-09-13 22:54:49 +02:00
|
|
|
return nil
|
|
|
|
}
|