Skip to content

Commit e595f9e

Browse files
committed
Working polling system with building all pipelines.
1 parent bc40872 commit e595f9e

File tree

7 files changed

+34
-17
lines changed

7 files changed

+34
-17
lines changed

Makefile

+1-1
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ GO_LDFLAGS_STATIC=-ldflags "-s -w -extldflags -static"
44
default: dev
55

66
dev:
7-
go run ./cmd/gaia/main.go -homepath=${PWD}/tmp -dev true
7+
go run ./cmd/gaia/main.go -homepath=${PWD}/tmp -dev=true -poll=true
88

99
compile_frontend:
1010
cd ./frontend && \

cmd/gaia/main.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ func init() {
3737
flag.StringVar(&gaia.Cfg.Worker, "worker", "2", "Number of worker gaia will use to execute pipelines in parallel")
3838
flag.BoolVar(&gaia.Cfg.DevMode, "dev", false, "If true, gaia will be started in development mode. Don't use this in production!")
3939
flag.BoolVar(&gaia.Cfg.VersionSwitch, "version", false, "If true, will print the version and immediately exit")
40-
40+
flag.BoolVar(&gaia.Cfg.Poll, "poll", false, "Instead of using a Webhook, keep polling git for changes on pipelines")
4141
// Default values
4242
gaia.Cfg.Bolt.Mode = 0600
4343
}

gaia.go

+1
Original file line numberDiff line numberDiff line change
@@ -148,6 +148,7 @@ var Cfg *Config
148148
type Config struct {
149149
DevMode bool
150150
VersionSwitch bool
151+
Poll bool
151152
ListenPort string
152153
HomePath string
153154
DataPath string

pipeline/build_golang.go

+7-1
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ func (b *BuildPipelineGolang) PrepareEnvironment(p *gaia.CreatePipeline) error {
4141
// Set new generated path in pipeline obj for later usage
4242
p.Pipeline.Repo.LocalDest = cloneFolder
4343
p.Pipeline.UUID = uuid.String()
44-
return nil
44+
return err
4545
}
4646

4747
// ExecuteBuild executes the golang build process
@@ -116,6 +116,12 @@ func (b *BuildPipelineGolang) CopyBinary(p *gaia.CreatePipeline) error {
116116
return err
117117
}
118118

119+
p.Pipeline.ExecPath = dest
120+
// Our pipeline is finished constructing. Save it.
121+
if err := storeService.PipelinePut(&p.Pipeline); err != nil {
122+
return err
123+
}
124+
119125
// Set +x (execution right) for pipeline
120126
return os.Chmod(dest, 0766)
121127
}

pipeline/build_golang_test.go

+6
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,8 @@ import (
1212
"strings"
1313
"testing"
1414

15+
"github.com/gaia-pipeline/gaia/store"
16+
1517
"github.com/gaia-pipeline/gaia"
1618
hclog "github.com/hashicorp/go-hclog"
1719
)
@@ -181,6 +183,10 @@ func TestExecuteBuildBinaryNotFoundError(t *testing.T) {
181183
}
182184

183185
func TestCopyBinary(t *testing.T) {
186+
s := store.NewStore()
187+
s.Init()
188+
storeService = s
189+
defer os.Remove("gaia.db")
184190
tmp := os.TempDir()
185191
gaia.Cfg = new(gaia.Config)
186192
gaia.Cfg.HomePath = tmp

pipeline/git.go

+3-5
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
package pipeline
22

33
import (
4-
"path/filepath"
54
"strings"
65
"sync"
76

@@ -117,16 +116,15 @@ func updateAllCurrentPipelines() {
117116
for pipeline := range GlobalActivePipelines.Iter() {
118117
allPipelines = append(allPipelines, pipeline)
119118
}
120-
goPath := filepath.Join(gaia.Cfg.HomePath, tmpFolder, golangFolder)
121119
for _, p := range allPipelines {
122120
wg.Add(1)
123121
go func(pipe gaia.Pipeline) {
124122
defer wg.Done()
125123
sem <- 1
126-
cloneFolder := filepath.Join(goPath, srcFolder, pipe.UUID)
127-
r, err := git.PlainOpen(cloneFolder)
124+
r, err := git.PlainOpen(pipe.Repo.LocalDest)
128125
if err != nil {
129-
// ignore for now
126+
// It's also an error if the repo is already up to date so we just move on.
127+
gaia.Cfg.Logger.Debug("error while opening repo: ", pipe.Repo.LocalDest, err.Error())
130128
return
131129
}
132130
beforPull, _ := r.Head()

pipeline/ticker.go

+15-9
Original file line numberDiff line numberDiff line change
@@ -54,16 +54,22 @@ func InitTicker(store *store.Store, scheduler *scheduler.Scheduler) {
5454
}
5555
}()
5656

57-
pollTicket := time.NewTicker(pollTicketIntervalMinutes * time.Minute)
58-
go func() {
59-
defer pollTicket.Stop()
60-
for {
61-
select {
62-
case <-pollTicket.C:
63-
updateAllCurrentPipelines()
57+
if gaia.Cfg.Poll {
58+
pollTicket := time.NewTicker(pollTicketIntervalMinutes * time.Minute)
59+
go func() {
60+
defer pollTicket.Stop()
61+
for {
62+
select {
63+
case <-pollTicket.C:
64+
updateAllCurrentPipelines()
65+
}
6466
}
65-
}
66-
}()
67+
}()
68+
} else {
69+
gaia.Cfg.Logger.Debug("webhooks enabled")
70+
// WebHook needs to be an option on the UI for
71+
// a registered repository. If polling is on, that checkbox needs to be disabled.
72+
}
6773
}
6874

6975
// checkActivePipelines looks up all files in the pipeline folder.

0 commit comments

Comments
 (0)