Skip to content

Commit

Permalink
Prepared gaia for first release and added new steps to make file
Browse files Browse the repository at this point in the history
  • Loading branch information
michelvocks committed Jun 26, 2018
1 parent aa5131b commit 77d69a9
Show file tree
Hide file tree
Showing 9 changed files with 62 additions and 15 deletions.
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@
*.so
*.dylib
*.db
rice-box.go
gaia-linux-amd64

# Test binary, build with `go test -c`
*.test
Expand Down
23 changes: 18 additions & 5 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,7 +1,20 @@
default: run
default: dev

build: ./cmd/gaia/main.go
go install ./cmd/gaia/
dev:
go run ./cmd/gaia/main.go -homepath=${PWD}/tmp -dev true

run: build
gaia -homepath=${PWD}/tmp
compile_frontend:
cd ./frontend && \
rm -rf dist && \
npm install && \
npm run build

static_assets:
go get github.com/GeertJohan/go.rice && \
go get github.com/GeertJohan/go.rice/rice && \
cd ./handlers && \
rm -f rice-box.go && \
rice embed-go

release: compile_frontend static_assets
env GOOS=linux GOARCH=amd64 go build -o gaia-linux-amd64 ./cmd/gaia/main.go
12 changes: 12 additions & 0 deletions cmd/gaia/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package main

import (
"flag"
"fmt"
"os"
"path/filepath"

Expand All @@ -19,6 +20,9 @@ var (
)

const (
// Version is the current version of gaia.
Version = "0.1.1"

dataFolder = "data"
pipelinesFolder = "pipelines"
workspaceFolder = "workspace"
Expand All @@ -31,6 +35,8 @@ func init() {
flag.StringVar(&gaia.Cfg.ListenPort, "port", "8080", "Listen port for gaia")
flag.StringVar(&gaia.Cfg.HomePath, "homepath", "", "Path to the gaia home folder")
flag.IntVar(&gaia.Cfg.Workers, "workers", 2, "Number of workers gaia will use to execute pipelines in parallel")
flag.BoolVar(&gaia.Cfg.DevMode, "dev", false, "If true, gaia will be started in development mode. Don't use this in production!")
flag.BoolVar(&gaia.Cfg.VersionSwitch, "version", false, "If true, will print the version and immediately exit")

// Default values
gaia.Cfg.Bolt.Mode = 0600
Expand All @@ -40,6 +46,12 @@ func main() {
// Parse command line flgs
flag.Parse()

// Check version switch
if gaia.Cfg.VersionSwitch {
fmt.Printf("Gaia Version: V%s\n", Version)
os.Exit(0)
}

// Initialize shared logger
gaia.Cfg.Logger = hclog.New(&hclog.LoggerOptions{
Level: hclog.Trace,
Expand Down
2 changes: 1 addition & 1 deletion frontend/build/webpack.dev.conf.js
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ module.exports = merge(baseWebpackConfig, {
filename: 'index.html',
template: 'index.html',
inject: true,
favicon: 'client/assets/logo.png'
favicon: 'client/assets/favicon.ico'
})
]
})
2 changes: 1 addition & 1 deletion frontend/build/webpack.prod.conf.js
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ const webpackConfig = merge(baseWebpackConfig, {
: config.build.index,
template: 'index.html',
inject: true,
favicon: 'client/assets/logo.png',
favicon: 'client/assets/favicon.ico',
minify: {
removeComments: true,
collapseWhitespace: true,
Expand Down
Binary file added frontend/client/assets/favicon.ico
Binary file not shown.
2 changes: 2 additions & 0 deletions gaia.go
Original file line number Diff line number Diff line change
Expand Up @@ -145,6 +145,8 @@ var Cfg *Config

// Config holds all config options
type Config struct {
DevMode bool
VersionSwitch bool
ListenPort string
HomePath string
DataPath string
Expand Down
7 changes: 2 additions & 5 deletions handlers/User.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,11 +30,8 @@ func UserLogin(c echo.Context) error {

// Authenticate user
user, err := storeService.UserAuth(u, true)
if err != nil {
gaia.Cfg.Logger.Error("error during UserAuth", "error", err.Error())
return c.String(http.StatusInternalServerError, err.Error())
}
if user == nil {
if err != nil || user == nil {
gaia.Cfg.Logger.Error("invalid credentials provided", "message", err.Error())
return c.String(http.StatusForbidden, "invalid username and/or password")
}

Expand Down
27 changes: 24 additions & 3 deletions handlers/handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,10 @@ import (
"net/http"
"strings"

"github.com/GeertJohan/go.rice"

jwt "github.com/dgrijalva/jwt-go"
"github.com/gaia-pipeline/gaia"
scheduler "github.com/gaia-pipeline/gaia/scheduler"
"github.com/gaia-pipeline/gaia/store"
"github.com/labstack/echo"
Expand Down Expand Up @@ -64,7 +67,7 @@ func InitHandlers(e *echo.Echo, store *store.Store, scheduler *scheduler.Schedul
// Define prefix
p := "/api/" + apiVersion + "/"

// --- Register handlers at iris instance ---
// --- Register handlers at echo instance ---

// Users
e.POST(p+"login", UserLogin)
Expand Down Expand Up @@ -98,6 +101,24 @@ func InitHandlers(e *echo.Echo, store *store.Store, scheduler *scheduler.Schedul
// Extra options
e.HideBanner = true

// Are we in production mode?
if !gaia.Cfg.DevMode {
staticAssets, err := rice.FindBox("../frontend/dist")
if err != nil {
gaia.Cfg.Logger.Error("Cannot find assets in production mode.")
return err
}

// Register handler for static assets
assetHandler := http.FileServer(staticAssets.HTTPBox())
e.GET("/", echo.WrapHandler(assetHandler))
e.GET("/favicon.ico", echo.WrapHandler(assetHandler))
e.GET("/assets/css/*", echo.WrapHandler(http.StripPrefix("/", assetHandler)))
e.GET("/assets/js/*", echo.WrapHandler(http.StripPrefix("/", assetHandler)))
e.GET("/assets/fonts/*", echo.WrapHandler(http.StripPrefix("/", assetHandler)))
e.GET("/assets/img/*", echo.WrapHandler(http.StripPrefix("/", assetHandler)))
}

return nil
}

Expand All @@ -106,8 +127,8 @@ func InitHandlers(e *echo.Echo, store *store.Store, scheduler *scheduler.Schedul
// TODO: Role based access
func authBarrier(next echo.HandlerFunc) echo.HandlerFunc {
return func(c echo.Context) error {
// Login resource is open
if strings.Contains(c.Path(), "login") {
// Login and static resources are open
if strings.Contains(c.Path(), "/login") || c.Path() == "/" || strings.Contains(c.Path(), "/assets/") || c.Path() == "/favicon.ico" {
return next(c)
}

Expand Down

0 comments on commit 77d69a9

Please sign in to comment.