feature/docker-action #11
8
_examples/actions/docker_action/Dockerfile
Normal file
8
_examples/actions/docker_action/Dockerfile
Normal file
@ -0,0 +1,8 @@
|
||||
FROM debian:bullseye-slim
|
||||
|
||||
# Kraken relies on this path being the specified path
|
||||
WORKDIR /src/work/
|
||||
|
||||
COPY . .
|
||||
|
||||
RUN echo "# README docker" >> README.md
|
11
_examples/actions/docker_action/go.mod
Normal file
11
_examples/actions/docker_action/go.mod
Normal file
@ -0,0 +1,11 @@
|
||||
module write_a_readme
|
||||
|
||||
go 1.19
|
||||
|
||||
require github.com/bitfield/script v0.20.2
|
||||
|
||||
require (
|
||||
bitbucket.org/creachadair/shell v0.0.7 // indirect
|
||||
github.com/itchyny/gojq v0.12.7 // indirect
|
||||
github.com/itchyny/timefmt-go v0.1.3 // indirect
|
||||
)
|
20
_examples/actions/docker_action/go.sum
Normal file
20
_examples/actions/docker_action/go.sum
Normal file
@ -0,0 +1,20 @@
|
||||
bitbucket.org/creachadair/shell v0.0.7 h1:Z96pB6DkSb7F3Y3BBnJeOZH2gazyMTWlvecSD4vDqfk=
|
||||
bitbucket.org/creachadair/shell v0.0.7/go.mod h1:oqtXSSvSYr4624lnnabXHaBsYW6RD80caLi2b3hJk0U=
|
||||
github.com/bitfield/script v0.20.2 h1:4DexsRtBILVMEn3EZwHbtJdDqdk43sXI8gM3F04JXgs=
|
||||
github.com/bitfield/script v0.20.2/go.mod h1:l3AZPVAtKQrL03bwh7nlNTUtgrgSWurpJSbtqspYrOA=
|
||||
github.com/google/go-cmp v0.5.4/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE=
|
||||
github.com/google/go-cmp v0.5.6/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE=
|
||||
github.com/google/go-cmp v0.5.7 h1:81/ik6ipDQS2aGcBfIN5dHDB36BwrStyeAQquSYCV4o=
|
||||
github.com/google/go-cmp v0.5.7/go.mod h1:n+brtR0CgQNWTVd5ZUFpTBC8YFBDLK/h/bpaJ8/DtOE=
|
||||
github.com/itchyny/gojq v0.12.7 h1:hYPTpeWfrJ1OT+2j6cvBScbhl0TkdwGM4bc66onUSOQ=
|
||||
github.com/itchyny/gojq v0.12.7/go.mod h1:ZdvNHVlzPgUf8pgjnuDTmGfHA/21KoutQUJ3An/xNuw=
|
||||
github.com/itchyny/timefmt-go v0.1.3 h1:7M3LGVDsqcd0VZH2U+x393obrzZisp7C0uEe921iRkU=
|
||||
github.com/itchyny/timefmt-go v0.1.3/go.mod h1:0osSSCQSASBJMsIZnhAaF1C2fCBTJZXrnj37mG8/c+A=
|
||||
github.com/mattn/go-isatty v0.0.14/go.mod h1:7GGIvUiUoEMVVmxf/4nioHXj79iQHKdU27kJ6hsGG94=
|
||||
github.com/mattn/go-runewidth v0.0.9/go.mod h1:H031xJmbD/WCDINGzjvQ9THkh0rPKHF+m2gUSrubnMI=
|
||||
golang.org/x/sys v0.0.0-20210630005230-0f9fa26af87c/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
|
||||
golang.org/x/sys v0.0.0-20220227234510-4e6760a101f9/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
|
||||
golang.org/x/xerrors v0.0.0-20191204190536-9bdfabe68543/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
|
||||
golang.org/x/xerrors v0.0.0-20200804184101-5ec99f83aff1/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
|
||||
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
|
||||
gopkg.in/yaml.v3 v3.0.0-20210107192922-496545a6307b/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
|
11
_examples/actions/docker_action/kraken.yml
Normal file
11
_examples/actions/docker_action/kraken.yml
Normal file
@ -0,0 +1,11 @@
|
||||
apiVersion: git.front.kjuulh.io/kjuulh/kraken/blob/main/schema/v1
|
||||
name: write-a-readme
|
||||
select:
|
||||
repositories:
|
||||
- git@git.front.kjuulh.io:kjuulh/kraken-test.git
|
||||
# providers:
|
||||
# - gitea: https://git.front.kjuulh.io
|
||||
# organisation: "cibus"
|
||||
actions:
|
||||
- type: docker-build
|
||||
entry: "Dockerfile"
|
@ -22,8 +22,8 @@ func CreateKrakenProcessCmd() *cobra.Command {
|
||||
Path string `json:"path"`
|
||||
}{
|
||||
Repository: "git@git.front.kjuulh.io:kjuulh/kraken.git",
|
||||
Branch: "feature/gitea-integration",
|
||||
Path: "_examples/actions/write_a_readme/",
|
||||
Branch: "feature/docker-action",
|
||||
Path: "_examples/actions/docker_action/",
|
||||
})
|
||||
if err != nil {
|
||||
panic(err)
|
||||
|
@ -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
|
||||
}
|
Loading…
Reference in New Issue
Block a user