WIP: with docker action
This commit is contained in:
parent
8c6eea468e
commit
c2d1a7b89e
@ -3,6 +3,4 @@ FROM debian:bullseye-slim
|
|||||||
# Kraken relies on this path being the specified path
|
# Kraken relies on this path being the specified path
|
||||||
WORKDIR /src/work/
|
WORKDIR /src/work/
|
||||||
|
|
||||||
COPY . .
|
RUN echo "# README docker" > README.md
|
||||||
|
|
||||||
RUN echo "# README docker" >> README.md
|
|
||||||
|
@ -8,4 +8,4 @@ select:
|
|||||||
# organisation: "cibus"
|
# organisation: "cibus"
|
||||||
actions:
|
actions:
|
||||||
- type: docker-build
|
- type: docker-build
|
||||||
entry: "Dockerfile"
|
entry: Dockerfile
|
||||||
|
@ -31,6 +31,7 @@ func (a *Action) Execute(ctx context.Context, area *storage.Area) error {
|
|||||||
zap.L().Debug("Execution done")
|
zap.L().Debug("Execution done")
|
||||||
|
|
||||||
case "docker-build":
|
case "docker-build":
|
||||||
|
zap.L().Debug("Building docker-build")
|
||||||
runCmd, err := builders.NewDockerBuild(zap.L()).Build(ctx, a.SchemaPath, action.Entry)
|
runCmd, err := builders.NewDockerBuild(zap.L()).Build(ctx, a.SchemaPath, action.Entry)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
|
@ -2,20 +2,23 @@ package builders
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"context"
|
"context"
|
||||||
|
"crypto/rand"
|
||||||
|
"encoding/hex"
|
||||||
"errors"
|
"errors"
|
||||||
"fmt"
|
"fmt"
|
||||||
"os"
|
"os"
|
||||||
"os/exec"
|
"os/exec"
|
||||||
|
|
||||||
"go.uber.org/zap"
|
"go.uber.org/zap"
|
||||||
|
"go.uber.org/zap/zapio"
|
||||||
)
|
)
|
||||||
|
|
||||||
type DockerBuild struct {
|
type DockerBuild struct {
|
||||||
logger *zap.Logger
|
logger *zap.Logger
|
||||||
}
|
}
|
||||||
|
|
||||||
func NewDockerBuild(logger *zap.Logger) *Go {
|
func NewDockerBuild(logger *zap.Logger) *DockerBuild {
|
||||||
return &Go{logger: logger}
|
return &DockerBuild{logger: logger}
|
||||||
}
|
}
|
||||||
|
|
||||||
type DockerRunCommand func(ctx context.Context, victimPath string) error
|
type DockerRunCommand func(ctx context.Context, victimPath string) error
|
||||||
@ -27,7 +30,41 @@ func (g *DockerBuild) Build(ctx context.Context, modulePath, entryPath string) (
|
|||||||
return nil, errors.New("could not find entry")
|
return nil, errors.New("could not find entry")
|
||||||
}
|
}
|
||||||
|
|
||||||
g.logger.Debug("Go binary built!")
|
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 {
|
return func(ctx context.Context, victimPath string) error {
|
||||||
g.logger.Debug("Executing script", zap.String("victim", victimPath))
|
g.logger.Debug("Executing script", zap.String("victim", victimPath))
|
||||||
@ -36,9 +73,23 @@ func (g *DockerBuild) Build(ctx context.Context, modulePath, entryPath string) (
|
|||||||
ctx,
|
ctx,
|
||||||
"/bin/bash",
|
"/bin/bash",
|
||||||
"-c",
|
"-c",
|
||||||
fmt.Sprintf("(cd %s; docker build)", modulePath),
|
fmt.Sprintf("docker run --rm -v %s/:/src/work/ kraken/%s", victimPath, tag),
|
||||||
)
|
)
|
||||||
|
|
||||||
return cmd.Run()
|
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
|
}, nil
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user