Skip to content

Commit

Permalink
feat: adding build executable to worker
Browse files Browse the repository at this point in the history
  • Loading branch information
Claire.Nicholas authored and Claire.Nicholas committed Aug 25, 2023
1 parent 07aa18d commit e81ce75
Show file tree
Hide file tree
Showing 4 changed files with 23 additions and 8 deletions.
15 changes: 14 additions & 1 deletion cmd/vela-worker/exec.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ package main

import (
"context"
"encoding/json"
"net/http"
"strconv"
"sync"
Expand All @@ -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"
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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(),
Expand Down
4 changes: 3 additions & 1 deletion executor/linux/build.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -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
}
}
Expand All @@ -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
//
Expand Down
4 changes: 2 additions & 2 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
8 changes: 4 additions & 4 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -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=
Expand Down

0 comments on commit e81ce75

Please sign in to comment.