Compare commits
16 Commits
kraken-app
...
6686cb8392
Author | SHA1 | Date | |
---|---|---|---|
6686cb8392
|
|||
21108fbc10
|
|||
2c9a70e13c
|
|||
2c37384af5
|
|||
04d1ffc971
|
|||
0ca78b015e
|
|||
0cb923a3a5 | |||
ce55f6523c
|
|||
564147eb6a
|
|||
fcd369d48f
|
|||
c759f8e698
|
|||
fd7b06e840 | |||
c7e773be93
|
|||
559fb41571 | |||
1b14d33a53 | |||
d9404525f5
|
1
.gitignore
vendored
1
.gitignore
vendored
@@ -1,2 +1 @@
|
||||
.cuddle/
|
||||
.env
|
||||
|
@@ -1,11 +0,0 @@
|
||||
|
||||
branches:
|
||||
- "main"
|
||||
- "v0.x"
|
||||
|
||||
plugins:
|
||||
- "@semantic-release/commit-analyzer"
|
||||
- "@semantic-release/release-notes-generator"
|
||||
- "@semantic-release/changelog"
|
||||
- "@semantic-release/git"
|
||||
|
@@ -1,8 +0,0 @@
|
||||
FROM debian:bullseye-slim
|
||||
|
||||
# Kraken relies on this path being the specified path
|
||||
WORKDIR /src/work/
|
||||
|
||||
COPY entry.sh /src/script.sh
|
||||
|
||||
CMD [ "/src/script.sh" ]
|
@@ -1,5 +0,0 @@
|
||||
#!/bin/bash
|
||||
|
||||
set -e
|
||||
|
||||
echo "# README docker" > README.md
|
@@ -1,11 +0,0 @@
|
||||
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
|
||||
)
|
@@ -1,20 +0,0 @@
|
||||
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=
|
@@ -1,11 +0,0 @@
|
||||
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
|
@@ -3,9 +3,116 @@ name: write-a-readme
|
||||
select:
|
||||
repositories:
|
||||
- git@git.front.kjuulh.io:kjuulh/kraken-test.git
|
||||
# providers:
|
||||
# - gitea: https://git.front.kjuulh.io
|
||||
# organisation: "cibus"
|
||||
- git@git.front.kjuulh.io:kjuulh/kraken-test.git
|
||||
- git@git.front.kjuulh.io:kjuulh/kraken-test.git
|
||||
- git@git.front.kjuulh.io:kjuulh/kraken-test.git
|
||||
- git@git.front.kjuulh.io:kjuulh/kraken-test.git
|
||||
- git@git.front.kjuulh.io:kjuulh/kraken-test.git
|
||||
- git@git.front.kjuulh.io:kjuulh/kraken-test.git
|
||||
- git@git.front.kjuulh.io:kjuulh/kraken-test.git
|
||||
- git@git.front.kjuulh.io:kjuulh/kraken-test.git
|
||||
- git@git.front.kjuulh.io:kjuulh/kraken-test.git
|
||||
- git@git.front.kjuulh.io:kjuulh/kraken-test.git
|
||||
- git@git.front.kjuulh.io:kjuulh/kraken-test.git
|
||||
- git@git.front.kjuulh.io:kjuulh/kraken-test.git
|
||||
- git@git.front.kjuulh.io:kjuulh/kraken-test.git
|
||||
- git@git.front.kjuulh.io:kjuulh/kraken-test.git
|
||||
- git@git.front.kjuulh.io:kjuulh/kraken-test.git
|
||||
- git@git.front.kjuulh.io:kjuulh/kraken-test.git
|
||||
- git@git.front.kjuulh.io:kjuulh/kraken-test.git
|
||||
- git@git.front.kjuulh.io:kjuulh/kraken-test.git
|
||||
- git@git.front.kjuulh.io:kjuulh/kraken-test.git
|
||||
- git@git.front.kjuulh.io:kjuulh/kraken-test.git
|
||||
- git@git.front.kjuulh.io:kjuulh/kraken-test.git
|
||||
- git@git.front.kjuulh.io:kjuulh/kraken-test.git
|
||||
- git@git.front.kjuulh.io:kjuulh/kraken-test.git
|
||||
- git@git.front.kjuulh.io:kjuulh/kraken-test.git
|
||||
- git@git.front.kjuulh.io:kjuulh/kraken-test.git
|
||||
- git@git.front.kjuulh.io:kjuulh/kraken-test.git
|
||||
- git@git.front.kjuulh.io:kjuulh/kraken-test.git
|
||||
- git@git.front.kjuulh.io:kjuulh/kraken-test.git
|
||||
- git@git.front.kjuulh.io:kjuulh/kraken-test.git
|
||||
- git@git.front.kjuulh.io:kjuulh/kraken-test.git
|
||||
- git@git.front.kjuulh.io:kjuulh/kraken-test.git
|
||||
- git@git.front.kjuulh.io:kjuulh/kraken-test.git
|
||||
- git@git.front.kjuulh.io:kjuulh/kraken-test.git
|
||||
- git@git.front.kjuulh.io:kjuulh/kraken-test.git
|
||||
- git@git.front.kjuulh.io:kjuulh/kraken-test.git
|
||||
- git@git.front.kjuulh.io:kjuulh/kraken-test.git
|
||||
- git@git.front.kjuulh.io:kjuulh/kraken-test.git
|
||||
- git@git.front.kjuulh.io:kjuulh/kraken-test.git
|
||||
- git@git.front.kjuulh.io:kjuulh/kraken-test.git
|
||||
- git@git.front.kjuulh.io:kjuulh/kraken-test.git
|
||||
- git@git.front.kjuulh.io:kjuulh/kraken-test.git
|
||||
- git@git.front.kjuulh.io:kjuulh/kraken-test.git
|
||||
- git@git.front.kjuulh.io:kjuulh/kraken-test.git
|
||||
- git@git.front.kjuulh.io:kjuulh/kraken-test.git
|
||||
- git@git.front.kjuulh.io:kjuulh/kraken-test.git
|
||||
- git@git.front.kjuulh.io:kjuulh/kraken-test.git
|
||||
- git@git.front.kjuulh.io:kjuulh/kraken-test.git
|
||||
- git@git.front.kjuulh.io:kjuulh/kraken-test.git
|
||||
- git@git.front.kjuulh.io:kjuulh/kraken-test.git
|
||||
- git@git.front.kjuulh.io:kjuulh/kraken-test.git
|
||||
- git@git.front.kjuulh.io:kjuulh/kraken-test.git
|
||||
- git@git.front.kjuulh.io:kjuulh/kraken-test.git
|
||||
- git@git.front.kjuulh.io:kjuulh/kraken-test.git
|
||||
- git@git.front.kjuulh.io:kjuulh/kraken-test.git
|
||||
- git@git.front.kjuulh.io:kjuulh/kraken-test.git
|
||||
- git@git.front.kjuulh.io:kjuulh/kraken-test.git
|
||||
- git@git.front.kjuulh.io:kjuulh/kraken-test.git
|
||||
- git@git.front.kjuulh.io:kjuulh/kraken-test.git
|
||||
- git@git.front.kjuulh.io:kjuulh/kraken-test.git
|
||||
- git@git.front.kjuulh.io:kjuulh/kraken-test.git
|
||||
- git@git.front.kjuulh.io:kjuulh/kraken-test.git
|
||||
- git@git.front.kjuulh.io:kjuulh/kraken-test.git
|
||||
- git@git.front.kjuulh.io:kjuulh/kraken-test.git
|
||||
- git@git.front.kjuulh.io:kjuulh/kraken-test.git
|
||||
- git@git.front.kjuulh.io:kjuulh/kraken-test.git
|
||||
- git@git.front.kjuulh.io:kjuulh/kraken-test.git
|
||||
- git@git.front.kjuulh.io:kjuulh/kraken-test.git
|
||||
- git@git.front.kjuulh.io:kjuulh/kraken-test.git
|
||||
- git@git.front.kjuulh.io:kjuulh/kraken-test.git
|
||||
- git@git.front.kjuulh.io:kjuulh/kraken-test.git
|
||||
- git@git.front.kjuulh.io:kjuulh/kraken-test.git
|
||||
- git@git.front.kjuulh.io:kjuulh/kraken-test.git
|
||||
- git@git.front.kjuulh.io:kjuulh/kraken-test.git
|
||||
- git@git.front.kjuulh.io:kjuulh/kraken-test.git
|
||||
- git@git.front.kjuulh.io:kjuulh/kraken-test.git
|
||||
- git@git.front.kjuulh.io:kjuulh/kraken-test.git
|
||||
- git@git.front.kjuulh.io:kjuulh/kraken-test.git
|
||||
- git@git.front.kjuulh.io:kjuulh/kraken-test.git
|
||||
- git@git.front.kjuulh.io:kjuulh/kraken-test.git
|
||||
- git@git.front.kjuulh.io:kjuulh/kraken-test.git
|
||||
- git@git.front.kjuulh.io:kjuulh/kraken-test.git
|
||||
- git@git.front.kjuulh.io:kjuulh/kraken-test.git
|
||||
- git@git.front.kjuulh.io:kjuulh/kraken-test.git
|
||||
- git@git.front.kjuulh.io:kjuulh/kraken-test.git
|
||||
- git@git.front.kjuulh.io:kjuulh/kraken-test.git
|
||||
- git@git.front.kjuulh.io:kjuulh/kraken-test.git
|
||||
- git@git.front.kjuulh.io:kjuulh/kraken-test.git
|
||||
- git@git.front.kjuulh.io:kjuulh/kraken-test.git
|
||||
- git@git.front.kjuulh.io:kjuulh/kraken-test.git
|
||||
- git@git.front.kjuulh.io:kjuulh/kraken-test.git
|
||||
- git@git.front.kjuulh.io:kjuulh/kraken-test.git
|
||||
- git@git.front.kjuulh.io:kjuulh/kraken-test.git
|
||||
- git@git.front.kjuulh.io:kjuulh/kraken-test.git
|
||||
- git@git.front.kjuulh.io:kjuulh/kraken-test.git
|
||||
- git@git.front.kjuulh.io:kjuulh/kraken-test.git
|
||||
- git@git.front.kjuulh.io:kjuulh/kraken-test.git
|
||||
- git@git.front.kjuulh.io:kjuulh/kraken-test.git
|
||||
- git@git.front.kjuulh.io:kjuulh/kraken-test.git
|
||||
- git@git.front.kjuulh.io:kjuulh/kraken-test.git
|
||||
- git@git.front.kjuulh.io:kjuulh/kraken-test.git
|
||||
- git@git.front.kjuulh.io:kjuulh/kraken-test.git
|
||||
- git@git.front.kjuulh.io:kjuulh/kraken-test.git
|
||||
- git@git.front.kjuulh.io:kjuulh/kraken-test.git
|
||||
- git@git.front.kjuulh.io:kjuulh/kraken-test.git
|
||||
- git@git.front.kjuulh.io:kjuulh/kraken-test.git
|
||||
- git@git.front.kjuulh.io:kjuulh/kraken-test.git
|
||||
- git@git.front.kjuulh.io:kjuulh/kraken-test.git
|
||||
providers:
|
||||
- gitea: https://git.front.kjuulh.io
|
||||
organisation: "cibus"
|
||||
actions:
|
||||
- type: go
|
||||
entry: "main.go"
|
||||
|
@@ -1,11 +0,0 @@
|
||||
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"
|
||||
queries:
|
||||
- type: grep
|
||||
query: "# README"
|
@@ -9,19 +9,9 @@ import (
|
||||
)
|
||||
|
||||
func CreateKrakenProcessCmd() *cobra.Command {
|
||||
|
||||
var (
|
||||
actionsRepo string
|
||||
branch string
|
||||
path string
|
||||
)
|
||||
cmd := &cobra.Command{
|
||||
Use: "process",
|
||||
RunE: func(cmd *cobra.Command, args []string) error {
|
||||
if err := cmd.ParseFlags(args); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
Run: func(cmd *cobra.Command, _ []string) {
|
||||
client := http.Client{}
|
||||
|
||||
var buf bytes.Buffer
|
||||
@@ -31,9 +21,9 @@ func CreateKrakenProcessCmd() *cobra.Command {
|
||||
Branch string `json:"branch"`
|
||||
Path string `json:"path"`
|
||||
}{
|
||||
Repository: actionsRepo,
|
||||
Branch: branch,
|
||||
Path: path,
|
||||
Repository: "git@git.front.kjuulh.io:kjuulh/kraken.git",
|
||||
Branch: "feature/gitea-integration",
|
||||
Path: "_examples/actions/write_a_readme/",
|
||||
})
|
||||
if err != nil {
|
||||
panic(err)
|
||||
@@ -56,18 +46,8 @@ func CreateKrakenProcessCmd() *cobra.Command {
|
||||
if resp.StatusCode >= 300 {
|
||||
panic(resp.Status)
|
||||
}
|
||||
|
||||
return nil
|
||||
},
|
||||
}
|
||||
|
||||
pf := cmd.PersistentFlags()
|
||||
|
||||
pf.StringVar(&actionsRepo, "actions-repo", "", "actions repo is the location of your actions, not where to apply the actions themselves, that should be self contained")
|
||||
cmd.MarkPersistentFlagRequired("actions-repo")
|
||||
pf.StringVar(&branch, "branch", "main", "which branch to look for actions in, will default to main")
|
||||
pf.StringVar(&path, "path", "", "the location of the path inside the repository")
|
||||
cmd.MarkPersistentFlagRequired("path")
|
||||
|
||||
return cmd
|
||||
}
|
||||
|
@@ -9,9 +9,3 @@ vars:
|
||||
scripts:
|
||||
push_github:
|
||||
type: shell
|
||||
run_server:
|
||||
type: shell
|
||||
run_client:
|
||||
type: shell
|
||||
run:
|
||||
type: shell
|
||||
|
1
go.mod
1
go.mod
@@ -49,7 +49,6 @@ require (
|
||||
github.com/sirupsen/logrus v1.7.0 // indirect
|
||||
github.com/spf13/pflag v1.0.5 // indirect
|
||||
github.com/ugorji/go/codec v1.2.7 // indirect
|
||||
github.com/whilp/git-urls v1.0.0 // indirect
|
||||
github.com/xanzy/ssh-agent v0.3.2 // indirect
|
||||
go.uber.org/atomic v1.10.0 // indirect
|
||||
go.uber.org/multierr v1.8.0 // indirect
|
||||
|
2
go.sum
2
go.sum
@@ -153,8 +153,6 @@ github.com/ugorji/go v1.2.7/go.mod h1:nF9osbDWLy6bDVv/Rtoh6QgnvNDpmCalQV5urGCCS6
|
||||
github.com/ugorji/go/codec v1.1.7/go.mod h1:Ax+UKWsSmolVDwsd+7N3ZtXu+yMGCf907BLYF3GoBXY=
|
||||
github.com/ugorji/go/codec v1.2.7 h1:YPXUKf7fYbp/y8xloBqZOw2qaVggbfwMlI8WM3wZUJ0=
|
||||
github.com/ugorji/go/codec v1.2.7/go.mod h1:WGN1fab3R1fzQlVQTkfxVtIBhWDRqOviHU95kRgeqEY=
|
||||
github.com/whilp/git-urls v1.0.0 h1:95f6UMWN5FKW71ECsXRUd3FVYiXdrE7aX4NZKcPmIjU=
|
||||
github.com/whilp/git-urls v1.0.0/go.mod h1:J16SAmobsqc3Qcy98brfl5f5+e0clUvg1krgwk/qCfE=
|
||||
github.com/xanzy/ssh-agent v0.3.0/go.mod h1:3s9xbODqPuuhK9JV1R321M/FlMZSBvE5aY6eAcqrDh0=
|
||||
github.com/xanzy/ssh-agent v0.3.2 h1:eKj4SX2Fe7mui28ZgnFW5fmTz1EIr7ugo5s6wDxdHBM=
|
||||
github.com/xanzy/ssh-agent v0.3.2/go.mod h1:6dzNDKs0J9rVPHPhaGCukekBHKqfl+L3KghI1Bc68Uw=
|
||||
|
@@ -5,7 +5,6 @@ import (
|
||||
"errors"
|
||||
|
||||
"git.front.kjuulh.io/kjuulh/kraken/internal/actions/builders"
|
||||
"git.front.kjuulh.io/kjuulh/kraken/internal/actions/querier"
|
||||
"git.front.kjuulh.io/kjuulh/kraken/internal/schema"
|
||||
"git.front.kjuulh.io/kjuulh/kraken/internal/services/storage"
|
||||
"go.uber.org/zap"
|
||||
@@ -31,18 +30,6 @@ func (a *Action) Execute(ctx context.Context, area *storage.Area) error {
|
||||
|
||||
zap.L().Debug("Execution done")
|
||||
|
||||
case "docker-build":
|
||||
zap.L().Debug("Building 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")
|
||||
}
|
||||
@@ -50,28 +37,3 @@ func (a *Action) Execute(ctx context.Context, area *storage.Area) error {
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
func (a *Action) Query(ctx context.Context, area *storage.Area) ([]string, bool, error) {
|
||||
for _, query := range a.Schema.Queries {
|
||||
switch query.Type {
|
||||
case "grep":
|
||||
exe, err := querier.NewRipGrep(zap.L()).Build(ctx, a.SchemaPath, query.Query)
|
||||
if err != nil {
|
||||
return nil, false, err
|
||||
}
|
||||
output, found, err := exe(ctx, area.Path)
|
||||
if err != nil {
|
||||
return nil, false, err
|
||||
}
|
||||
|
||||
zap.L().Debug("Execution done")
|
||||
|
||||
return output, found, nil
|
||||
|
||||
default:
|
||||
return nil, false, errors.New("could not determine query type")
|
||||
}
|
||||
}
|
||||
|
||||
return nil, false, nil
|
||||
}
|
||||
|
@@ -1,95 +0,0 @@
|
||||
package builders
|
||||
|
||||
import (
|
||||
"context"
|
||||
"crypto/rand"
|
||||
"encoding/hex"
|
||||
"errors"
|
||||
"fmt"
|
||||
"os"
|
||||
"os/exec"
|
||||
|
||||
"go.uber.org/zap"
|
||||
"go.uber.org/zap/zapio"
|
||||
)
|
||||
|
||||
type DockerBuild struct {
|
||||
logger *zap.Logger
|
||||
}
|
||||
|
||||
func NewDockerBuild(logger *zap.Logger) *DockerBuild {
|
||||
return &DockerBuild{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")
|
||||
}
|
||||
|
||||
b := make([]byte, 20)
|
||||
_, err := rand.Reader.Read(b)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
tag := hex.EncodeToString(b)
|
||||
buildDockerCmd := fmt.Sprintf("(cd %s; docker build -f %s --tag kraken/%s .)", modulePath, entryPath, tag)
|
||||
g.logger.Debug("Running command", zap.String("command", buildDockerCmd))
|
||||
|
||||
cmd := exec.CommandContext(
|
||||
ctx,
|
||||
"/bin/bash",
|
||||
"-c",
|
||||
buildDockerCmd,
|
||||
)
|
||||
|
||||
debugwriter := &zapio.Writer{
|
||||
Log: g.logger,
|
||||
Level: zap.DebugLevel,
|
||||
}
|
||||
defer debugwriter.Close()
|
||||
|
||||
cmd.Stdout = debugwriter
|
||||
cmd.Stderr = debugwriter
|
||||
err = cmd.Start()
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
err = cmd.Wait()
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
g.logger.Debug("Docker image 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("docker run --rm -v %s/:/src/work/ kraken/%s", victimPath, tag),
|
||||
)
|
||||
|
||||
runDockerWriter := &zapio.Writer{
|
||||
Log: g.logger,
|
||||
Level: zap.DebugLevel,
|
||||
}
|
||||
defer runDockerWriter.Close()
|
||||
|
||||
cmd.Stdout = runDockerWriter
|
||||
cmd.Stderr = runDockerWriter
|
||||
|
||||
err = cmd.Start()
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
return cmd.Wait()
|
||||
}, nil
|
||||
}
|
@@ -1,106 +0,0 @@
|
||||
package querier
|
||||
|
||||
import (
|
||||
"context"
|
||||
"fmt"
|
||||
"io"
|
||||
"os/exec"
|
||||
"strings"
|
||||
|
||||
"go.uber.org/zap"
|
||||
"go.uber.org/zap/zapio"
|
||||
)
|
||||
|
||||
type RipGrep struct {
|
||||
logger *zap.Logger
|
||||
}
|
||||
|
||||
func NewRipGrep(logger *zap.Logger) *RipGrep {
|
||||
return &RipGrep{logger: logger}
|
||||
}
|
||||
|
||||
type RipGrepCommand func(ctx context.Context, victimPath string) ([]string, bool, error)
|
||||
|
||||
func (g *RipGrep) Build(ctx context.Context, modulePath, query string) (RipGrepCommand, error) {
|
||||
g.logger.Debug("Pulling docker image", zap.String("actiondir", modulePath), zap.String("query", query))
|
||||
|
||||
pullDockerImage := "docker pull mbologna/docker-ripgrep"
|
||||
g.logger.Debug("Running command", zap.String("command", pullDockerImage))
|
||||
|
||||
cmd := exec.CommandContext(
|
||||
ctx,
|
||||
"/bin/bash",
|
||||
"-c",
|
||||
pullDockerImage,
|
||||
)
|
||||
|
||||
debugwriter := &zapio.Writer{
|
||||
Log: g.logger,
|
||||
Level: zap.DebugLevel,
|
||||
}
|
||||
defer debugwriter.Close()
|
||||
|
||||
cmd.Stdout = debugwriter
|
||||
cmd.Stderr = debugwriter
|
||||
err := cmd.Start()
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
err = cmd.Wait()
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
g.logger.Debug("Docker image pulled")
|
||||
|
||||
return func(ctx context.Context, victimPath string) ([]string, bool, error) {
|
||||
g.logger.Debug("Executing script", zap.String("victim", victimPath))
|
||||
|
||||
runRipGrepCmd := fmt.Sprintf("docker run --rm -v %s/:/data:ro mbologna/docker-ripgrep rg -i '%s' || true", victimPath, query)
|
||||
|
||||
g.logger.Debug("Execute ripgrep query", zap.String("command", runRipGrepCmd))
|
||||
|
||||
cmd := exec.CommandContext(
|
||||
ctx,
|
||||
"/bin/bash",
|
||||
"-c",
|
||||
runRipGrepCmd,
|
||||
)
|
||||
|
||||
runDockerWriter := &zapio.Writer{
|
||||
Log: g.logger,
|
||||
Level: zap.DebugLevel,
|
||||
}
|
||||
defer runDockerWriter.Close()
|
||||
|
||||
builder := &strings.Builder{}
|
||||
combinedWriter := io.MultiWriter(runDockerWriter, builder)
|
||||
|
||||
cmd.Stdout = combinedWriter
|
||||
cmd.Stderr = combinedWriter
|
||||
|
||||
err = cmd.Start()
|
||||
if err != nil {
|
||||
return nil, false, err
|
||||
}
|
||||
|
||||
err = cmd.Wait()
|
||||
if err != nil {
|
||||
return nil, false, err
|
||||
}
|
||||
|
||||
contents := strings.Split(builder.String(), "\n")
|
||||
validatedOutput := make([]string, 0)
|
||||
|
||||
for _, c := range contents {
|
||||
if !strings.Contains(c, "WARNING:") {
|
||||
validatedOutput = append(validatedOutput, c)
|
||||
}
|
||||
}
|
||||
|
||||
found := len(validatedOutput) > 0
|
||||
|
||||
return validatedOutput, found, nil
|
||||
}, nil
|
||||
}
|
@@ -3,7 +3,6 @@ package commands
|
||||
import (
|
||||
"context"
|
||||
"fmt"
|
||||
"strings"
|
||||
"sync"
|
||||
"time"
|
||||
|
||||
@@ -12,7 +11,6 @@ import (
|
||||
"git.front.kjuulh.io/kjuulh/kraken/internal/schema"
|
||||
"git.front.kjuulh.io/kjuulh/kraken/internal/services/providers"
|
||||
"git.front.kjuulh.io/kjuulh/kraken/internal/services/storage"
|
||||
giturls "github.com/whilp/git-urls"
|
||||
"go.uber.org/zap"
|
||||
)
|
||||
|
||||
@@ -44,6 +42,8 @@ func NewProcessRepos(logger *zap.Logger, deps ProcessReposDeps) *ProcessRepos {
|
||||
}
|
||||
|
||||
func (pr *ProcessRepos) Process(ctx context.Context, repository string, branch string, actionPath string) error {
|
||||
errChan := make(chan error, 1)
|
||||
|
||||
action, err := pr.actionCreator.Prepare(ctx, &actions.ActionCreatorOps{
|
||||
RepositoryUrl: repository,
|
||||
Branch: branch,
|
||||
@@ -68,14 +68,19 @@ func (pr *ProcessRepos) Process(ctx context.Context, repository string, branch s
|
||||
}()
|
||||
err := pr.processRepo(ctx, repoUrl, action)
|
||||
if err != nil {
|
||||
pr.logger.Error("could not process repo", zap.Error(err))
|
||||
errChan <- err
|
||||
}
|
||||
}(ctx, repoUrl)
|
||||
}
|
||||
|
||||
wg.Wait()
|
||||
close(errChan)
|
||||
pr.logger.Debug("finished processing all repos", zap.Strings("repos", repositoryUrls))
|
||||
|
||||
for err := range errChan {
|
||||
return err
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
@@ -112,32 +117,17 @@ func (pr *ProcessRepos) processRepo(ctx context.Context, repoUrl string, action
|
||||
return err
|
||||
}
|
||||
|
||||
if len(action.Schema.Queries) > 0 {
|
||||
result, found, err := action.Query(ctx, area)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
if found {
|
||||
pr.logger.Info("Query result", zap.Strings("result", result))
|
||||
// TODO: Append to real result, and return together
|
||||
}
|
||||
err = action.Execute(ctx, area)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
if len(action.Schema.Actions) > 0 {
|
||||
err = action.Execute(ctx, area)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
err = pr.commit(ctx, area, repo, repoUrl)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
err = pr.commit(ctx, area, repo)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
pr.logger.Debug("processing done", zap.String("path", area.Path), zap.String("repoUrl", repoUrl))
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
@@ -177,64 +167,23 @@ func (pr *ProcessRepos) clone(ctx context.Context, area *storage.Area, repoUrl s
|
||||
return repo, nil
|
||||
}
|
||||
|
||||
func (pr *ProcessRepos) commit(ctx context.Context, area *storage.Area, repo *providers.GitRepo, repoUrl string) error {
|
||||
wt, err := pr.git.Add(ctx, area, repo)
|
||||
func (pr *ProcessRepos) commit(ctx context.Context, area *storage.Area, repo *providers.GitRepo) error {
|
||||
_, err := pr.git.Add(ctx, area, repo)
|
||||
if err != nil {
|
||||
return fmt.Errorf("could not add file: %w", err)
|
||||
}
|
||||
|
||||
status, err := wt.Status()
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
if status.IsClean() {
|
||||
pr.logger.Info("Returning early, as no modifications are detected")
|
||||
return nil
|
||||
}
|
||||
|
||||
err = pr.git.Commit(ctx, repo)
|
||||
if err != nil {
|
||||
return fmt.Errorf("could not get diff: %w", err)
|
||||
}
|
||||
|
||||
dryrun := false
|
||||
dryrun := true
|
||||
if !dryrun {
|
||||
|
||||
err = pr.git.Push(ctx, repo)
|
||||
if err != nil {
|
||||
return fmt.Errorf("could not push to repo: %w", err)
|
||||
}
|
||||
|
||||
url, err := giturls.Parse(repoUrl)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
head, err := repo.GetHEAD()
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
path := strings.Split(url.Path, "/")
|
||||
pr.logger.Debug("path string", zap.Strings("paths", path), zap.String("HEAD", head))
|
||||
|
||||
org := path[0]
|
||||
repoName := path[1]
|
||||
semanticName, _, ok := strings.Cut(repoName, ".")
|
||||
if !ok {
|
||||
semanticName = repoName
|
||||
}
|
||||
|
||||
originHead, err := pr.git.GetOriginHEADForRepo(ctx, repo)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
err = pr.gitea.CreatePr(ctx, fmt.Sprintf("%s://%s", "https", url.Host), org, semanticName, head, originHead, "kraken-apply")
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
@@ -2,9 +2,7 @@ package gitproviders
|
||||
|
||||
import (
|
||||
"context"
|
||||
"errors"
|
||||
"fmt"
|
||||
"os"
|
||||
"sync"
|
||||
|
||||
"code.gitea.io/sdk/gitea"
|
||||
@@ -25,11 +23,7 @@ func NewGitea(logger *zap.Logger) *Gitea {
|
||||
}
|
||||
}
|
||||
|
||||
func (g *Gitea) ListRepositoriesForOrganization(
|
||||
ctx context.Context,
|
||||
server string,
|
||||
organization string,
|
||||
) ([]string, error) {
|
||||
func (g *Gitea) ListRepositoriesForOrganization(ctx context.Context, server string, organization string) ([]string, error) {
|
||||
client, err := g.getOrCreateClient(ctx, server)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
@@ -58,82 +52,14 @@ func (g *Gitea) ListRepositoriesForOrganization(
|
||||
return repoUrls, err
|
||||
}
|
||||
|
||||
func (g *Gitea) CreatePr(
|
||||
ctx context.Context,
|
||||
server string,
|
||||
organization string,
|
||||
repository string,
|
||||
head string,
|
||||
base string,
|
||||
actionName string,
|
||||
) error {
|
||||
client, err := g.getOrCreateClient(ctx, server)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
prs, _, err := client.ListRepoPullRequests(organization, repository, gitea.ListPullRequestsOptions{
|
||||
ListOptions: gitea.ListOptions{
|
||||
Page: 0,
|
||||
PageSize: 30,
|
||||
},
|
||||
State: gitea.StateOpen,
|
||||
Sort: "recentupdate",
|
||||
Milestone: 0,
|
||||
})
|
||||
if err != nil {
|
||||
return fmt.Errorf(
|
||||
"could not list repos, needed because we need to check for conflicts. Original error: %w",
|
||||
err,
|
||||
)
|
||||
}
|
||||
for _, pr := range prs {
|
||||
if pr.Head.Name == head {
|
||||
g.logger.Info(
|
||||
"returning early from creating pull-request, as it already exists.",
|
||||
zap.String("repository", repository),
|
||||
zap.String("pull-request", pr.URL),
|
||||
)
|
||||
return nil
|
||||
}
|
||||
}
|
||||
|
||||
pr, _, err := client.CreatePullRequest(organization, repository, gitea.CreatePullRequestOption{
|
||||
Head: head,
|
||||
Base: base,
|
||||
Title: actionName,
|
||||
})
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
g.logger.Debug(
|
||||
"Created pr",
|
||||
zap.String("repository", repository),
|
||||
zap.String("branch", head),
|
||||
zap.String("pull-request", pr.URL),
|
||||
)
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
func (g *Gitea) getOrCreateClient(ctx context.Context, server string) (*gitea.Client, error) {
|
||||
g.giteamu.Lock()
|
||||
defer g.giteamu.Unlock()
|
||||
client, ok := g.giteaClients[server]
|
||||
if !ok || client == nil {
|
||||
c, err := gitea.NewClient(server)
|
||||
username, ok := os.LookupEnv("GITEA_USERNAME")
|
||||
if !ok {
|
||||
return nil, errors.New("missing environment variable GITEA_USERNAME")
|
||||
}
|
||||
apitoken, ok := os.LookupEnv("GITEA_API_TOKEN")
|
||||
if !ok {
|
||||
return nil, errors.New("missing environment variable GITEA_API_TOKEN")
|
||||
}
|
||||
c.SetBasicAuth(username, apitoken)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
return nil, nil
|
||||
}
|
||||
g.giteaClients[server] = c
|
||||
return c, nil
|
||||
|
@@ -16,10 +16,6 @@ type KrakenSchema struct {
|
||||
Type string `yaml:"type"`
|
||||
Entry string `yaml:"entry"`
|
||||
} `yaml:"actions"`
|
||||
Queries []struct {
|
||||
Type string `yaml:"type"`
|
||||
Query string `yaml:"query"`
|
||||
} `yaml:"queries"`
|
||||
}
|
||||
|
||||
func Unmarshal(raw string) (*KrakenSchema, error) {
|
||||
|
@@ -2,7 +2,6 @@ package providers
|
||||
|
||||
import (
|
||||
"context"
|
||||
"errors"
|
||||
"fmt"
|
||||
"time"
|
||||
|
||||
@@ -31,15 +30,6 @@ type GitRepo struct {
|
||||
repo *git.Repository
|
||||
}
|
||||
|
||||
func (gr *GitRepo) GetHEAD() (string, error) {
|
||||
head, err := gr.repo.Head()
|
||||
if err != nil {
|
||||
return "", err
|
||||
}
|
||||
|
||||
return head.Name().Short(), nil
|
||||
}
|
||||
|
||||
type GitAuth string
|
||||
|
||||
const (
|
||||
@@ -63,39 +53,6 @@ func NewGit(logger *zap.Logger, gitConfig *GitConfig, openPGP *signer.OpenPGP) *
|
||||
return &Git{logger: logger, gitConfig: gitConfig, openPGP: openPGP}
|
||||
}
|
||||
|
||||
func (g *Git) GetOriginHEADForRepo(ctx context.Context, gitRepo *GitRepo) (string, error) {
|
||||
auth, err := g.GetAuth()
|
||||
if err != nil {
|
||||
return "", err
|
||||
}
|
||||
|
||||
remote, err := gitRepo.repo.Remote("origin")
|
||||
if err != nil {
|
||||
return "", err
|
||||
}
|
||||
|
||||
refs, err := remote.ListContext(ctx, &git.ListOptions{
|
||||
Auth: auth,
|
||||
})
|
||||
if err != nil {
|
||||
return "", err
|
||||
}
|
||||
|
||||
headRef := ""
|
||||
for _, ref := range refs {
|
||||
//g.logger.Debug(ref.String())
|
||||
if !ref.Name().IsBranch() {
|
||||
headRef = ref.Target().Short()
|
||||
}
|
||||
}
|
||||
|
||||
if headRef == "" {
|
||||
return "", errors.New("no upstream HEAD branch could be found")
|
||||
}
|
||||
|
||||
return headRef, nil
|
||||
}
|
||||
|
||||
func (g *Git) CloneBranch(ctx context.Context, storageArea *storage.Area, repoUrl string, branch string) (*GitRepo, error) {
|
||||
g.logger.Debug(
|
||||
"cloning repository",
|
||||
@@ -113,7 +70,7 @@ func (g *Git) CloneBranch(ctx context.Context, storageArea *storage.Area, repoUr
|
||||
Auth: auth,
|
||||
RemoteName: "origin",
|
||||
ReferenceName: plumbing.NewBranchReferenceName(branch),
|
||||
SingleBranch: false,
|
||||
SingleBranch: true,
|
||||
NoCheckout: false,
|
||||
Depth: 1,
|
||||
RecurseSubmodules: 1,
|
||||
@@ -124,7 +81,7 @@ func (g *Git) CloneBranch(ctx context.Context, storageArea *storage.Area, repoUr
|
||||
}
|
||||
|
||||
repo, err := git.PlainCloneContext(ctx, storageArea.Path, false, &cloneOptions)
|
||||
if err != nil && !errors.Is(err, git.NoErrAlreadyUpToDate) {
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
@@ -150,7 +107,7 @@ func (g *Git) Clone(ctx context.Context, storageArea *storage.Area, repoUrl stri
|
||||
Auth: auth,
|
||||
RemoteName: "origin",
|
||||
ReferenceName: "refs/heads/main",
|
||||
SingleBranch: false,
|
||||
SingleBranch: true,
|
||||
NoCheckout: false,
|
||||
Depth: 1,
|
||||
RecurseSubmodules: 1,
|
||||
@@ -242,7 +199,7 @@ func (g *Git) CreateBranch(ctx context.Context, gitRepo *GitRepo) error {
|
||||
err = worktree.PullContext(ctx, &git.PullOptions{
|
||||
RemoteName: "origin",
|
||||
ReferenceName: "refs/heads/main",
|
||||
SingleBranch: false,
|
||||
SingleBranch: true,
|
||||
Depth: 1,
|
||||
Auth: auth,
|
||||
RecurseSubmodules: 1,
|
||||
@@ -251,7 +208,7 @@ func (g *Git) CreateBranch(ctx context.Context, gitRepo *GitRepo) error {
|
||||
InsecureSkipTLS: false,
|
||||
CABundle: []byte{},
|
||||
})
|
||||
if err != nil && !errors.Is(err, git.NoErrAlreadyUpToDate) {
|
||||
if err != nil {
|
||||
return fmt.Errorf("could not pull from origin: %w", err)
|
||||
}
|
||||
|
||||
@@ -293,11 +250,12 @@ func (g *Git) Push(ctx context.Context, gitRepo *GitRepo) error {
|
||||
Auth: auth,
|
||||
Progress: g.getProgressWriter(),
|
||||
Prune: false,
|
||||
Force: true,
|
||||
Force: false,
|
||||
InsecureSkipTLS: false,
|
||||
CABundle: []byte{},
|
||||
RequireRemoteRefs: []config.RefSpec{},
|
||||
})
|
||||
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
21
roadmap.md
21
roadmap.md
@@ -20,12 +20,12 @@
|
||||
|
||||
- [x] Setup a way to choose actions and predicates
|
||||
- [x] Allow instantiation of actions, kraken template repo etc.
|
||||
- [x] Implement docker action
|
||||
- [x] Create pr for gitea provider
|
||||
- [x] Providing query results
|
||||
- [ ] Create pr for gitea provider
|
||||
- [ ] Think about some sort of isolation
|
||||
- [ ] Create CLI to trigger action
|
||||
|
||||
### Not in scope
|
||||
- [ ] Setup pool of runners
|
||||
- [ ] Run authenticated on servers
|
||||
- [ ] Create queuing system
|
||||
|
||||
## Version 1.0
|
||||
|
||||
@@ -33,14 +33,3 @@
|
||||
- [ ] Make configurable ssh user
|
||||
- [ ] Make configurable gpg keyset
|
||||
- [ ] Make configurable git provider
|
||||
- [ ] Create templating function
|
||||
- [ ] Add way to see progress of runners
|
||||
- [ ] Implement global .kraken store for easy access
|
||||
- [ ] Move builders to start instead of every time
|
||||
|
||||
## Version 1.x
|
||||
|
||||
- Think about some sort of isolation
|
||||
- Run authenticated on servers
|
||||
- Create queuing system
|
||||
- Setup pool of runners
|
||||
|
@@ -1,15 +0,0 @@
|
||||
#!/bin/bash
|
||||
|
||||
set -e
|
||||
|
||||
run_server="cuddle_cli x run_server"
|
||||
|
||||
$run_server &
|
||||
|
||||
sleep 1s
|
||||
|
||||
cuddle_cli x run_client
|
||||
|
||||
sleep 5s
|
||||
|
||||
kill %1
|
@@ -1,8 +0,0 @@
|
||||
#!/bin/bash
|
||||
|
||||
set -e
|
||||
|
||||
current_branch=$(git branch --show-current)
|
||||
|
||||
go run cmd/kraken/kraken.go process --actions-repo "git@git.front.kjuulh.io:kjuulh/kraken.git" --branch "$current_branch" --path "_examples/actions/write_a_readme"
|
||||
go run cmd/kraken/kraken.go process --actions-repo "git@git.front.kjuulh.io:kjuulh/kraken.git" --branch "$current_branch" --path "_examples/queries/scrape_readme"
|
@@ -1,7 +0,0 @@
|
||||
#!/bin/bash
|
||||
|
||||
set -e
|
||||
|
||||
export $(cat .env | xargs)
|
||||
|
||||
go run cmd/server/server.go start
|
Reference in New Issue
Block a user