From 3c9f9b7b84004eb2d71e2215f94173b9f198dbd1 Mon Sep 17 00:00:00 2001 From: Yauhen Shulitski Date: Wed, 20 Jan 2021 21:47:56 +0100 Subject: [PATCH 1/4] Update editor settings --- .vscode/settings.json | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/.vscode/settings.json b/.vscode/settings.json index ea3fed6..3f465cd 100644 --- a/.vscode/settings.json +++ b/.vscode/settings.json @@ -10,7 +10,8 @@ "source.fixAll.eslint": true }, "eslint.workingDirectories": ["src/frontend/"], - "go.languageServerExperimentalFeatures": { - "rename": true - }, + "gopls": { + "buildFlags": ["-tags=wireinject"], + "experimentalWorkspaceModule": true + }, } From eb2dd01353b23dc5e837cd4cc6f50d2f3262e709 Mon Sep 17 00:00:00 2001 From: Yauhen Shulitski Date: Wed, 20 Jan 2021 23:43:40 +0100 Subject: [PATCH 2/4] Update npm test targets --- src/frontend/{cypress.json => cypress_dev.json} | 0 src/frontend/cypress_prod.json | 4 ++++ src/frontend/package.json | 6 ++++-- 3 files changed, 8 insertions(+), 2 deletions(-) rename src/frontend/{cypress.json => cypress_dev.json} (100%) create mode 100644 src/frontend/cypress_prod.json diff --git a/src/frontend/cypress.json b/src/frontend/cypress_dev.json similarity index 100% rename from src/frontend/cypress.json rename to src/frontend/cypress_dev.json diff --git a/src/frontend/cypress_prod.json b/src/frontend/cypress_prod.json new file mode 100644 index 0000000..34449f4 --- /dev/null +++ b/src/frontend/cypress_prod.json @@ -0,0 +1,4 @@ +{ + "baseUrl": "http://localhost:8081", + "video": false +} diff --git a/src/frontend/package.json b/src/frontend/package.json index 748c7e9..f62c843 100644 --- a/src/frontend/package.json +++ b/src/frontend/package.json @@ -6,8 +6,10 @@ "serve": "vue-cli-service serve", "build": "vue-cli-service build", "lint": "vue-cli-service lint", - "test": "cypress run --browser=firefox --headless", - "test:open": "cypress open" + "test": "cypress run --browser=firefox --headless --config-file=cypress_prod.json", + "test:prod": "cypress run --browser=firefox --headless --config-file=cypress_prod.json", + "test:dev": "cypress run --browser=firefox --headless --config-file=cypress_dev.json", + "test:open": "cypress open --config-file=cypress_dev.json" }, "dependencies": { "axios": "^0.21.1", From 53ac8d9dbd9d2767deffe8c92a997568a87aa4a3 Mon Sep 17 00:00:00 2001 From: Yauhen Shulitski Date: Wed, 20 Jan 2021 23:44:24 +0100 Subject: [PATCH 3/4] :M: Switch to go embed --- Makefile | 22 +++++----------------- src/backend/.gitignore | 3 +-- src/backend/go.mod | 5 ++--- src/backend/go.sum | 11 ----------- src/backend/main.go | 7 ++++--- src/backend/middleware.go | 30 +++++++++++++++++------------- 6 files changed, 29 insertions(+), 49 deletions(-) diff --git a/Makefile b/Makefile index a6861dd..21318c1 100644 --- a/Makefile +++ b/Makefile @@ -16,16 +16,14 @@ export VUE_APP_VERSION = ${VERSION}-${VUE_VERSION_SUFFIX} .ONESHELL: src/backend/wakeci: version src/backend/*.go cd src/backend - rm -f rice-box.go - go build -ldflags="-X main.Version=${VERSION}" -o ${BINARY} + rm -rf assets + cp -r ../frontend/dist/ assets + CGO_ENABLED=0 go build -ldflags="-X main.Version=${VERSION}" -o ${BINARY} .ONESHELL: -bin/wakeci: version src/backend/*.go +bin/wakeci: src/backend/wakeci cd src/backend - rm -f rice-box.go - rice embed-go || exit 1 - CGO_ENABLED=0 go build -ldflags="-X main.Version=${VERSION}" -o ${BINARY} - mv wakeci ${PWD}/bin/ + cp wakeci ${PWD}/bin/ runf: cd src/frontend && npm run serve @@ -41,16 +39,6 @@ buildf: build: buildf bin/wakeci -deploy: build - ssh wakeci mkdir wakedir - ssh wakeci mkdir wakeconfig - ssh wakeci sudo systemctl stop ${BINARY} || exit 0 - ssh wakeci rm -f ${BINARY} - scp bin/${BINARY} wakeci:~/ - ssh wakeci sudo setcap cap_net_bind_service=+ep ${BINARY} - ssh wakeci sudo systemctl start ${BINARY} - ssh wakeci sudo systemctl status ${BINARY} - release: build grm release jsnjack/wakeci -f bin/${BINARY} -t "v`monova`" diff --git a/src/backend/.gitignore b/src/backend/.gitignore index b3ac85d..8d1faa1 100644 --- a/src/backend/.gitignore +++ b/src/backend/.gitignore @@ -1,3 +1,2 @@ wakeci -vendor/ -rice-box.go +assets diff --git a/src/backend/go.mod b/src/backend/go.mod index 3ae6b84..1dfa45b 100644 --- a/src/backend/go.mod +++ b/src/backend/go.mod @@ -1,12 +1,11 @@ module wakeci -go 1.13 +go 1.16 require ( - github.com/GeertJohan/go.rice v1.0.2 github.com/NYTimes/gziphandler v1.1.1 github.com/bmatcuk/doublestar v1.3.4 - github.com/daaku/go.zipexe v1.0.1 // indirect + github.com/davecgh/go-spew v1.1.1 // indirect github.com/go-cmd/cmd v1.2.0 // indirect github.com/gofrs/uuid v4.0.0+incompatible github.com/gorilla/websocket v1.4.2 diff --git a/src/backend/go.sum b/src/backend/go.sum index cd4213f..cc3f777 100644 --- a/src/backend/go.sum +++ b/src/backend/go.sum @@ -1,14 +1,7 @@ -github.com/GeertJohan/go.incremental v1.0.0/go.mod h1:6fAjUhbVuX1KcMD3c8TEgVUqmo4seqhv0i0kdATSkM0= -github.com/GeertJohan/go.rice v1.0.2 h1:PtRw+Tg3oa3HYwiDBZyvOJ8LdIyf6lAovJJtr7YOAYk= -github.com/GeertJohan/go.rice v1.0.2/go.mod h1:af5vUNlDNkCjOZeSGFgIJxDje9qdjsO6hshx0gTmZt4= github.com/NYTimes/gziphandler v1.1.1 h1:ZUDjpQae29j0ryrS0u/B8HZfJBtBQHjqw2rQ2cqUQ3I= github.com/NYTimes/gziphandler v1.1.1/go.mod h1:n/CVRwUEOgIxrgPvAQhUUr9oeUtvrhMomdKFjzJNB0c= -github.com/akavel/rsrc v0.8.0/go.mod h1:uLoCtb9J+EyAqh+26kdrTgmzRBFPGOolLWKpdxkKq+c= github.com/bmatcuk/doublestar v1.3.4 h1:gPypJ5xD31uhX6Tf54sDPUOBXTqKH4c9aPY66CyQrS0= github.com/bmatcuk/doublestar v1.3.4/go.mod h1:wiQtGV+rzVYxB7WIlirSN++5HPtPlXEo9MEoZQC/PmE= -github.com/daaku/go.zipexe v1.0.0/go.mod h1:z8IiR6TsVLEYKwXAoE/I+8ys/sDkgTzSL0CLnGVd57E= -github.com/daaku/go.zipexe v1.0.1 h1:wV4zMsDOI2SZ2m7Tdz1Ps96Zrx+TzaK15VbUaGozw0M= -github.com/daaku/go.zipexe v1.0.1/go.mod h1:5xWogtqlYnfBXkSB1o9xysukNP9GTvaNkqzUZbt3Bw8= github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c= github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= @@ -20,12 +13,10 @@ github.com/gofrs/uuid v4.0.0+incompatible h1:1SD/1F5pU8p29ybwgQSwpQk+mwdRrXCYuPh github.com/gofrs/uuid v4.0.0+incompatible/go.mod h1:b2aQJv3Z4Fp6yNu3cdSllBxTCLRxnplIgP/c0N/04lM= github.com/gorilla/websocket v1.4.2 h1:+/TMaTYc4QFitKJxsQ7Yye35DkWvkdLcvGKqM+x0Ufc= github.com/gorilla/websocket v1.4.2/go.mod h1:YR8l580nyteQvAITg2hZ9XVh4b55+EU/adAjf1fMHhE= -github.com/jessevdk/go-flags v1.4.0/go.mod h1:4FA24M0QyGHXBuZZK/XkWh8h0e1EYbRYJSGM75WSRxI= github.com/jsnjack/cmd v1.0.6-0.20200228215332-45cf13c519c4 h1:ratfe5IRiMI6/kzQt3xTPVoUYXtiC/yEaRqRSvZdQOc= github.com/jsnjack/cmd v1.0.6-0.20200228215332-45cf13c519c4/go.mod h1:f14kglzXmlAgGKitIHA4NC7BxUQ+eqa2l4LfUzRz5tg= github.com/julienschmidt/httprouter v1.3.0 h1:U0609e9tgbseu3rBINet9P48AI/D3oJs4dN7jwJOQ1U= github.com/julienschmidt/httprouter v1.3.0/go.mod h1:JR6WtHb+2LUe8TCKY3cZOxFyyO8IZAc4RVcycCCAKdM= -github.com/nkovacs/streamquote v1.0.0/go.mod h1:BN+NaZ2CmdKqUuTUXUEm9j95B2TRbpOWpxbJYzzgUsc= github.com/petermattis/goid v0.0.0-20180202154549-b0b1615b78e5 h1:q2e307iGHPdTGp0hoxKjt1H5pDo6utceo3dQVK3I5XQ= github.com/petermattis/goid v0.0.0-20180202154549-b0b1615b78e5/go.mod h1:jvVRKCrJTQWu0XVbaOlby/2lO20uSCHEMzzplHXte1o= github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM= @@ -37,8 +28,6 @@ github.com/sasha-s/go-deadlock v0.2.0/go.mod h1:StQn567HiB1fF2yJ44N9au7wOhrPS3iZ github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME= github.com/stretchr/testify v1.3.0 h1:TivCn/peBQ7UY8ooIcPgZFpTNSz0Q2U6UrFlUfqbe0Q= github.com/stretchr/testify v1.3.0/go.mod h1:M5WIy9Dh21IEIfnGCwXGc5bZfKNJtfHm1UVUgZn+9EI= -github.com/valyala/bytebufferpool v1.0.0/go.mod h1:6bBcMArwyJ5K/AmCkWv1jt77kVWyCJ6HpOuEn7z0Csc= -github.com/valyala/fasttemplate v1.0.1/go.mod h1:UQGH1tvbgY+Nz5t2n7tXsz52dQxojPUpymEIMZ47gx8= go.etcd.io/bbolt v1.3.5 h1:XAzx9gjCb0Rxj7EoqcClPD1d5ZBxZJk0jbuoPHenBt0= go.etcd.io/bbolt v1.3.5/go.mod h1:G5EMThwa9y8QZGBClrRx5EY+Yw9kAhnjy3bSjsnlVTQ= golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w= diff --git a/src/backend/main.go b/src/backend/main.go index aec249c..2744361 100644 --- a/src/backend/main.go +++ b/src/backend/main.go @@ -2,6 +2,7 @@ package main import ( "crypto/tls" + "embed" "flag" "log" "net/http" @@ -10,7 +11,6 @@ import ( "golang.org/x/crypto/acme/autocert" "golang.org/x/crypto/bcrypt" - rice "github.com/GeertJohan/go.rice" "github.com/NYTimes/gziphandler" "github.com/julienschmidt/httprouter" "github.com/robfig/cron/v3" @@ -134,9 +134,10 @@ func main() { HostPolicy: autocert.HostWhitelist(Config.Hostname), } - vueBox := rice.MustFindBox("../frontend/dist/").HTTPBox() + //go:embed assets/* + var assets embed.FS - vuefs := http.FileServer(vueBox) + vuefs := http.FileServer(http.FS(assets)) storageServer := http.FileServer(http.Dir(Config.WorkDir + "wakespace")) // Configure routes router := httprouter.New() diff --git a/src/backend/middleware.go b/src/backend/middleware.go index 1c5bb48..ffc93c4 100644 --- a/src/backend/middleware.go +++ b/src/backend/middleware.go @@ -151,25 +151,29 @@ func VueResourcesMi(h http.Handler) http.Handler { if !ok { logger = Logger } - // First check if it is any of API or AUTH calls - if strings.HasPrefix(r.URL.Path, "/api/") || strings.HasPrefix(r.URL.Path, "/auth/") { - w.WriteHeader(http.StatusNotFound) - logger.Printf("vue 404 %s\n", r.URL.Path) + // First check if it is any of API, AUTH or STORAGE calls. This urls + // should never reach this point + switch { + case strings.HasPrefix(r.URL.Path, "/api/"), strings.HasPrefix(r.URL.Path, "/auth/"), strings.HasPrefix(r.URL.Path, "/storage/"): + w.WriteHeader(http.StatusInternalServerError) + logger.Printf("vue 500 %s\n", r.URL.Path) return } - // Static file or root address - if strings.Contains(r.URL.Path, ".") || r.URL.Path == "/" { - logger.Printf("vue GET %s\n", r.URL.Path) - h.ServeHTTP(w, r) - return - } - // Most likely this is request to one of the dynamic URLs used by frontend, - // serve index.html (/) in this case + r2 := new(http.Request) *r2 = *r r2.URL = new(url.URL) *r2.URL = *r.URL - r2.URL.Path = "/" + switch { + case strings.Contains(r.URL.Path, "."), r.URL.Path == "/": + // Static file or root address + r2.URL.Path = "/assets" + r.URL.Path + break + default: + // Most likely this is request to one of the dynamic URLs used by frontend, + // serve index.html (/assets/) in this case + r2.URL.Path = "/assets/" + } logger.Printf("vue %s --> %s\n", r.URL.Path, r2.URL.Path) h.ServeHTTP(w, r2) }) From 8fd2c78e046b5025f098770eadf681d05d80118d Mon Sep 17 00:00:00 2001 From: Yauhen Shulitski Date: Wed, 20 Jan 2021 23:45:25 +0100 Subject: [PATCH 4/4] Update readme --- README.md | 5 ----- 1 file changed, 5 deletions(-) diff --git a/README.md b/README.md index f89803f..eea7027 100644 --- a/README.md +++ b/README.md @@ -77,8 +77,3 @@ jobdir: ./ ### API documentation See full description [here](https://github.com/jsnjack/wakeci/blob/master/API.md) -### For developers -#### Build dependencies -```bash -sudo dnf install golang-github-geertjohan-rice -```