Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Worker builds binary in case the binary doesn't match the worker arch #200

Merged
merged 52 commits into from
Sep 4, 2019
Merged
Show file tree
Hide file tree
Changes from 20 commits
Commits
Show all changes
52 commits
Select commit Hold shift + click to select a range
265fb7d
Initial try to build binary by worker.
Jul 23, 2019
9557f27
A little bit of refactoring.
Jul 23, 2019
a56c272
Cleaning up the errorous binary.
Skarlso Jul 23, 2019
763462d
A different approach.
Skarlso Jul 23, 2019
fc756b9
Creating an api which the worker can call to get information about th…
Skarlso Jul 24, 2019
0e241f5
Skeleton of the api
Skarlso Jul 25, 2019
43fab8f
Added more logic.
Skarlso Jul 25, 2019
f355109
Using the name instead
Skarlso Jul 25, 2019
4bde3b2
Moar info
Skarlso Jul 25, 2019
8c346ad
Added correct error display.
Skarlso Jul 25, 2019
3ab6e20
RPC endpoint.
Jul 25, 2019
b19d052
Changed impl to gRPC
Jul 25, 2019
0b67ca3
Fixed wording and nil panic
Skarlso Jul 25, 2019
5b22447
Using the ID instead.
Skarlso Jul 25, 2019
52843de
Cannot save pipeline run
Skarlso Jul 25, 2019
0045758
GitPull the repo...
Skarlso Jul 25, 2019
73d8c18
Handling error
Skarlso Jul 25, 2019
23198f9
It works!
Skarlso Jul 25, 2019
d5acea1
Agent test build failure.
Skarlso Jul 25, 2019
9d19530
linter
Skarlso Jul 25, 2019
7c5648b
Trying out createpipeline again.
Skarlso Jul 26, 2019
c5ff190
Extracting rebuilding of binary.
Skarlso Jul 26, 2019
0e76372
Linting fix
Skarlso Jul 26, 2019
b625ee5
mergin...
Skarlso Jul 27, 2019
4e00b1f
Merge branch 'master' into issues_194_worker_builds_binary
Skarlso Jul 27, 2019
c1dbc53
Fixed version of protoc-gen-go
Skarlso Jul 27, 2019
ef7784d
Create the skeleton for the sha pair work
Aug 17, 2019
7768c37
The skeleton is there. Daughter woke up I will have to continue this …
Skarlso Aug 17, 2019
3cd8a84
Small adjustments.
Skarlso Aug 17, 2019
30444f5
Added metadata uniqueid to shapair.
Skarlso Aug 17, 2019
9ac6e38
Using pipelinID as string.
Skarlso Aug 18, 2019
0fc686b
Working on checking if there was a record or not.
Skarlso Aug 18, 2019
b9ac24b
Fixed condition.
Skarlso Aug 18, 2019
899b2bf
Added re-try of the failed operation after the binary has been rebuilt.
Skarlso Aug 19, 2019
315db17
Fixed the test.
Skarlso Aug 19, 2019
ba10c67
Added test and nil check for private key.
Skarlso Aug 19, 2019
3efb482
Deleting it for now... And then I will try to fix that.
Skarlso Aug 19, 2019
91b094d
Removed gosdk.
Skarlso Aug 19, 2019
1130104
Added a basic test case for the re-builder.
Skarlso Aug 19, 2019
c9e1bdf
Added test for the pipeline rebuilder.
Aug 22, 2019
820ff51
Some more coverage.
Aug 22, 2019
3c31dfb
TODO: Fix whatever is adding an extra run to the update workflow. It …
Aug 23, 2019
178a795
Fixed the test which was causing problems.
Aug 23, 2019
f773964
Passed test.
Aug 23, 2019
48ca7f6
Added moar coverage for the worker.
Skarlso Aug 25, 2019
47ea5c9
Added coverage to sha pair methods.
Skarlso Aug 25, 2019
f2c29d2
Merge branch 'master' into issues_194_worker_builds_binary
Sep 3, 2019
e4744b9
Shifted the sha storing process into bolt db.
Sep 3, 2019
e098b75
Added tests and fixed bucket names.
Sep 3, 2019
ca090e3
Changed to PipelineID instead of UniqueID which was unique per run in…
Sep 3, 2019
41b0432
Fixed comments.
Sep 4, 2019
5ca5149
Renamed uniqueID field to pipelineid so it does not get accidentally …
Sep 4, 2019
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ require (
github.com/emirpasic/gods v1.9.0 // indirect
github.com/flynn/go-shlex v0.0.0-20150515145356-3f9db97f8568 // indirect
github.com/gaia-pipeline/flag v1.7.4-pre
github.com/gaia-pipeline/gosdk v0.0.0-20180909192508-cc9f89055777
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

go mod automatically adds them when you test a pipeline build because the source code from the pipeline is in the tmp folder

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

interesting, I thought I made it ignore that folder. :D But apparently not. :)

