Skip to content

Commit

Permalink
Repository checkout works now fully with the correct path. UI is auto…
Browse files Browse the repository at this point in the history
…matically updated with progress.
  • Loading branch information
michelvocks committed Mar 6, 2018
1 parent 76a072a commit 48f9525
Show file tree
Hide file tree
Showing 12 changed files with 234 additions and 68 deletions.
4 changes: 2 additions & 2 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -25,5 +25,5 @@ selenium-debug.log
test/unit/coverage
test/e2e/reports

# data folder generated by gaia
data/
# home folder generated by gaia during local test
tmp/
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,4 @@ build: ./cmd/gaia/main.go
go install ./cmd/gaia/

run: build
gaia
gaia -homepath=${PWD}/tmp
46 changes: 34 additions & 12 deletions cmd/gaia/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package main
import (
"flag"
"os"
"path/filepath"

"github.com/gaia-pipeline/gaia"
"github.com/gaia-pipeline/gaia/handlers"
Expand All @@ -12,51 +13,72 @@ import (
)

var (
cfg *gaia.Config
irisInstance *iris.Application
)

func init() {
cfg = &gaia.Config{}
gaia.Cfg = &gaia.Config{}

// command line arguments
flag.StringVar(&cfg.ListenPort, "port", "8080", "Listen port for gaia")
flag.StringVar(&cfg.DataPath, "datapath", "data", "Path to the data folder")
flag.StringVar(&cfg.Bolt.Path, "dbpath", "gaia.db", "Path to gaia bolt db file")
flag.StringVar(&gaia.Cfg.ListenPort, "port", "8080", "Listen port for gaia")
flag.StringVar(&gaia.Cfg.HomePath, "homepath", "", "Path to the gaia home folder")
flag.StringVar(&gaia.Cfg.Bolt.Path, "dbpath", "gaia.db", "Path to gaia bolt db file")

// Default values
cfg.Bolt.Mode = 0600
gaia.Cfg.Bolt.Mode = 0600
}

func main() {
// Parse command line flgs
flag.Parse()

// Initialize shared logger
cfg.Logger = hclog.New(&hclog.LoggerOptions{
gaia.Cfg.Logger = hclog.New(&hclog.LoggerOptions{
Level: hclog.Trace,
Output: hclog.DefaultOutput,
Name: "Gaia",
})

// Find path for gaia home folder if not given by parameter
if gaia.Cfg.HomePath == "" {
// Find executeable path
execPath, err := findExecuteablePath()
if err != nil {
gaia.Cfg.Logger.Error("cannot find executeable path", "error", err.Error())
os.Exit(1)
}
gaia.Cfg.HomePath = execPath
gaia.Cfg.Logger.Debug("executeable path found", "path", execPath)
}

// Initialize IRIS
irisInstance = iris.New()

// Initialize store
s := store.NewStore()
err := s.Init(cfg)
err := s.Init()
if err != nil {
cfg.Logger.Error("cannot initialize store", "error", err.Error())
gaia.Cfg.Logger.Error("cannot initialize store", "error", err.Error())
os.Exit(1)
}

// Initialize handlers
err = handlers.InitHandlers(cfg, irisInstance, s)
err = handlers.InitHandlers(irisInstance, s)
if err != nil {
cfg.Logger.Error("cannot initialize handlers", "error", err.Error())
gaia.Cfg.Logger.Error("cannot initialize handlers", "error", err.Error())
os.Exit(1)
}

// Start listen
irisInstance.Run(iris.Addr(":" + cfg.ListenPort))
irisInstance.Run(iris.Addr(":" + gaia.Cfg.ListenPort))
}

// findExecuteablePath returns the absolute path for the current
// process.
func findExecuteablePath() (string, error) {
ex, err := os.Executable()
if err != nil {
return "", err
}
return filepath.Dir(ex), nil
}
4 changes: 2 additions & 2 deletions frontend/client/views/pipelines/create.vue
Original file line number Diff line number Diff line change
Expand Up @@ -98,11 +98,11 @@
</tr>
</thead>
<tbody>
<tr class="blink" v-for="pipeline in createdPipelines" :key="pipeline">
<tr v-bind:class="{ blink: pipeline.status < 100 }" v-for="(pipeline, index) in createdPipelines" :key="index">
<td>
{{ pipeline.pipelinename }}
</td>
<td class="th">
<td>
<div v-if="pipeline.status < 100">
<progress-bar :type="'info'" :size="'small'" :value="pipeline.status" :max="100" :show-label="false"></progress-bar>
</div>
Expand Down
23 changes: 13 additions & 10 deletions gaia.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,12 @@ import (
hclog "github.com/hashicorp/go-hclog"
)

// PluginType represents supported plugin types
type PluginType string
// PipelineType represents supported plugin types
type PipelineType string

const (
// GOLANG plugin type
GOLANG PluginType = "golang"
GOLANG PipelineType = "golang"
)

// User is the user object
Expand All @@ -26,12 +26,12 @@ type User struct {

// Pipeline represents a single pipeline
type Pipeline struct {
Name string `json:"pipelinename"`
Repo GitRepo `json:"gitrepo"`
Type PluginType `json:"pipelinetype"`
Status int `json:"status"`
ErrMsg string `json:"errmsg"`
CreationDate time.Time `json:"creationdate"`
Name string `json:"pipelinename"`
Repo GitRepo `json:"gitrepo"`
Type PipelineType `json:"pipelinetype"`
Status int `json:"status"`
ErrMsg string `json:"errmsg"`
CreationDate time.Time `json:"creationdate"`
}

// GitRepo represents a single git repository
Expand All @@ -52,10 +52,13 @@ type PrivateKey struct {
Password string `json:"password"`
}

// Cfg represents the global config instance
var Cfg *Config

// Config holds all config options
type Config struct {
ListenPort string
DataPath string
HomePath string
Logger hclog.Logger

Bolt struct {
Expand Down
6 changes: 3 additions & 3 deletions handlers/User.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,14 +24,14 @@ func UserLogin(ctx iris.Context) {
if err := ctx.ReadJSON(u); err != nil {
ctx.StatusCode(iris.StatusBadRequest)
ctx.WriteString(err.Error())
cfg.Logger.Debug("error reading json during UserLogin", "error", err.Error())
gaia.Cfg.Logger.Debug("error reading json during UserLogin", "error", err.Error())
return
}

// Authenticate user
user, err := storeService.UserAuth(u)
if err != nil {
cfg.Logger.Error("error during UserAuth", "error", err.Error())
gaia.Cfg.Logger.Error("error during UserAuth", "error", err.Error())
ctx.StatusCode(iris.StatusInternalServerError)
return
}
Expand All @@ -58,7 +58,7 @@ func UserLogin(ctx iris.Context) {
tokenstring, err := token.SignedString(jwtKey)
if err != nil {
ctx.StatusCode(iris.StatusInternalServerError)
cfg.Logger.Error("error signing jwt token", "error", err.Error())
gaia.Cfg.Logger.Error("error signing jwt token", "error", err.Error())
return
}
user.JwtExpiry = claims.ExpiresAt
Expand Down
9 changes: 1 addition & 8 deletions handlers/handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ package handlers
import (
"crypto/rand"

"github.com/gaia-pipeline/gaia"
"github.com/gaia-pipeline/gaia/store"
"github.com/kataras/iris"
)
Expand All @@ -16,17 +15,11 @@ const (
// Use this to talk to the store.
var storeService *store.Store

// cfg is a pointer to the global config
var cfg *gaia.Config

// jwtKey is a random generated key for jwt signing
var jwtKey []byte

// InitHandlers initializes(registers) all handlers
func InitHandlers(c *gaia.Config, i *iris.Application, s *store.Store) error {
// Set config
cfg = c

func InitHandlers(i *iris.Application, s *store.Store) error {
// Set store instance
storeService = s

Expand Down
60 changes: 49 additions & 11 deletions handlers/pipeline.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,9 @@ const (
// Percent of pipeline creation progress after git clone
pipelineCloneStatus = 25

// Percent of pipeline creation progress after compile process done
pipelineCompileStatus = 75

// Completed percent progress
pipelineCompleteStatus = 100
)
Expand Down Expand Up @@ -65,7 +68,7 @@ func PipelineBuildFromSource(ctx iris.Context) {
if err != nil {
ctx.StatusCode(iris.StatusInternalServerError)
ctx.WriteString(err.Error())
cfg.Logger.Debug("cannot put pipeline into store", "error", err.Error())
gaia.Cfg.Logger.Debug("cannot put pipeline into store", "error", err.Error())
return
}

Expand All @@ -77,37 +80,72 @@ func PipelineBuildFromSource(ctx iris.Context) {
// the pipeline. After every step, the status will be store.
// This method is designed to be called async.
func createPipelineExecute(p *gaia.Pipeline) {
// Define build process for the given type
bP := pipeline.NewBuildPipeline(p.Type)
if bP == nil {
// Pipeline type is not supported
gaia.Cfg.Logger.Debug("create pipeline failed. Pipeline type is not supported", "type", p.Type)
return
}

// Setup environment before cloning repo and command
cmd, err := bP.PrepareBuild(p)
if err != nil {
gaia.Cfg.Logger.Error("cannot prepare build", "error", err.Error())
return
}

// Clone git repo
err := pipeline.GitCloneRepo(&p.Repo)
err = pipeline.GitCloneRepo(&p.Repo)
if err != nil {
// Add error message and store
p.ErrMsg = err.Error()
storeService.CreatePipelinePut(p)
cfg.Logger.Debug("cannot clone repo", "error", err.Error())
gaia.Cfg.Logger.Debug("cannot clone repo", "error", err.Error())
return
}

// Update status of our pipeline build
p.Status = pipelineCloneStatus
err = storeService.CreatePipelinePut(p)
if err != nil {
cfg.Logger.Error("cannot put create pipeline into store", "error", err.Error())
gaia.Cfg.Logger.Error("cannot put create pipeline into store", "error", err.Error())
return
}

// Start compiling process for given plugin type
switch p.Type {
case gaia.GOLANG:
// Start compile process for golang TODO
// Run compile process
err = bP.ExecuteBuild(cmd)
if err != nil {
// Add error message and store
p.ErrMsg = err.Error()
storeService.CreatePipelinePut(p)
gaia.Cfg.Logger.Debug("cannot compile pipeline", "error", err.Error())
return
}

// copy compiled binary to plugins folder
// Update status of our pipeline build
p.Status = pipelineCompileStatus
err = storeService.CreatePipelinePut(p)
if err != nil {
gaia.Cfg.Logger.Error("cannot put create pipeline into store", "error", err.Error())
return
}

// Copy compiled binary to plugins folder
err = bP.CopyBinary(p)
if err != nil {
// Add error message and store
p.ErrMsg = err.Error()
storeService.CreatePipelinePut(p)
gaia.Cfg.Logger.Debug("cannot copy compiled binary", "error", err.Error())
return
}

// Set create pipeline status to complete
p.Status = pipelineCompleteStatus
err = storeService.CreatePipelinePut(p)
if err != nil {
cfg.Logger.Error("cannot put create pipeline into store", "error", err.Error())
gaia.Cfg.Logger.Error("cannot put create pipeline into store", "error", err.Error())
return
}
}
Expand All @@ -121,7 +159,7 @@ func CreatePipelineGetAll(ctx iris.Context) {
if err != nil {
ctx.StatusCode(iris.StatusInternalServerError)
ctx.WriteString(err.Error())
cfg.Logger.Debug("cannot get create pipelines from store", "error", err.Error())
gaia.Cfg.Logger.Debug("cannot get create pipelines from store", "error", err.Error())
return
}

Expand Down
Loading

0 comments on commit 48f9525

Please sign in to comment.