Skip to content

Commit 77d69a9

Browse files
committed
Prepared gaia for first release and added new steps to make file
1 parent aa5131b commit 77d69a9

File tree

9 files changed

+62
-15
lines changed

9 files changed

+62
-15
lines changed

.gitignore

+2
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@
44
*.so
55
*.dylib
66
*.db
7+
rice-box.go
8+
gaia-linux-amd64
79

810
# Test binary, build with `go test -c`
911
*.test

Makefile

+18-5
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,20 @@
1-
default: run
1+
default: dev
22

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

6-
run: build
7-
gaia -homepath=${PWD}/tmp
6+
compile_frontend:
7+
cd ./frontend && \
8+
rm -rf dist && \
9+
npm install && \
10+
npm run build
11+
12+
static_assets:
13+
go get github.com/GeertJohan/go.rice && \
14+
go get github.com/GeertJohan/go.rice/rice && \
15+
cd ./handlers && \
16+
rm -f rice-box.go && \
17+
rice embed-go
18+
19+
release: compile_frontend static_assets
20+
env GOOS=linux GOARCH=amd64 go build -o gaia-linux-amd64 ./cmd/gaia/main.go

cmd/gaia/main.go

+12
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ package main
22

33
import (
44
"flag"
5+
"fmt"
56
"os"
67
"path/filepath"
78

@@ -19,6 +20,9 @@ var (
1920
)
2021

2122
const (
23+
// Version is the current version of gaia.
24+
Version = "0.1.1"
25+
2226
dataFolder = "data"
2327
pipelinesFolder = "pipelines"
2428
workspaceFolder = "workspace"
@@ -31,6 +35,8 @@ func init() {
3135
flag.StringVar(&gaia.Cfg.ListenPort, "port", "8080", "Listen port for gaia")
3236
flag.StringVar(&gaia.Cfg.HomePath, "homepath", "", "Path to the gaia home folder")
3337
flag.IntVar(&gaia.Cfg.Workers, "workers", 2, "Number of workers gaia will use to execute pipelines in parallel")
38+
flag.BoolVar(&gaia.Cfg.DevMode, "dev", false, "If true, gaia will be started in development mode. Don't use this in production!")
39+
flag.BoolVar(&gaia.Cfg.VersionSwitch, "version", false, "If true, will print the version and immediately exit")
3440

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

49+
// Check version switch
50+
if gaia.Cfg.VersionSwitch {
51+
fmt.Printf("Gaia Version: V%s\n", Version)
52+
os.Exit(0)
53+
}
54+
4355
// Initialize shared logger
4456
gaia.Cfg.Logger = hclog.New(&hclog.LoggerOptions{
4557
Level: hclog.Trace,

frontend/build/webpack.dev.conf.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ module.exports = merge(baseWebpackConfig, {
3636
filename: 'index.html',
3737
template: 'index.html',
3838
inject: true,
39-
favicon: 'client/assets/logo.png'
39+
favicon: 'client/assets/favicon.ico'
4040
})
4141
]
4242
})

frontend/build/webpack.prod.conf.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ const webpackConfig = merge(baseWebpackConfig, {
5757
: config.build.index,
5858
template: 'index.html',
5959
inject: true,
60-
favicon: 'client/assets/logo.png',
60+
favicon: 'client/assets/favicon.ico',
6161
minify: {
6262
removeComments: true,
6363
collapseWhitespace: true,

frontend/client/assets/favicon.ico

14.7 KB
Binary file not shown.

gaia.go

+2
Original file line numberDiff line numberDiff line change
@@ -145,6 +145,8 @@ var Cfg *Config
145145

146146
// Config holds all config options
147147
type Config struct {
148+
DevMode bool
149+
VersionSwitch bool
148150
ListenPort string
149151
HomePath string
150152
DataPath string

handlers/User.go

+2-5
Original file line numberDiff line numberDiff line change
@@ -30,11 +30,8 @@ func UserLogin(c echo.Context) error {
3030

3131
// Authenticate user
3232
user, err := storeService.UserAuth(u, true)
33-
if err != nil {
34-
gaia.Cfg.Logger.Error("error during UserAuth", "error", err.Error())
35-
return c.String(http.StatusInternalServerError, err.Error())
36-
}
37-
if user == nil {
33+
if err != nil || user == nil {
34+
gaia.Cfg.Logger.Error("invalid credentials provided", "message", err.Error())
3835
return c.String(http.StatusForbidden, "invalid username and/or password")
3936
}
4037

handlers/handler.go

+24-3
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,10 @@ import (
77
"net/http"
88
"strings"
99

10+
"github.com/GeertJohan/go.rice"
11+
1012
jwt "github.com/dgrijalva/jwt-go"
13+
"github.com/gaia-pipeline/gaia"
1114
scheduler "github.com/gaia-pipeline/gaia/scheduler"
1215
"github.com/gaia-pipeline/gaia/store"
1316
"github.com/labstack/echo"
@@ -64,7 +67,7 @@ func InitHandlers(e *echo.Echo, store *store.Store, scheduler *scheduler.Schedul
6467
// Define prefix
6568
p := "/api/" + apiVersion + "/"
6669

67-
// --- Register handlers at iris instance ---
70+
// --- Register handlers at echo instance ---
6871

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

104+
// Are we in production mode?
105+
if !gaia.Cfg.DevMode {
106+
staticAssets, err := rice.FindBox("../frontend/dist")
107+
if err != nil {
108+
gaia.Cfg.Logger.Error("Cannot find assets in production mode.")
109+
return err
110+
}
111+
112+
// Register handler for static assets
113+
assetHandler := http.FileServer(staticAssets.HTTPBox())
114+
e.GET("/", echo.WrapHandler(assetHandler))
115+
e.GET("/favicon.ico", echo.WrapHandler(assetHandler))
116+
e.GET("/assets/css/*", echo.WrapHandler(http.StripPrefix("/", assetHandler)))
117+
e.GET("/assets/js/*", echo.WrapHandler(http.StripPrefix("/", assetHandler)))
118+
e.GET("/assets/fonts/*", echo.WrapHandler(http.StripPrefix("/", assetHandler)))
119+
e.GET("/assets/img/*", echo.WrapHandler(http.StripPrefix("/", assetHandler)))
120+
}
121+
101122
return nil
102123
}
103124

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

0 commit comments

Comments
 (0)