github.com/gaia-pipeline/protobuf v0.0.0-20180812091451-7be8a901b55a
github.com/gliderlabs/ssh v0.1.1 // indirect
github.com/golang/protobuf v1.3.1
Expand Down Expand Up @@ -39,6 +40,7 @@ require (
github.com/stretchr/testify v1.3.0 // indirect
github.com/xanzy/ssh-agent v0.2.0 // indirect
golang.org/x/crypto v0.0.0-20190211182817-74369b46fc67
golang.org/x/net v0.0.0-20180826012351-8a410e7b638d
golang.org/x/oauth2 v0.0.0-20180821212333-d2e6202438be
golang.org/x/sys v0.0.0-20180905080454-ebe1bf3edb33 // indirect
google.golang.org/grpc v1.18.0
Expand Down
2 changes: 2 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,8 @@ github.com/flynn/go-shlex v0.0.0-20150515145356-3f9db97f8568 h1:BHsljHzVlRcyQhjr
github.com/flynn/go-shlex v0.0.0-20150515145356-3f9db97f8568/go.mod h1:xEzjJPgXI435gkrCt3MPfRiAkVrwSbHsst4LCFVfpJc=
github.com/gaia-pipeline/flag v1.7.4-pre h1:/TAmHVYVQGE4Mw9xl0Qs0D5UruVDMF95thexyEFbTAY=
github.com/gaia-pipeline/flag v1.7.4-pre/go.mod h1:rLpsWzqOEPa2K0Yl4aC34nmblLpIYjGqjP/srZbYvEk=
github.com/gaia-pipeline/gosdk v0.0.0-20180909192508-cc9f89055777 h1:Gn3nmETr4IE44pIFLeTDNNBBRhNXXh53PqFV23CsVok=
github.com/gaia-pipeline/gosdk v0.0.0-20180909192508-cc9f89055777/go.mod h1:e3TkvPdcdSdHZTgwiS89fs8lJrveYHsGLlz/Q0oXlN8=
github.com/gaia-pipeline/protobuf v0.0.0-20180812091451-7be8a901b55a h1:/5XAmdAyGl4yL9BugdPdBLaXquif1zw6Hih6go8E7Xs=
github.com/gaia-pipeline/protobuf v0.0.0-20180812091451-7be8a901b55a/go.mod h1:H0w7MofSuW53Nz7kesnBdVkvr437flf5B7D9Lcsb+lQ=
github.com/gliderlabs/ssh v0.1.1 h1:j3L6gSLQalDETeEg/Jg0mGY0/y/N6zI2xX1978P0Uqw=
Expand Down
74 changes: 71 additions & 3 deletions workers/agent/agent.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ import (
"github.com/gaia-pipeline/gaia/helper/pipelinehelper"
"github.com/gaia-pipeline/gaia/store"
"github.com/gaia-pipeline/gaia/workers/agent/api"
gp "github.com/gaia-pipeline/gaia/workers/pipeline"
pb "github.com/gaia-pipeline/gaia/workers/proto"
"github.com/gaia-pipeline/gaia/workers/scheduler"
"google.golang.org/grpc"
Expand Down Expand Up @@ -454,9 +455,76 @@ func (a *Agent) scheduleWork() {

// Let us try to start the plugin and receive all implemented jobs
if err = a.scheduler.SetPipelineJobs(pipeline); err != nil {
gaia.Cfg.Logger.Error("cannot get pipeline jobs", "error", err.Error(), "pipelinerun", pipelineRunPB)
reschedulePipeline()
return
if strings.Contains(err.Error(), "exec format error") {
gaia.Cfg.Logger.Info("pipeline in a different format than worker; attempting to rebuild...")
err = nil
// Try rebuilding the pipeline...
if err := os.Remove(pipelineFullPath); err != nil {
gaia.Cfg.Logger.Error("failed to remove pipeline binary", "error", err.Error(), "pipelinerun", pipelineRunPB)
reschedulePipeline()
return
}
pCreate := &gaia.CreatePipeline{}
repo, err := a.client.GetGitRepo(ctx, &pb.PipelineID{Id: int64(pipeline.ID)})
if err != nil {
gaia.Cfg.Logger.Error("failed to get pipeline information", "error", err.Error(), "pipelinerun", pipelineRunPB)
reschedulePipeline()
return
}
pCreate.Pipeline = *pipeline
// Unfortunately, since pb.GitRepo has extra gRPC fields on it
// we can't use gaia.GitRepo(repo) here to convert immediately.
gitRepo := gaia.GitRepo{}
gitRepo.Username = repo.Username
gitRepo.Password = repo.Password
pk := gaia.PrivateKey{}
pk.Password = repo.PrivateKey.Password
pk.Username = repo.PrivateKey.Username
pk.Key = repo.PrivateKey.Key
gitRepo.PrivateKey = pk
gitRepo.URL = repo.Url
gitRepo.SelectedBranch = repo.SelectedBranch
pCreate.Pipeline.Repo = &gitRepo
//gp.CreatePipeline(pCreate)
//if pCreate.StatusType == gaia.CreatePipelineFailed {
// gaia.Cfg.Logger.Error("cannot create pipeline", "output", pCreate.Output, "pipelinerun", pipelineRunPB)
// reschedulePipeline()
// return
//}

pb := gp.NewBuildPipeline(pipeline.Type)
if err = pb.PrepareEnvironment(pCreate); err != nil {
gaia.Cfg.Logger.Error("cannot prepare pipeline environment by worker", "error", err.Error(), "pipelinerun", pipelineRunPB)
reschedulePipeline()
return
}
if err = gp.GitCloneRepo(pCreate.Pipeline.Repo); err != nil {
gaia.Cfg.Logger.Error("error pulling repo", "error", err.Error(), "pipelinerun", pipelineRunPB)
reschedulePipeline()
return
}

if err = pb.ExecuteBuild(pCreate); err != nil {
gaia.Cfg.Logger.Error("cannot execute build by worker", "error", err.Error(), "pipelinerun", pipelineRunPB)
reschedulePipeline()
return
}
if err = pb.CopyBinary(pCreate); err != nil {
gaia.Cfg.Logger.Error("cannot copy binary by worker", "error", err.Error(), "pipelinerun", pipelineRunPB)
reschedulePipeline()
return
}
pipeline = &pCreate.Pipeline
if err = a.scheduler.SetPipelineJobs(pipeline); err != nil {
gaia.Cfg.Logger.Error("cannot execute build by worker", "error", err.Error(), "pipelinerun", pipelineRunPB)
reschedulePipeline()
return
}
} else {
gaia.Cfg.Logger.Error("cannot get pipeline jobs", "error", err.Error(), "pipelinerun", pipelineRunPB)
reschedulePipeline()
return
}
}
pipelineRun.Jobs = pipeline.Jobs

Expand Down
4 changes: 4 additions & 0 deletions workers/agent/agent_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,10 @@ type mockWorkerInterface struct {
pbRuns []*pb.PipelineRun
}

func (mw *mockWorkerInterface) GetGitRepo(context.Context, *pb.PipelineID) (*pb.GitRepo, error) {
return &pb.GitRepo{}, nil
}

var mW *mockWorkerInterface

func (mw *mockWorkerInterface) GetWork(workInst *pb.WorkerInstance, serv pb.Worker_GetWorkServer) error {
Expand Down
4 changes: 2 additions & 2 deletions workers/pipeline/create_pipeline.go
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ func CreatePipeline(p *gaia.CreatePipeline) {
p.GitHubToken = ""
storeService, _ := services.StorageService()
// Define build process for the given type
bP := newBuildPipeline(p.Pipeline.Type)
bP := NewBuildPipeline(p.Pipeline.Type)
if bP == nil {
// Pipeline type is not supported
p.StatusType = gaia.CreatePipelineFailed
Expand All @@ -63,7 +63,7 @@ func CreatePipeline(p *gaia.CreatePipeline) {
}

// Clone git repo
err = gitCloneRepo(p.Pipeline.Repo)
err = GitCloneRepo(p.Pipeline.Repo)
if err != nil {
p.StatusType = gaia.CreatePipelineFailed
p.Output = fmt.Sprintf("cannot prepare build: %s", err.Error())
Expand Down
6 changes: 3 additions & 3 deletions workers/pipeline/git.go
Original file line number Diff line number Diff line change
Expand Up @@ -138,7 +138,7 @@ func UpdateRepository(pipe *gaia.Pipeline) error {
}

gaia.Cfg.Logger.Debug("updating pipeline: ", "message", pipe.Name)
b := newBuildPipeline(pipe.Type)
b := NewBuildPipeline(pipe.Type)
createPipeline := &gaia.CreatePipeline{
Pipeline: gaia.Pipeline{
Repo: &gaia.GitRepo{},
Expand All @@ -151,9 +151,9 @@ func UpdateRepository(pipe *gaia.Pipeline) error {
return nil
}

// gitCloneRepo clones the given repo to a local folder.
// GitCloneRepo clones the given repo to a local folder.
// The destination will be attached to the given repo obj.
func gitCloneRepo(repo *gaia.GitRepo) error {
func GitCloneRepo(repo *gaia.GitRepo) error {
// Check if credentials were provided
auth, err := getAuthInfo(repo, nil)
if err != nil {
Expand Down
10 changes: 5 additions & 5 deletions workers/pipeline/git_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ func TestGitCloneRepo(t *testing.T) {
URL: "https://github.com/gaia-pipeline/pipeline-test",
LocalDest: tmp,
}
err := gitCloneRepo(repo)
err := GitCloneRepo(repo)
if err != nil {
t.Fatal(err)
}
Expand Down Expand Up @@ -69,7 +69,7 @@ func TestUpdateAllPipelinesAlreadyUpToDate(t *testing.T) {
}
// always ensure that tmp folder is cleaned up
defer os.RemoveAll("tmp")
err := gitCloneRepo(repo)
err := GitCloneRepo(repo)
if err != nil {
t.Fatal(err)
}
Expand Down Expand Up @@ -125,7 +125,7 @@ Xbs5AQIEIzWnmQIFAOEml+E=

// always ensure that tmp folder is cleaned up
defer os.RemoveAll("tmp")
_ = gitCloneRepo(repo)
_ = GitCloneRepo(repo)
want := "knownhosts: key is unknown"
if !strings.Contains(b.String(), want) {
t.Fatalf("wanted buf to contain: '%s', got: '%s'", want, b.String())
Expand Down Expand Up @@ -170,7 +170,7 @@ Xbs5AQIEIzWnmQIFAOEml+E=

// always ensure that tmp folder is cleaned up
defer os.RemoveAll("tmp")
_ = gitCloneRepo(repo)
_ = GitCloneRepo(repo)

p := new(gaia.Pipeline)
p.Name = "main"
Expand Down Expand Up @@ -209,7 +209,7 @@ func TestUpdateAllPipelinesAlreadyUpToDateWithMoreThanOnePipeline(t *testing.T)
}
// always ensure that tmp folder is cleaned up
defer os.RemoveAll("tmp")
err := gitCloneRepo(repo)
err := GitCloneRepo(repo)
if err != nil {
t.Fatal(err)
}
Expand Down
4 changes: 2 additions & 2 deletions workers/pipeline/pipeline.go
Original file line number Diff line number Diff line change
Expand Up @@ -66,9 +66,9 @@ var execCommandContext = exec.CommandContext
// Source folder name where the sources are stored
const srcFolder = "src"

// newBuildPipeline creates a new build pipeline for the given
// NewBuildPipeline creates a new build pipeline for the given
// pipeline type.
func newBuildPipeline(t gaia.PipelineType) BuildPipeline {
func NewBuildPipeline(t gaia.PipelineType) BuildPipeline {
var bP BuildPipeline

// Create build pipeline for given pipeline type
Expand Down
12 changes: 6 additions & 6 deletions workers/pipeline/pipeline_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -347,27 +347,27 @@ func TestGetExecPath(t *testing.T) {
}

func TestNewBuildPipeline(t *testing.T) {
goBuildPipeline := newBuildPipeline(gaia.PTypeGolang)
goBuildPipeline := NewBuildPipeline(gaia.PTypeGolang)
if goBuildPipeline == nil {
t.Fatalf("should be of type %s but is nil\n", gaia.PTypeGolang)
}
javaBuildPipeline := newBuildPipeline(gaia.PTypeJava)
javaBuildPipeline := NewBuildPipeline(gaia.PTypeJava)
if javaBuildPipeline == nil {
t.Fatalf("should be of type %s but is nil\n", gaia.PTypeJava)
}
pythonBuildPipeline := newBuildPipeline(gaia.PTypePython)
pythonBuildPipeline := NewBuildPipeline(gaia.PTypePython)
if pythonBuildPipeline == nil {
t.Fatalf("should be of type %s but is nil\n", gaia.PTypePython)
}
cppBuildPipeline := newBuildPipeline(gaia.PTypeCpp)
cppBuildPipeline := NewBuildPipeline(gaia.PTypeCpp)
if cppBuildPipeline == nil {
t.Fatalf("should be of type %s but is nil\n", gaia.PTypeCpp)
}
rubyBuildPipeline := newBuildPipeline(gaia.PTypeRuby)
rubyBuildPipeline := NewBuildPipeline(gaia.PTypeRuby)
if rubyBuildPipeline == nil {
t.Fatalf("should be of type %s but is nil\n", gaia.PTypeRuby)
}
nodeJSBuildPipeline := newBuildPipeline(gaia.PTypeNodeJS)
nodeJSBuildPipeline := NewBuildPipeline(gaia.PTypeNodeJS)
if nodeJSBuildPipeline == nil {
t.Fatalf("should be of type %s but is nil\n", gaia.PTypeNodeJS)
}
Expand Down
Loading