diff --git a/.travis.yml b/.travis.yml index 31fbade4..c6b9cdfc 100644 --- a/.travis.yml +++ b/.travis.yml @@ -18,7 +18,7 @@ services: env: global: - - VERSION=0.29.6 + - VERSION=0.29.7 - DB_HOST=localhost - DB_USER=travis - DB_PASS= diff --git a/Dockerfile b/Dockerfile index 4cb9b91d..17a5dc5e 100644 --- a/Dockerfile +++ b/Dockerfile @@ -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 && \ diff --git a/core/configs.go b/core/configs.go index 34e4dce7..8f4c5a77 100644 --- a/core/configs.go +++ b/core/configs.go @@ -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, &config) - Configs = config - CoreApp.DbConnection = config.Connection - return config, err + 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 + } + return val } diff --git a/core/core.go b/core/core.go index a4cc807d..d6804229 100644 --- a/core/core.go +++ b/core/core.go @@ -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" ) @@ -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 @@ -43,6 +44,7 @@ var ( EmailBox *rice.Box SetupMode bool UsingAssets bool + VERSION string ) func init() { @@ -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 @@ -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 } diff --git a/core/database.go b/core/database.go index 58f5c2de..40e0df5a 100644 --- a/core/database.go +++ b/core/database.go @@ -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 diff --git a/core/export.go b/core/export.go index 3a257921..e372b476 100644 --- a/core/export.go +++ b/core/export.go @@ -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") diff --git a/handlers/handlers.go b/handlers/handlers.go index 2856795d..3061314c 100644 --- a/handlers/handlers.go +++ b/handlers/handlers.go @@ -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) }, diff --git a/handlers/routes.go b/handlers/routes.go index 5461e889..145e55ca 100644 --- a/handlers/routes.go +++ b/handlers/routes.go @@ -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") diff --git a/handlers/settings.go b/handlers/settings.go index 633f8aae..f95d95ec 100644 --- a/handlers/settings.go +++ b/handlers/settings.go @@ -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) diff --git a/main.go b/main.go index 4ef21d58..eaa305f3 100644 --- a/main.go +++ b/main.go @@ -16,7 +16,8 @@ import ( ) var ( - VERSION string + VERSION string + usingEnv bool ) func init() { @@ -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() } @@ -56,6 +57,7 @@ func LoadDotEnvs() { err := godotenv.Load() if err == nil { utils.Log(1, "Environment file '.env' Loaded") + usingEnv = true } } diff --git a/source/tmpl/dashboard.html b/source/tmpl/dashboard.html index 6e05d55c..aff72068 100644 --- a/source/tmpl/dashboard.html +++ b/source/tmpl/dashboard.html @@ -3,8 +3,13 @@
+{{if USE_CDN}} + + +{{ else }} +{{end}}