Skip to content

Commit

Permalink
load from .env - view updates - enable CDN
Browse files Browse the repository at this point in the history
  • Loading branch information
hunterlong committed Jul 7, 2018
1 parent 5f2037a commit 3cc63a0
Show file tree
Hide file tree
Showing 21 changed files with 328 additions and 42 deletions.
2 changes: 1 addition & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ services:

env:
global:
- VERSION=0.29.6
- VERSION=0.29.7
- DB_HOST=localhost
- DB_USER=travis
- DB_PASS=
Expand Down
2 changes: 1 addition & 1 deletion Dockerfile
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
FROM alpine:latest

ENV VERSION=v0.29.6
ENV VERSION=v0.29.7

RUN apk --no-cache add libstdc++ ca-certificates
RUN wget -q https://github.com/hunterlong/statup/releases/download/$VERSION/statup-linux-alpine.tar.gz && \
Expand Down
63 changes: 50 additions & 13 deletions core/configs.go
Original file line number Diff line number Diff line change
@@ -1,25 +1,62 @@
package core

import (
"errors"
"github.com/go-yaml/yaml"
"github.com/hunterlong/statup/types"
"io/ioutil"
"os"
)

type Config types.Config

var (
VERSION string
)

func LoadConfig() (*Config, error) {
var config *Config
func LoadConfig() (*types.Config, error) {
if os.Getenv("DB_CONN") != "" {
return LoadUsingEnv()
}
Configs = new(types.Config)
file, err := ioutil.ReadFile("config.yml")
if err != nil {
return nil, err
return nil, errors.New("config.yml file not found - starting in setup mode")
}
err = yaml.Unmarshal(file, &Configs)
CoreApp.DbConnection = Configs.Connection
return Configs, err
}

func LoadUsingEnv() (*types.Config, error) {
Configs = new(types.Config)
if os.Getenv("DB_CONN") == "" {
return nil, errors.New("Missing DB_CONN environment variable")
}
if os.Getenv("DB_HOST") == "" {
return nil, errors.New("Missing DB_HOST environment variable")
}
if os.Getenv("DB_USER") == "" {
return nil, errors.New("Missing DB_USER environment variable")
}
if os.Getenv("DB_PASS") == "" {
return nil, errors.New("Missing DB_PASS environment variable")
}
if os.Getenv("DB_DATABASE") == "" {
return nil, errors.New("Missing DB_DATABASE environment variable")
}
Configs.Connection = os.Getenv("DB_CONN")
Configs.Host = os.Getenv("DB_HOST")
Configs.Port = os.Getenv("DB_PORT")
Configs.User = os.Getenv("DB_USER")
Configs.Password = os.Getenv("DB_PASS")
Configs.Database = os.Getenv("DB_DATABASE")
CoreApp.DbConnection = os.Getenv("DB_CONN")
CoreApp.Name = os.Getenv("NAME")
CoreApp.Domain = os.Getenv("DOMAIN")
if os.Getenv("USE_CDN") == "true" {
CoreApp.UseCdn = true
}
return Configs, nil
}

func ifOr(val, def string) string {
if val == "" {
return def
}
err = yaml.Unmarshal(file, &config)
Configs = config
CoreApp.DbConnection = config.Connection
return config, err
return val
}
12 changes: 10 additions & 2 deletions core/core.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@ import (
"github.com/GeertJohan/go.rice"
"github.com/hunterlong/statup/plugin"
"github.com/hunterlong/statup/types"
"github.com/pkg/errors"
"os"
"time"
)

Expand All @@ -27,13 +29,12 @@ type Core struct {
Repos []PluginJSON
AllPlugins []plugin.PluginActions
Communications []*types.Communication
OfflineAssets bool
DbConnection string
started time.Time
}

var (
Configs *Config
Configs *types.Config
CoreApp *Core
SqlBox *rice.Box
CssBox *rice.Box
Expand All @@ -43,6 +44,7 @@ var (
EmailBox *rice.Box
SetupMode bool
UsingAssets bool
VERSION string
)

func init() {
Expand Down Expand Up @@ -107,6 +109,9 @@ func (c Core) AllOnline() bool {

func SelectLastMigration() (int64, error) {
var c *Core
if DbSession == nil {
return 0, errors.New("Database connection has not been created yet")
}
err := DbSession.Collection("core").Find().One(&c)
if err != nil {
return 0, err
Expand All @@ -124,6 +129,9 @@ func SelectCore() (*Core, error) {
CoreApp.DbConnection = Configs.Connection
CoreApp.Version = VERSION
CoreApp.Services, _ = SelectAllServices()
if os.Getenv("USE_CDN") == "true" {
CoreApp.UseCdn = true
}
//store = sessions.NewCookieStore([]byte(core.ApiSecret))
return CoreApp, err
}
3 changes: 3 additions & 0 deletions core/database.go
Original file line number Diff line number Diff line change
Expand Up @@ -157,6 +157,9 @@ func reverseSlice(s []string) []string {
func RunDatabaseUpgrades() error {
var err error
currentMigration, err = SelectLastMigration()
if err != nil {
return err
}
utils.Log(1, fmt.Sprintf("Checking for Database Upgrades since #%v", currentMigration))
upgrade, _ := SqlBox.String(CoreApp.DbConnection + "_upgrade.sql")
// parse db version and upgrade file
Expand Down
2 changes: 1 addition & 1 deletion core/export.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import (
)

func ExportIndexHTML() string {
CoreApp.OfflineAssets = true
CoreApp.UseCdn = true
//out := index{*CoreApp, CoreApp.Services}
nav, _ := TmplBox.String("nav.html")
footer, _ := TmplBox.String("footer.html")
Expand Down
3 changes: 3 additions & 0 deletions handlers/handlers.go
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,9 @@ func ExecuteResponse(w http.ResponseWriter, r *http.Request, file string, data i
"VERSION": func() string {
return core.VERSION
},
"USE_CDN": func() bool {
return core.CoreApp.UseCdn
},
"underscore": func(html string) string {
return utils.UnderScoreString(html)
},
Expand Down
1 change: 1 addition & 0 deletions handlers/routes.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ func Router() *mux.Router {
r.Handle("/service/{id}/delete_failures", http.HandlerFunc(ServicesDeleteFailuresHandler)).Methods("GET")
r.Handle("/service/{id}/checkin", http.HandlerFunc(CheckinCreateUpdateHandler)).Methods("POST")
r.Handle("/users", http.HandlerFunc(UsersHandler)).Methods("GET")
r.Handle("/user/{id}", http.HandlerFunc(UsersHandler)).Methods("GET")
r.Handle("/users", http.HandlerFunc(CreateUserHandler)).Methods("POST")
r.Handle("/users/{id}/delete", http.HandlerFunc(UsersDeleteHandler)).Methods("GET")
r.Handle("/settings", http.HandlerFunc(PluginsHandler)).Methods("GET")
Expand Down
1 change: 1 addition & 0 deletions handlers/settings.go
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@ func SaveSettingsHandler(w http.ResponseWriter, r *http.Request) {
if domain != core.CoreApp.Domain {
core.CoreApp.Domain = domain
}
core.CoreApp.UseCdn = (r.PostForm.Get("enable_cdn") == "on")
core.CoreApp.Update()
core.OnSettingsSaved(core.CoreApp)
http.Redirect(w, r, "/settings", http.StatusSeeOther)
Expand Down
6 changes: 4 additions & 2 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,8 @@ import (
)

var (
VERSION string
VERSION string
usingEnv bool
)

func init() {
Expand All @@ -36,7 +37,7 @@ func main() {

core.Configs, err = core.LoadConfig()
if err != nil {
utils.Log(2, "config.yml file not found - starting in setup mode")
utils.Log(3, err)
core.SetupMode = true
handlers.RunHTTPServer()
}
Expand All @@ -56,6 +57,7 @@ func LoadDotEnvs() {
err := godotenv.Load()
if err == nil {
utils.Log(1, "Environment file '.env' Loaded")
usingEnv = true
}
}

Expand Down
13 changes: 13 additions & 0 deletions source/tmpl/dashboard.html
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,13 @@
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no, maximum-scale=1.0, user-scalable=0">
{{if USE_CDN}}
<link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/4.1.1/css/bootstrap.min.css" integrity="sha384-WskhaSGFgHYWDcbwN70/dfYBj47jz9qbsMId/iRN3ewGhXQFZCSftd1LZCfmhktB" crossorigin="anonymous">
<link rel="stylesheet" href="https://assets.statup.io/base.css">
{{ else }}
<link rel="stylesheet" href="/css/bootstrap.min.css">
<link rel="stylesheet" href="/css/base.css">
{{end}}

<title>Statup | Dashboard</title>
</head>
Expand Down Expand Up @@ -83,8 +88,16 @@ <h5 class="mb-1">{{.ParseError}}</h5>

{{template "footer"}}

{{if USE_CDN}}
<script src="https://code.jquery.com/jquery-3.3.1.slim.min.js" integrity="sha384-q8i/X+965DzO0rT7abK41JStQIAqVgRVzpbzo5smXKp4YfRvH+8abtTE1Pi6jizo" crossorigin="anonymous"></script>
<script src="https://stackpath.bootstrapcdn.com/bootstrap/4.1.1/js/bootstrap.min.js" integrity="sha384-smHYKdLADwkXOn1EmN1qk/HfnUcbVRZyYmZ4qpPea6sjB/pTJ0euyQp0Mk8ck+5T" crossorigin="anonymous"></script>
<script src="https://assets.statup.io/main.js"></script>
{{ else }}
<script src="/js/jquery-3.3.1.slim.min.js"></script>
<script src="/js/bootstrap.min.js"></script>
<script src="/js/main.js"></script>
{{end}}


</body>
</html>
13 changes: 13 additions & 0 deletions source/tmpl/error_404.html
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,13 @@
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no, maximum-scale=1.0, user-scalable=0">
{{if USE_CDN}}
<link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/4.1.1/css/bootstrap.min.css" integrity="sha384-WskhaSGFgHYWDcbwN70/dfYBj47jz9qbsMId/iRN3ewGhXQFZCSftd1LZCfmhktB" crossorigin="anonymous">
<link rel="stylesheet" href="https://assets.statup.io/base.css">
{{ else }}
<link rel="stylesheet" href="/css/bootstrap.min.css">
<link rel="stylesheet" href="/css/base.css">
{{end}}

<title>Statup | Page Not Found</title>
</head>
Expand All @@ -25,7 +30,15 @@

{{template "footer"}}

{{if USE_CDN}}
<script src="https://code.jquery.com/jquery-3.3.1.slim.min.js" integrity="sha384-q8i/X+965DzO0rT7abK41JStQIAqVgRVzpbzo5smXKp4YfRvH+8abtTE1Pi6jizo" crossorigin="anonymous"></script>
<script src="https://stackpath.bootstrapcdn.com/bootstrap/4.1.1/js/bootstrap.min.js" integrity="sha384-smHYKdLADwkXOn1EmN1qk/HfnUcbVRZyYmZ4qpPea6sjB/pTJ0euyQp0Mk8ck+5T" crossorigin="anonymous"></script>
<script src="https://assets.statup.io/main.js"></script>
{{ else }}
<script src="/js/jquery-3.3.1.slim.min.js"></script>
<script src="/js/bootstrap.min.js"></script>
<script src="/js/main.js"></script>
{{end}}

</body>
</html>
19 changes: 15 additions & 4 deletions source/tmpl/help.html
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,13 @@
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">

{{if USE_CDN}}
<link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/4.1.1/css/bootstrap.min.css" integrity="sha384-WskhaSGFgHYWDcbwN70/dfYBj47jz9qbsMId/iRN3ewGhXQFZCSftd1LZCfmhktB" crossorigin="anonymous">
<link rel="stylesheet" href="https://assets.statup.io/base.css">
{{ else }}
<link rel="stylesheet" href="/css/bootstrap.min.css">
<link rel="stylesheet" href="/css/base.css">

{{end}}
<title>Statup | Help</title>
</head>
<body>
Expand Down Expand Up @@ -52,7 +55,15 @@ <h2 class="mt-3">Custom Stlying</h2>

{{template "footer"}}

<script src="/js/jquery-3.3.1.slim.min.js"></script>
<script src="/js/bootstrap.min.js"></script>
{{if USE_CDN}}
<script src="https://code.jquery.com/jquery-3.3.1.slim.min.js" integrity="sha384-q8i/X+965DzO0rT7abK41JStQIAqVgRVzpbzo5smXKp4YfRvH+8abtTE1Pi6jizo" crossorigin="anonymous"></script>
<script src="https://stackpath.bootstrapcdn.com/bootstrap/4.1.1/js/bootstrap.min.js" integrity="sha384-smHYKdLADwkXOn1EmN1qk/HfnUcbVRZyYmZ4qpPea6sjB/pTJ0euyQp0Mk8ck+5T" crossorigin="anonymous"></script>
<script src="https://assets.statup.io/main.js"></script>
{{ else }}
<script src="/js/jquery-3.3.1.slim.min.js"></script>
<script src="/js/bootstrap.min.js"></script>
<script src="/js/main.js"></script>
{{end}}

</body>
</html>
18 changes: 10 additions & 8 deletions source/tmpl/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,13 @@
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no, maximum-scale=1.0, user-scalable=0">
<link rel="shortcut icon" type="image/x-icon" href="/favicon.ico">
{{if .Core.OfflineAssets}}
<link rel="stylesheet" href="https://assets.statup.io/bootstrap.min.css">
{{if USE_CDN}}
<link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/4.1.1/css/bootstrap.min.css" integrity="sha384-WskhaSGFgHYWDcbwN70/dfYBj47jz9qbsMId/iRN3ewGhXQFZCSftd1LZCfmhktB" crossorigin="anonymous">
<link rel="stylesheet" href="https://assets.statup.io/base.css">
{{ else }}
<link rel="stylesheet" href="/css/bootstrap.min.css">
<link rel="stylesheet" href="/css/base.css">
{{end}}
<link rel="stylesheet" href="/css/base.css">

<title>{{.Core.Name}} Status</title>
</head>
Expand Down Expand Up @@ -101,16 +102,17 @@ <h4 class="mt-3"><a href="/service/{{.Id}}"{{if not .Online}} class="text-danger
{{template "footer"}}


{{if .Core.OfflineAssets}}
<script src="https://assets.statup.io/jquery-3.3.1.slim.min.js"></script>
<script src="https://assets.statup.io/bootstrap.min.js"></script>
<script src="https://assets.statup.io/Chart.bundle.min.js"></script>
{{if USE_CDN}}
<script src="https://code.jquery.com/jquery-3.3.1.slim.min.js" integrity="sha384-q8i/X+965DzO0rT7abK41JStQIAqVgRVzpbzo5smXKp4YfRvH+8abtTE1Pi6jizo" crossorigin="anonymous"></script>
<script src="https://stackpath.bootstrapcdn.com/bootstrap/4.1.1/js/bootstrap.min.js" integrity="sha384-smHYKdLADwkXOn1EmN1qk/HfnUcbVRZyYmZ4qpPea6sjB/pTJ0euyQp0Mk8ck+5T" crossorigin="anonymous"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/Chart.js/2.7.2/Chart.bundle.min.js"></script>
<script src="https://assets.statup.io/main.js"></script>
{{ else }}
<script src="/js/jquery-3.3.1.slim.min.js"></script>
<script src="/js/bootstrap.min.js"></script>
<script src="/js/Chart.bundle.min.js"></script>
{{end}}
<script src="/js/main.js"></script>
{{end}}
<script src="/charts.js"></script>

{{ if .Core.Style }}
Expand Down
14 changes: 13 additions & 1 deletion source/tmpl/login.html
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,13 @@
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no, maximum-scale=1.0, user-scalable=0">
{{if USE_CDN}}
<link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/4.1.1/css/bootstrap.min.css" integrity="sha384-WskhaSGFgHYWDcbwN70/dfYBj47jz9qbsMId/iRN3ewGhXQFZCSftd1LZCfmhktB" crossorigin="anonymous">
<link rel="stylesheet" href="https://assets.statup.io/base.css">
{{ else }}
<link rel="stylesheet" href="/css/bootstrap.min.css">
<link rel="stylesheet" href="/css/base.css">

{{end}}
<title>Statup | Login</title>
</head>
<body>
Expand Down Expand Up @@ -47,7 +51,15 @@

{{template "footer"}}

{{if USE_CDN}}
<script src="https://code.jquery.com/jquery-3.3.1.slim.min.js" integrity="sha384-q8i/X+965DzO0rT7abK41JStQIAqVgRVzpbzo5smXKp4YfRvH+8abtTE1Pi6jizo" crossorigin="anonymous"></script>
<script src="https://stackpath.bootstrapcdn.com/bootstrap/4.1.1/js/bootstrap.min.js" integrity="sha384-smHYKdLADwkXOn1EmN1qk/HfnUcbVRZyYmZ4qpPea6sjB/pTJ0euyQp0Mk8ck+5T" crossorigin="anonymous"></script>
<script src="https://assets.statup.io/main.js"></script>
{{ else }}
<script src="/js/jquery-3.3.1.slim.min.js"></script>
<script src="/js/bootstrap.min.js"></script>
<script src="/js/main.js"></script>
{{end}}

</body>
</html>

0 comments on commit 3cc63a0

Please sign in to comment.