From b745ec6fa2af29fd012673cc3243530bf84147ce Mon Sep 17 00:00:00 2001 From: Tom Whiston Date: Mon, 5 Mar 2018 19:59:58 +0100 Subject: [PATCH 1/3] change to using packr instead of go-bindata --- .gitignore | 4 ++-- api/router.go | 11 +++++++---- db/migrations.go | 7 +++++-- db/versionHistory.go | 13 +++++++------ make.sh | 11 +---------- 5 files changed, 22 insertions(+), 24 deletions(-) diff --git a/.gitignore b/.gitignore index 4303094d9..7e5bd38d9 100644 --- a/.gitignore +++ b/.gitignore @@ -1,5 +1,4 @@ gin-bin -util/bindata.go build/ public/js/bundle.js public/css/semaphore.css @@ -9,4 +8,5 @@ node_modules .idea/ caddyfile -cli/semaphore_* \ No newline at end of file +cli/semaphore_* +*-packr.go diff --git a/api/router.go b/api/router.go index 2194e77aa..3d2e64faf 100644 --- a/api/router.go +++ b/api/router.go @@ -9,10 +9,13 @@ import ( "github.com/ansible-semaphore/semaphore/api/tasks" "github.com/ansible-semaphore/semaphore/util" "github.com/castawaylabs/mulekick" + "github.com/gobuffalo/packr" "github.com/gorilla/mux" "github.com/russross/blackfriday" ) +var publicAssets = packr.NewBox("../public") + // Declare all routes func Route() mulekick.Router { r := mulekick.New(mux.NewRouter(), mulekick.CorsMiddleware) @@ -123,21 +126,21 @@ func servePublic(w http.ResponseWriter, r *http.Request) { return } - path = "/public/html/index.html" + path = "/html/index.html" } - path = strings.Replace(path, "/", "", 1) + path = strings.Replace(path, "/public/", "", 1) split := strings.Split(path, ".") suffix := split[len(split)-1] - res, err := util.Asset(path) + res, err := publicAssets.MustBytes(path) if err != nil { mulekick.NotFoundHandler(w, r) return } // replace base path - if util.WebHostURL != nil && path == "public/html/index.html" { + if util.WebHostURL != nil && path == "html/index.html" { res = []byte(strings.Replace(string(res), "", "", diff --git a/db/migrations.go b/db/migrations.go index 6f0f8d8ca..0bd4a00c1 100644 --- a/db/migrations.go +++ b/db/migrations.go @@ -4,10 +4,12 @@ import ( "fmt" "time" - "github.com/ansible-semaphore/semaphore/util" "github.com/go-sql-driver/mysql" + "github.com/gobuffalo/packr" ) +var dbAssets = packr.NewBox("./migrations") + func (version *DBVersion) CheckExists() (bool, error) { exists, err := Mysql.SelectInt("select count(1) as ex from migrations where version=?", version.VersionString()) @@ -69,7 +71,8 @@ func (version *DBVersion) Run() error { func (version *DBVersion) TryRollback() { fmt.Printf("Rolling back %s (time: %v)...\n", version.HumanoidVersion(), time.Now()) - if _, err := util.Asset(version.GetErrPath()); err != nil { + data := dbAssets.Bytes(version.GetErrPath()) + if len(data) == 0 { fmt.Println("Rollback SQL does not exist.") fmt.Println() return diff --git a/db/versionHistory.go b/db/versionHistory.go index e47872f43..9ea085203 100644 --- a/db/versionHistory.go +++ b/db/versionHistory.go @@ -4,8 +4,6 @@ import ( "fmt" "strings" "time" - - "github.com/ansible-semaphore/semaphore/util" ) type DBVersion struct { @@ -41,15 +39,18 @@ func (version *DBVersion) HumanoidVersion() string { } func (version *DBVersion) GetPath() string { - return "db/migrations/v" + version.VersionString() + ".sql" + return "v" + version.VersionString() + ".sql" } func (version *DBVersion) GetErrPath() string { - return "db/migrations/v" + version.VersionString() + ".err.sql" + return "v" + version.VersionString() + ".err.sql" } func (version *DBVersion) GetSQL(path string) []string { - sql := util.MustAsset(path) - return strings.Split(string(sql), ";\n") + sql, err := dbAssets.MustString(path) + if err != nil { + panic(err) + } + return strings.Split(sql, ";\n") } func init() { diff --git a/make.sh b/make.sh index ac8d697a0..302f054e9 100755 --- a/make.sh +++ b/make.sh @@ -1,15 +1,6 @@ #!/bin/bash set -e -BINDATA_ARGS="-o util/bindata.go -pkg util" - -if [ "$1" == "watch" ]; then - BINDATA_ARGS="-debug ${BINDATA_ARGS}" - echo "Creating util/bindata.go with file proxy" -else - echo "Creating util/bindata.go" -fi - if [ "$1" == "ci_test" ]; then echo "Creating CI Test config.json" @@ -63,7 +54,7 @@ HEREDOC github-release release --draft -u ansible-semaphore -r semaphore -t "v$VERSION" -d "## Special thanks to\n\n## Installation\n\nFollow [wiki/Installation](https://github.com/ansible-semaphore/semaphore/wiki/Installation)\n\n## Changelog" fi -go-bindata $BINDATA_ARGS db/migrations/ $(find public/* -type d -print) +packr if [ "$1" == "ci_test" ]; then exit 0 From 5ecb4cb97fdf4e093860b8996b030843f502c382 Mon Sep 17 00:00:00 2001 From: Tom Whiston Date: Mon, 5 Mar 2018 20:09:02 +0100 Subject: [PATCH 2/3] Update CONTRIBUTING.md --- CONTRIBUTING.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index adfeeba47..311162cc6 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -33,7 +33,7 @@ git clone --recursive git@github.com:ansible-semaphore/semaphore.git && cd semap 3) Install dev dependencies ``` -go get ./... github.com/cespare/reflex github.com/jteeuwen/go-bindata/... github.com/mitchellh/gox +go get ./... github.com/cespare/reflex github.com/gobuffalo/packr/... github.com/mitchellh/gox npm install async npm install -g nodemon pug-cli less ``` From 8e9161100787e9c75f4508a43155ab990668a171 Mon Sep 17 00:00:00 2001 From: Tom Whiston Date: Mon, 5 Mar 2018 20:15:47 +0100 Subject: [PATCH 3/3] Update circle.yml --- circle.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/circle.yml b/circle.yml index 481214130..b14507b32 100644 --- a/circle.yml +++ b/circle.yml @@ -10,7 +10,7 @@ dependencies: - git submodule update --init --recursive - npm i -g less pug-cli - npm i async - - go get github.com/jteeuwen/go-bindata/... + - go get github.com/gobuffalo/packr/... - go get github.com/mitchellh/gox override: