From e81ce750b773155d60c6a25a4000ebd347976587 Mon Sep 17 00:00:00 2001 From: "Claire.Nicholas" Date: Fri, 25 Aug 2023 11:59:08 -0500 Subject: [PATCH] feat: adding build executable to worker --- cmd/vela-worker/exec.go | 15 ++++++++++++++- executor/linux/build.go | 4 +++- go.mod | 4 ++-- go.sum | 8 ++++---- 4 files changed, 23 insertions(+), 8 deletions(-) diff --git a/cmd/vela-worker/exec.go b/cmd/vela-worker/exec.go index 4e336997..072962b6 100644 --- a/cmd/vela-worker/exec.go +++ b/cmd/vela-worker/exec.go @@ -6,6 +6,7 @@ package main import ( "context" + "encoding/json" "net/http" "strconv" "sync" @@ -14,6 +15,7 @@ import ( "github.com/go-vela/types" "github.com/go-vela/types/constants" "github.com/go-vela/types/library" + "github.com/go-vela/types/pipeline" "github.com/go-vela/worker/executor" "github.com/go-vela/worker/runtime" "github.com/go-vela/worker/version" @@ -60,6 +62,17 @@ func (w *Worker) exec(index int, config *library.Worker) error { return err } + execBuildExecutable, resp, err := execBuildClient.Build.GetBuildExecutable(item.Repo.GetOrg(), item.Repo.GetName(), item.Build.GetNumber()) + if err != nil { + return err + } + + var execBuildExecutablePipeline pipeline.Build + err = json.Unmarshal([]byte(execBuildExecutable.GetData()), &execBuildExecutablePipeline) + if err != nil { + return err + } + // create logger with extra metadata // // https://pkg.go.dev/github.com/sirupsen/logrus?tab=doc#WithFields @@ -149,7 +162,7 @@ func (w *Worker) exec(index int, config *library.Worker) error { Hostname: w.Config.API.Address.Hostname(), Runtime: w.Runtime, Build: item.Build, - Pipeline: item.Pipeline.Sanitize(w.Config.Runtime.Driver), + Pipeline: &execBuildExecutablePipeline, Repo: item.Repo, User: item.User, Version: v.Semantic(), diff --git a/executor/linux/build.go b/executor/linux/build.go index cb55d5be..51eff038 100644 --- a/executor/linux/build.go +++ b/executor/linux/build.go @@ -369,6 +369,7 @@ func (c *client) AssembleBuild(ctx context.Context) error { // assume no privileged images are in use containsPrivilegedImages := false + var privImage string // verify all pipeline containers for _, container := range containers { @@ -408,6 +409,7 @@ func (c *client) AssembleBuild(ctx context.Context) error { if privileged { // pipeline contains at least one privileged image + privImage = container.Image containsPrivilegedImages = privileged } } @@ -421,7 +423,7 @@ func (c *client) AssembleBuild(ctx context.Context) error { // ensure pipelines containing privileged images are only permitted to run by trusted repos if (containsPrivilegedImages) && !(c.repo != nil && c.repo.GetTrusted()) { // update error - c.err = fmt.Errorf("unable to assemble build. pipeline contains privileged images and repo is not trusted") + c.err = fmt.Errorf("unable to assemble build. pipeline contains privileged images and repo is not trusted %s", privImage) // update the init log with image info // diff --git a/go.mod b/go.mod index 650b52b8..6e4c1dd7 100644 --- a/go.mod +++ b/go.mod @@ -8,9 +8,9 @@ require ( github.com/docker/docker v20.10.25+incompatible github.com/docker/go-units v0.5.0 github.com/gin-gonic/gin v1.9.1 - github.com/go-vela/sdk-go v0.20.1 + github.com/go-vela/sdk-go v0.20.2-0.20230824133536-0b0212b996f5 github.com/go-vela/server v0.20.1 - github.com/go-vela/types v0.20.1 + github.com/go-vela/types v0.20.2-0.20230822144153-14b37585731d github.com/golang-jwt/jwt/v5 v5.0.0 github.com/google/go-cmp v0.5.9 github.com/joho/godotenv v1.5.1 diff --git a/go.sum b/go.sum index 011680e2..61e62003 100644 --- a/go.sum +++ b/go.sum @@ -146,12 +146,12 @@ github.com/go-playground/universal-translator v0.18.1/go.mod h1:xekY+UJKNuX9WP91 github.com/go-playground/validator/v10 v10.14.0 h1:vgvQWe3XCz3gIeFDm/HnTIbj6UGmg/+t63MyGU2n5js= github.com/go-playground/validator/v10 v10.14.0/go.mod h1:9iXMNT7sEkjXb0I+enO7QXmzG6QCsPWY4zveKFVRSyU= github.com/go-task/slim-sprig v0.0.0-20210107165309-348f09dbbbc0 h1:p104kn46Q8WdvHunIJ9dAyjPVtrBPhSr3KT2yUst43I= -github.com/go-vela/sdk-go v0.20.1 h1:c0i4kzeHtvdZHJwCEIK9SsUUc6oSyynYv66IXw6MRCc= -github.com/go-vela/sdk-go v0.20.1/go.mod h1:LnWNiqcFVv9GARBFLLvgoYycfbi5PI187NrL1FLn8v0= +github.com/go-vela/sdk-go v0.20.2-0.20230824133536-0b0212b996f5 h1:PfGWo9Yzv6xfHYSYYArlsrWfs3cvOlBopCjHyHi/SPs= +github.com/go-vela/sdk-go v0.20.2-0.20230824133536-0b0212b996f5/go.mod h1:j7DFviaUd+XArpFr9KoHLWwUXRyFYAiZvPPF42gktoA= github.com/go-vela/server v0.20.1 h1:TsAhCj3wqm4kxfq9M6J8+3MmBKlDeJoTr4UGknT9yQw= github.com/go-vela/server v0.20.1/go.mod h1:M4rSAg8arMhIQYXQpc/ZmMbNW73ur8yE88klMk0Dq9w= -github.com/go-vela/types v0.20.1 h1:hHAX0Iij2J7UZ9f3SlXbwNy481CjKzU9CBfkiLuysVE= -github.com/go-vela/types v0.20.1/go.mod h1:AXO4oQSygOBQ02fPapsKjQHkx2aQO3zTu7clpvVbXBY= +github.com/go-vela/types v0.20.2-0.20230822144153-14b37585731d h1:ag6trc3Ev+7hzifeWy0M9rHHjrO9nFCYgW8dlKdZ4j4= +github.com/go-vela/types v0.20.2-0.20230822144153-14b37585731d/go.mod h1:AXO4oQSygOBQ02fPapsKjQHkx2aQO3zTu7clpvVbXBY= github.com/goccy/go-json v0.10.2 h1:CrxCmQqYDkv1z7lO7Wbh2HN93uovUHgrECaO5ZrCXAU= github.com/goccy/go-json v0.10.2/go.mod h1:6MelG93GURQebXPDq3khkgXZkazVtN9CRI+MGFi0w8I= github.com/gogo/protobuf v1.3.2 h1:Ov1cvc58UF3b5XjBnZv7+opcTcQFZebYjWzi34vdm4Q=