log view fixed - moved main to cmd folder - update service fix

pull/44/merge
Hunter Long 2018-07-26 19:10:05 -07:00
parent db7be1a11d
commit f13570e4e6
19 changed files with 113 additions and 69 deletions

5
.gitignore vendored
View File

@ -1,5 +1,5 @@
.idea .idea
./rice-box.go cmd/rice-box.go
config.yml config.yml
statup.db statup.db
plugins/*.so plugins/*.so
@ -13,4 +13,5 @@ public
assets assets
cmd.sh cmd.sh
*.log *.log
.env .env
logs

View File

@ -18,7 +18,7 @@ services:
env: env:
global: global:
- VERSION=0.35 - VERSION=0.36
- DB_HOST=localhost - DB_HOST=localhost
- DB_USER=travis - DB_USER=travis
- DB_PASS= - DB_PASS=
@ -38,14 +38,14 @@ deploy:
- provider: releases - provider: releases
api_key: $GH_TOKEN api_key: $GH_TOKEN
file: file:
- "build/statup-osx-x64.tar.gz" - "cmd/build/statup-osx-x64.tar.gz"
- "build/statup-osx-x32.tar.gz" - "cmd/build/statup-osx-x32.tar.gz"
- "build/statup-linux-x64.tar.gz" - "cmd/build/statup-linux-x64.tar.gz"
- "build/statup-linux-x32.tar.gz" - "cmd/build/statup-linux-x32.tar.gz"
- "build/statup-linux-arm64.tar.gz" - "cmd/build/statup-linux-arm64.tar.gz"
- "build/statup-linux-arm7.tar.gz" - "cmd/build/statup-linux-arm7.tar.gz"
- "build/statup-linux-alpine.tar.gz" - "cmd/build/statup-linux-alpine.tar.gz"
- "build/statup-windows-x64.zip" - "cmd/build/statup-windows-x64.zip"
skip_cleanup: true skip_cleanup: true
notifications: notifications:
@ -62,11 +62,11 @@ before_script:
- go get github.com/karalabe/xgo - go get github.com/karalabe/xgo
- go get github.com/GeertJohan/go.rice - go get github.com/GeertJohan/go.rice
- go get github.com/GeertJohan/go.rice/rice - go get github.com/GeertJohan/go.rice/rice
- go get - cd cmd && go get && cd $GOPATH/src/github.com/hunterlong/statup
script: script:
- /bin/bash -c .travis/compile.sh - /bin/bash -c .travis/compile.sh
- go test -v -covermode=count -coverprofile=coverage.out - go test -v ./... -covermode=count -coverprofile=coverage.out
- if [[ "$TRAVIS_BRANCH" == "master" ]]; then $GOPATH/bin/goveralls -coverprofile=coverage.out -service=travis -repotoken $COVERALLS; fi - if [[ "$TRAVIS_BRANCH" == "master" ]]; then $GOPATH/bin/goveralls -coverprofile=coverage.out -service=travis -repotoken $COVERALLS; fi
after_success: after_success:

View File

@ -3,6 +3,8 @@
APP="statup" APP="statup"
REPO="hunterlong/statup" REPO="hunterlong/statup"
cd $GOPATH/src/github.com/hunterlong/statup/cmd
# BUILD STATUP GOLANG BINS # BUILD STATUP GOLANG BINS
mkdir build mkdir build
xgo -go 1.10.x --targets=darwin/amd64 --dest=build -ldflags="-X main.VERSION=$VERSION" ./ xgo -go 1.10.x --targets=darwin/amd64 --dest=build -ldflags="-X main.VERSION=$VERSION" ./
@ -20,23 +22,25 @@ ls
mv alpine-linux-amd64 $APP mv alpine-linux-amd64 $APP
tar -czvf $APP-linux-alpine.tar.gz $APP && rm -f $APP tar -czvf $APP-linux-alpine.tar.gz $APP && rm -f $APP
mv $APP-darwin-10.6-amd64 $APP mv cmd-darwin-10.6-amd64 $APP
tar -czvf $APP-osx-x64.tar.gz $APP && rm -f $APP tar -czvf $APP-osx-x64.tar.gz $APP && rm -f $APP
mv $APP-darwin-10.6-386 $APP mv cmd-darwin-10.6-386 $APP
tar -czvf $APP-osx-x32.tar.gz $APP && rm -f $APP tar -czvf $APP-osx-x32.tar.gz $APP && rm -f $APP
mv $APP-linux-amd64 $APP mv cmd-linux-amd64 $APP
tar -czvf $APP-linux-x64.tar.gz $APP && rm -f $APP tar -czvf $APP-linux-x64.tar.gz $APP && rm -f $APP
mv $APP-linux-386 $APP mv cmd-linux-386 $APP
tar -czvf $APP-linux-x32.tar.gz $APP && rm -f $APP tar -czvf $APP-linux-x32.tar.gz $APP && rm -f $APP
mv $APP-windows-6.0-amd64.exe $APP.exe mv cmd-windows-6.0-amd64.exe $APP.exe
zip $APP-windows-x64.zip $APP.exe && rm -f $APP.exe zip $APP-windows-x64.zip $APP.exe && rm -f $APP.exe
mv $APP-linux-arm-7 $APP mv cmd-linux-arm-7 $APP
tar -czvf $APP-linux-arm7.tar.gz $APP && rm -f $APP tar -czvf $APP-linux-arm7.tar.gz $APP && rm -f $APP
mv $APP-linux-arm64 $APP mv cmd-linux-arm64 $APP
tar -czvf $APP-linux-arm64.tar.gz $APP && rm -f $APP tar -czvf $APP-linux-arm64.tar.gz $APP && rm -f $APP
cd $GOPATH/src/github.com/hunterlong/statup

View File

@ -1,8 +1,10 @@
#!/usr/bin/env bash #!/usr/bin/env bash
cd $GOPATH/src/github.com/hunterlong/statup/cmd
# RENDERING CSS # RENDERING CSS
gem install sass gem install sass
sass source/scss/base.scss source/css/base.css sass ../source/scss/base.scss ../source/css/base.css
# MIGRATION SQL FILE FOR CURRENT VERSION # MIGRATION SQL FILE FOR CURRENT VERSION
#printf "UPDATE core SET version='$VERSION';\n" >> source/sql/upgrade.sql #printf "UPDATE core SET version='$VERSION';\n" >> source/sql/upgrade.sql
@ -10,4 +12,8 @@ sass source/scss/base.scss source/css/base.css
# COMPILE SRC INTO BIN # COMPILE SRC INTO BIN
rice embed-go rice embed-go
go install go install
mv $GOPATH/bin/cmd $GOPATH/bin/statup
cd $GOPATH/src/github.com/hunterlong/statup

View File

View File

@ -46,11 +46,11 @@ func main() {
} }
func RenderBoxes() { func RenderBoxes() {
core.SqlBox = rice.MustFindBox("source/sql") core.SqlBox = rice.MustFindBox("../source/sql")
core.CssBox = rice.MustFindBox("source/css") core.CssBox = rice.MustFindBox("../source/css")
core.ScssBox = rice.MustFindBox("source/scss") core.ScssBox = rice.MustFindBox("../source/scss")
core.JsBox = rice.MustFindBox("source/js") core.JsBox = rice.MustFindBox("../source/js")
core.TmplBox = rice.MustFindBox("source/tmpl") core.TmplBox = rice.MustFindBox("../source/tmpl")
} }
func LoadDotEnvs() { func LoadDotEnvs() {

View File

@ -24,9 +24,9 @@ var (
func RunInit(t *testing.T) { func RunInit(t *testing.T) {
RenderBoxes() RenderBoxes()
os.Remove("./statup.db") os.Remove("cmd/statup.db")
os.Remove("./config.yml") os.Remove("cmd/config.yml")
os.Remove("./index.html") os.Remove("cmd/index.html")
route = handlers.Router() route = handlers.Router()
LoadDotEnvs() LoadDotEnvs()
core.CoreApp = core.NewCore() core.CoreApp = core.NewCore()
@ -46,7 +46,7 @@ func TestRunAll(t *testing.T) {
RunInit(t) RunInit(t)
}) })
t.Run(dbt+" load database config", func(t *testing.T) { t.Run(dbt+" load database config", func(t *testing.T) {
RunMySQLMakeConfig(t, dbt) RunMakeDatabaseConfig(t, dbt)
}) })
t.Run(dbt+" run database migrations", func(t *testing.T) { t.Run(dbt+" run database migrations", func(t *testing.T) {
RunDatabaseMigrations(t, dbt) RunDatabaseMigrations(t, dbt)
@ -154,6 +154,9 @@ func TestRunAll(t *testing.T) {
t.Run(dbt+" HTTP /settings", func(t *testing.T) { t.Run(dbt+" HTTP /settings", func(t *testing.T) {
RunSettingsHandler(t) RunSettingsHandler(t)
}) })
t.Run(dbt+" Cleanup", func(t *testing.T) {
Cleanup(t)
})
<-forceSequential <-forceSequential
@ -193,7 +196,7 @@ func TestAssetsCommand(t *testing.T) {
assert.True(t, fileExists("assets/scss/base.scss")) assert.True(t, fileExists("assets/scss/base.scss"))
} }
func RunMySQLMakeConfig(t *testing.T, db string) { func RunMakeDatabaseConfig(t *testing.T, db string) {
port := 5432 port := 5432
if db == "mysql" { if db == "mysql" {
port = 3306 port = 3306
@ -552,10 +555,12 @@ func RunSettingsHandler(t *testing.T) {
assert.True(t, strings.Contains(rr.Body.String(), "footer")) assert.True(t, strings.Contains(rr.Body.String(), "footer"))
} }
//func RunComplete(t *testing.T) { func Cleanup(t *testing.T) {
// //os.Remove("./statup.db") os.Remove("./cmd/statup.db")
// os.Remove("./config.yml") os.Remove("./cmd/config.yml")
//} os.RemoveAll("./cmd/assets")
os.RemoveAll("./cmd/logs")
}
func fileExists(file string) bool { func fileExists(file string) bool {
if _, err := os.Stat(file); os.IsNotExist(err) { if _, err := os.Stat(file); os.IsNotExist(err) {

View File

@ -95,15 +95,12 @@ func CreateAllAssets() {
utils.Log(1, "Inserting scss, css, emails, and javascript files into assets..") utils.Log(1, "Inserting scss, css, emails, and javascript files into assets..")
CopyToPublic(ScssBox, "scss", "base.scss") CopyToPublic(ScssBox, "scss", "base.scss")
CopyToPublic(ScssBox, "scss", "variables.scss") CopyToPublic(ScssBox, "scss", "variables.scss")
//CopyToPublic(EmailBox, "emails", "message.html")
//CopyToPublic(EmailBox, "emails", "failure.html")
CopyToPublic(CssBox, "css", "bootstrap.min.css") CopyToPublic(CssBox, "css", "bootstrap.min.css")
CopyToPublic(JsBox, "js", "bootstrap.min.js") CopyToPublic(JsBox, "js", "bootstrap.min.js")
CopyToPublic(JsBox, "js", "Chart.bundle.min.js") CopyToPublic(JsBox, "js", "Chart.bundle.min.js")
CopyToPublic(JsBox, "js", "jquery-3.3.1.slim.min.js") CopyToPublic(JsBox, "js", "jquery-3.3.1.slim.min.js")
CopyToPublic(JsBox, "js", "main.js") CopyToPublic(JsBox, "js", "main.js")
CopyToPublic(JsBox, "js", "setup.js") CopyToPublic(JsBox, "js", "setup.js")
CopyToPublic(JsBox, "js", "setup.js")
CopyToPublic(TmplBox, "", "robots.txt") CopyToPublic(TmplBox, "", "robots.txt")
CopyToPublic(TmplBox, "", "favicon.ico") CopyToPublic(TmplBox, "", "favicon.ico")
utils.Log(1, "Compiling CSS from SCSS style...") utils.Log(1, "Compiling CSS from SCSS style...")

15
core/core_test.go Normal file
View File

@ -0,0 +1,15 @@
package core
import (
"github.com/stretchr/testify/assert"
"testing"
)
var (
testCore *Core
)
func TestNewCore(t *testing.T) {
testCore = NewCore()
assert.NotNil(t, testCore)
}

View File

@ -227,10 +227,22 @@ func UpdateService(u *types.Service) *types.Service {
if err != nil { if err != nil {
utils.Log(3, fmt.Sprintf("Failed to update service %v. %v", u.Name, err)) utils.Log(3, fmt.Sprintf("Failed to update service %v. %v", u.Name, err))
} }
updateService(u)
OnUpdateService(u) OnUpdateService(u)
return u return u
} }
func updateService(u *types.Service) {
var services []*Service
for _, s := range CoreApp.Services {
if s.s.Id == u.Id {
s.s = u
}
services = append(services, s)
}
CoreApp.Services = services
}
func CreateService(u *types.Service) (int64, error) { func CreateService(u *types.Service) (int64, error) {
u.CreatedAt = time.Now() u.CreatedAt = time.Now()
uuid, err := serviceCol().Insert(u) uuid, err := serviceCol().Insert(u)

View File

@ -7,7 +7,6 @@ import (
"github.com/hunterlong/statup/types" "github.com/hunterlong/statup/types"
"github.com/hunterlong/statup/utils" "github.com/hunterlong/statup/utils"
"net/http" "net/http"
"os"
) )
type dashboard struct { type dashboard struct {
@ -66,21 +65,6 @@ func LogsHandler(w http.ResponseWriter, r *http.Request) {
http.Redirect(w, r, "/", http.StatusSeeOther) http.Redirect(w, r, "/", http.StatusSeeOther)
return return
} }
file, err := os.Open("./statup.log")
if err != nil {
panic(err)
}
defer file.Close()
buf := make([]byte, 62)
stat, err := os.Stat("./statup.log")
start := stat.Size() - 62
_, err = file.ReadAt(buf, start)
if err == nil {
fmt.Printf("%s\n", buf)
}
ExecuteResponse(w, r, "logs.html", nil) ExecuteResponse(w, r, "logs.html", nil)
} }

17
handlers/handlers_test.go Normal file
View File

@ -0,0 +1,17 @@
package handlers
import (
"github.com/stretchr/testify/assert"
"net/http"
"net/http/httptest"
"testing"
)
func TestIndexHandler(t *testing.T) {
req, err := http.NewRequest("GET", "/", nil)
assert.Nil(t, err)
rr := httptest.NewRecorder()
Router().ServeHTTP(rr, req)
assert.Equal(t, 303, rr.Code)
}

View File

@ -132,7 +132,8 @@ func ServicesUpdateHandler(w http.ResponseWriter, r *http.Request) {
Timeout: timeout, Timeout: timeout,
} }
service = core.UpdateService(serviceUpdate) service = core.UpdateService(serviceUpdate)
ExecuteResponse(w, r, "service.html", service) serv = core.SelectService(service.Id)
ExecuteResponse(w, r, "service.html", serv)
} }
func ServicesDeleteFailuresHandler(w http.ResponseWriter, r *http.Request) { func ServicesDeleteFailuresHandler(w http.ResponseWriter, r *http.Request) {

View File

@ -59,8 +59,8 @@ HTML, BODY {
width: 100%; width: 100%;
background-color: #48d338; background-color: #48d338;
padding: 15px 10px; padding: 15px 10px;
margin-left: 0 !important; margin-left: 0px !important;
margin-right: 0 !important; } margin-right: 0px !important; }
.lower_canvas SPAN { .lower_canvas SPAN {
font-size: 1rem; font-size: 1rem;

File diff suppressed because one or more lines are too long

View File

@ -68,8 +68,8 @@ HTML,BODY {
width: 100%; width: 100%;
background-color: #48d338; background-color: #48d338;
padding: 15px 10px; padding: 15px 10px;
margin-left: 0 !important; margin-left: 0px !important;
margin-right: 0 !important; margin-right: 0px !important;
} }
.lower_canvas SPAN { .lower_canvas SPAN {

View File

@ -106,7 +106,6 @@
{{template "footer"}} {{template "footer"}}
{{if USE_CDN}} {{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://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://stackpath.bootstrapcdn.com/bootstrap/4.1.1/js/bootstrap.min.js" integrity="sha384-smHYKdLADwkXOn1EmN1qk/HfnUcbVRZyYmZ4qpPea6sjB/pTJ0euyQp0Mk8ck+5T" crossorigin="anonymous"></script>

View File

@ -17,12 +17,10 @@
<div class="container col-md-7 col-sm-12 mt-md-5 bg-light"> <div class="container col-md-7 col-sm-12 mt-md-5 bg-light">
<div class="col-4 offset-4">
<img width="100%" src="https://assets.statup.io/statup-words.png">
</div>
<div class="col-8 offset-2 mt-3"> <div class="col-8 offset-2 mt-3">
<div class="col-8 offset-2"><img src="https://assets.statup.io/statup-words.svg"></div>
{{ if .Error }} {{ if .Error }}
<div class="alert alert-danger" role="alert"> <div class="alert alert-danger" role="alert">
Incorrect login information submitted, try again. Incorrect login information submitted, try again.

View File

@ -21,12 +21,17 @@ var (
func InitLogs() { func InitLogs() {
var err error var err error
logFile, err = os.OpenFile("statup.log", os.O_RDWR|os.O_CREATE|os.O_APPEND, 0666)
if _, err := os.Stat("./logs"); os.IsNotExist(err) {
os.Mkdir("./logs", 0777)
}
logFile, err = os.OpenFile("./logs/statup.log", os.O_RDWR|os.O_CREATE|os.O_APPEND, 0666)
if err != nil { if err != nil {
log.Printf("ERROR opening file: %v", err) log.Printf("ERROR opening file: %v", err)
} }
ljLogger = &lumberjack.Logger{ ljLogger = &lumberjack.Logger{
Filename: "statup.log", Filename: "./logs/statup.log",
MaxSize: 16, MaxSize: 16,
MaxBackups: 3, MaxBackups: 3,
MaxAge: 28, MaxAge: 28,