From 83951768bc39261f8d6f2e7d8ddc54fe30208f54 Mon Sep 17 00:00:00 2001 From: Maxim Babichev Date: Sat, 23 Mar 2024 19:54:09 +0300 Subject: [PATCH 1/5] add ui --- .gitmodules | 3 +++ stub/stub.go | 10 +++++++++- stub/ui | 1 + 3 files changed, 13 insertions(+), 1 deletion(-) create mode 100644 .gitmodules create mode 160000 stub/ui diff --git a/.gitmodules b/.gitmodules new file mode 100644 index 00000000..0fe19ffb --- /dev/null +++ b/.gitmodules @@ -0,0 +1,3 @@ +[submodule "stub/ui"] + path = stub/ui + url = git@github.com:bavix/gripmock-ui.git diff --git a/stub/stub.go b/stub/stub.go index f4f6f73d..beca1c8b 100644 --- a/stub/stub.go +++ b/stub/stub.go @@ -2,8 +2,9 @@ package stub import ( "context" + "embed" "errors" - "github.com/bavix/gripmock/internal/pkg/grpcreflector" + "io/fs" "net" "net/http" "time" @@ -16,6 +17,7 @@ import ( "github.com/bavix/gripmock/internal/app" "github.com/bavix/gripmock/internal/domain/rest" "github.com/bavix/gripmock/internal/pkg/features" + "github.com/bavix/gripmock/internal/pkg/grpcreflector" "github.com/bavix/gripmock/internal/pkg/muxmiddleware" ) @@ -25,6 +27,9 @@ type Options struct { StubPath string } +//go:embed ui/dist +var staticFiles embed.FS + func RunRestServer(ctx context.Context, ch chan struct{}, opt Options, reflector *grpcreflector.GReflector) { const timeout = time.Millisecond * 25 @@ -32,9 +37,12 @@ func RunRestServer(ctx context.Context, ch chan struct{}, opt Options, reflector apiServer, _ := app.NewRestServer(opt.StubPath, reflector) + htmlContent, _ := fs.Sub(staticFiles, "ui/dist") + router := mux.NewRouter() router.Use(muxmiddleware.RequestLogger) router.Use(otelmux.Middleware("gripmock-manager")) + router.Handle("/", http.FileServer(http.FS(htmlContent))) rest.HandlerFromMuxWithBaseURL(apiServer, router, "/api") srv := &http.Server{ diff --git a/stub/ui b/stub/ui new file mode 160000 index 00000000..3b58939a --- /dev/null +++ b/stub/ui @@ -0,0 +1 @@ +Subproject commit 3b58939a4a307424d4f4a4c9591443ae9a15c815 From 95769dfc90520e793d6eff6ad091540a513b9503 Mon Sep 17 00:00:00 2001 From: Maxim Babichev Date: Sat, 23 Mar 2024 20:01:31 +0300 Subject: [PATCH 2/5] submodules --- .github/workflows/builder.yaml | 3 +++ .github/workflows/unit.yml | 3 +++ stub/stub.go | 2 +- 3 files changed, 7 insertions(+), 1 deletion(-) diff --git a/.github/workflows/builder.yaml b/.github/workflows/builder.yaml index f615b034..8d09df44 100644 --- a/.github/workflows/builder.yaml +++ b/.github/workflows/builder.yaml @@ -14,6 +14,9 @@ jobs: - name: Checkout uses: actions/checkout@v4 + with: + submodules: 'true' + token: ${{ secrets.PAT_TOKEN }} - name: Docker meta id: meta diff --git a/.github/workflows/unit.yml b/.github/workflows/unit.yml index b9684d96..0c35522e 100644 --- a/.github/workflows/unit.yml +++ b/.github/workflows/unit.yml @@ -10,6 +10,9 @@ jobs: go-version: [ '1.22' ] steps: - uses: actions/checkout@v4 + with: + submodules: 'true' + token: ${{ secrets.PAT_TOKEN }} - name: Setup Go uses: actions/setup-go@v5 with: diff --git a/stub/stub.go b/stub/stub.go index beca1c8b..c9d0dbcc 100644 --- a/stub/stub.go +++ b/stub/stub.go @@ -27,7 +27,7 @@ type Options struct { StubPath string } -//go:embed ui/dist +//go:embed all:ui/dist var staticFiles embed.FS func RunRestServer(ctx context.Context, ch chan struct{}, opt Options, reflector *grpcreflector.GReflector) { From 6e7fad5c7f4b81bff870f75d53f12b3852a982fd Mon Sep 17 00:00:00 2001 From: Maxim Babichev Date: Sat, 23 Mar 2024 20:07:13 +0300 Subject: [PATCH 3/5] revert --- stub/stub.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/stub/stub.go b/stub/stub.go index c9d0dbcc..beca1c8b 100644 --- a/stub/stub.go +++ b/stub/stub.go @@ -27,7 +27,7 @@ type Options struct { StubPath string } -//go:embed all:ui/dist +//go:embed ui/dist var staticFiles embed.FS func RunRestServer(ctx context.Context, ch chan struct{}, opt Options, reflector *grpcreflector.GReflector) { From 28c517e2aeedaaf71465ba8166a33e69d8360f1e Mon Sep 17 00:00:00 2001 From: Maxim Babichev Date: Sat, 23 Mar 2024 20:09:38 +0300 Subject: [PATCH 4/5] actions/checkout --- .github/workflows/builder.yaml | 1 - .github/workflows/integration-test.yml | 7 +++++-- .github/workflows/unit.yml | 5 +++-- 3 files changed, 8 insertions(+), 5 deletions(-) diff --git a/.github/workflows/builder.yaml b/.github/workflows/builder.yaml index 8d09df44..24eb5934 100644 --- a/.github/workflows/builder.yaml +++ b/.github/workflows/builder.yaml @@ -16,7 +16,6 @@ jobs: uses: actions/checkout@v4 with: submodules: 'true' - token: ${{ secrets.PAT_TOKEN }} - name: Docker meta id: meta diff --git a/.github/workflows/integration-test.yml b/.github/workflows/integration-test.yml index ce4c8557..ab7ee1c2 100644 --- a/.github/workflows/integration-test.yml +++ b/.github/workflows/integration-test.yml @@ -7,8 +7,11 @@ jobs: name: Run example runs-on: ubuntu-latest steps: - - name: Checkout - uses: actions/checkout@master + - + name: Checkout + uses: actions/checkout@v4 + with: + submodules: 'true' - name: Run Simple Example uses: ./ with: diff --git a/.github/workflows/unit.yml b/.github/workflows/unit.yml index 0c35522e..b512ca22 100644 --- a/.github/workflows/unit.yml +++ b/.github/workflows/unit.yml @@ -9,10 +9,11 @@ jobs: matrix: go-version: [ '1.22' ] steps: - - uses: actions/checkout@v4 + - + name: Checkout + uses: actions/checkout@v4 with: submodules: 'true' - token: ${{ secrets.PAT_TOKEN }} - name: Setup Go uses: actions/setup-go@v5 with: From 94ac3f2c6701efc73d5e94309d7f74c8e749ca42 Mon Sep 17 00:00:00 2001 From: Maxim Babichev Date: Sat, 23 Mar 2024 23:44:56 +0300 Subject: [PATCH 5/5] revert changes --- .github/workflows/builder.yaml | 2 -- .github/workflows/integration-test.yml | 2 -- .github/workflows/unit.yml | 2 -- .gitmodules | 3 --- go.mod | 5 +++-- go.sum | 6 ++++++ stub/stub.go | 10 +++------- stub/ui | 1 - 8 files changed, 12 insertions(+), 19 deletions(-) delete mode 100644 .gitmodules delete mode 160000 stub/ui diff --git a/.github/workflows/builder.yaml b/.github/workflows/builder.yaml index 24eb5934..f615b034 100644 --- a/.github/workflows/builder.yaml +++ b/.github/workflows/builder.yaml @@ -14,8 +14,6 @@ jobs: - name: Checkout uses: actions/checkout@v4 - with: - submodules: 'true' - name: Docker meta id: meta diff --git a/.github/workflows/integration-test.yml b/.github/workflows/integration-test.yml index ab7ee1c2..42ed69e0 100644 --- a/.github/workflows/integration-test.yml +++ b/.github/workflows/integration-test.yml @@ -10,8 +10,6 @@ jobs: - name: Checkout uses: actions/checkout@v4 - with: - submodules: 'true' - name: Run Simple Example uses: ./ with: diff --git a/.github/workflows/unit.yml b/.github/workflows/unit.yml index b512ca22..70df77a6 100644 --- a/.github/workflows/unit.yml +++ b/.github/workflows/unit.yml @@ -12,8 +12,6 @@ jobs: - name: Checkout uses: actions/checkout@v4 - with: - submodules: 'true' - name: Setup Go uses: actions/setup-go@v5 with: diff --git a/.gitmodules b/.gitmodules deleted file mode 100644 index 0fe19ffb..00000000 --- a/.gitmodules +++ /dev/null @@ -1,3 +0,0 @@ -[submodule "stub/ui"] - path = stub/ui - url = git@github.com:bavix/gripmock-ui.git diff --git a/go.mod b/go.mod index 15adb1ba..59dab564 100644 --- a/go.mod +++ b/go.mod @@ -1,9 +1,10 @@ module github.com/bavix/gripmock -go 1.22.0 +go 1.22.1 require ( github.com/bavix/gripmock-sdk-go v1.0.2 + github.com/bavix/gripmock-ui v0.0.0-20240323204046-3f969ea2b548 github.com/bavix/gripmock/protogen v0.0.0 github.com/goccy/go-yaml v1.11.3 github.com/google/uuid v1.6.0 @@ -31,7 +32,7 @@ require ( require ( github.com/apapsch/go-jsonmerge/v2 v2.0.0 // indirect - github.com/bufbuild/protocompile v0.8.0 // indirect + github.com/bufbuild/protocompile v0.9.0 // indirect github.com/cenkalti/backoff/v4 v4.2.1 // indirect github.com/davecgh/go-spew v1.1.1 // indirect github.com/fatih/color v1.16.0 // indirect diff --git a/go.sum b/go.sum index d05bb33a..39bbf1e3 100644 --- a/go.sum +++ b/go.sum @@ -3,9 +3,15 @@ github.com/apapsch/go-jsonmerge/v2 v2.0.0 h1:axGnT1gRIfimI7gJifB699GoE/oq+F2MU7D github.com/apapsch/go-jsonmerge/v2 v2.0.0/go.mod h1:lvDnEdqiQrp0O42VQGgmlKpxL1AP2+08jFMw88y4klk= github.com/bavix/gripmock-sdk-go v1.0.2 h1:9FM8G4VVvwNrqGlbAvHjwM8h/TnbrCo4nJhsC8Lvaxw= github.com/bavix/gripmock-sdk-go v1.0.2/go.mod h1:/Z/81NJ7un4AIeAClLMJhZDyY9CBQOsSbPDqYds2kEY= +github.com/bavix/gripmock-ui v0.0.0-20240323201612-9c398954a28f h1:yvEJ72kfC2+RqPLtkEy4dUd6Aj65m0Fss7CkMsB2MSM= +github.com/bavix/gripmock-ui v0.0.0-20240323201612-9c398954a28f/go.mod h1:XEH4YYEKL+wEDtONntoWm6JxjbVWzl7XtDYztUTBfeA= +github.com/bavix/gripmock-ui v0.0.0-20240323204046-3f969ea2b548 h1:5dcwtgVLjgekwlVsgSF/EPD9wpl8niWyqcCNCrdHhLU= +github.com/bavix/gripmock-ui v0.0.0-20240323204046-3f969ea2b548/go.mod h1:XEH4YYEKL+wEDtONntoWm6JxjbVWzl7XtDYztUTBfeA= github.com/bmatcuk/doublestar v1.1.1/go.mod h1:UD6OnuiIn0yFxxA2le/rnRU1G4RaI4UvFv1sNto9p6w= github.com/bufbuild/protocompile v0.8.0 h1:9Kp1q6OkS9L4nM3FYbr8vlJnEwtbpDPQlQOVXfR+78s= github.com/bufbuild/protocompile v0.8.0/go.mod h1:+Etjg4guZoAqzVk2czwEQP12yaxLJ8DxuqCJ9qHdH94= +github.com/bufbuild/protocompile v0.9.0 h1:DI8qLG5PEO0Mu1Oj51YFPqtx6I3qYXUAhJVJ/IzAVl0= +github.com/bufbuild/protocompile v0.9.0/go.mod h1:s89m1O8CqSYpyE/YaSGtg1r1YFMF5nLTwh4vlj6O444= github.com/cenkalti/backoff/v4 v4.2.1 h1:y4OZtCnogmCPw98Zjyt5a6+QwPLGkiQsYW5oUqylYbM= github.com/cenkalti/backoff/v4 v4.2.1/go.mod h1:Y3VNntkOUPxTVeUxJ/G5vcM//AlwfmyYozVcomhLiZE= github.com/coreos/go-systemd/v22 v22.5.0/go.mod h1:Y58oyj3AT4RCenI/lSvhwexgC+NSVTIJ3seZv2GcEnc= diff --git a/stub/stub.go b/stub/stub.go index beca1c8b..e7b3145d 100644 --- a/stub/stub.go +++ b/stub/stub.go @@ -2,9 +2,7 @@ package stub import ( "context" - "embed" "errors" - "io/fs" "net" "net/http" "time" @@ -14,6 +12,7 @@ import ( "github.com/rs/zerolog" "go.opentelemetry.io/contrib/instrumentation/github.com/gorilla/mux/otelmux" + gripmockui "github.com/bavix/gripmock-ui" "github.com/bavix/gripmock/internal/app" "github.com/bavix/gripmock/internal/domain/rest" "github.com/bavix/gripmock/internal/pkg/features" @@ -27,9 +26,6 @@ type Options struct { StubPath string } -//go:embed ui/dist -var staticFiles embed.FS - func RunRestServer(ctx context.Context, ch chan struct{}, opt Options, reflector *grpcreflector.GReflector) { const timeout = time.Millisecond * 25 @@ -37,13 +33,13 @@ func RunRestServer(ctx context.Context, ch chan struct{}, opt Options, reflector apiServer, _ := app.NewRestServer(opt.StubPath, reflector) - htmlContent, _ := fs.Sub(staticFiles, "ui/dist") + ui, _ := gripmockui.Assets() router := mux.NewRouter() router.Use(muxmiddleware.RequestLogger) router.Use(otelmux.Middleware("gripmock-manager")) - router.Handle("/", http.FileServer(http.FS(htmlContent))) rest.HandlerFromMuxWithBaseURL(apiServer, router, "/api") + router.PathPrefix("/").Handler(http.FileServerFS(ui)).Methods(http.MethodGet) srv := &http.Server{ Addr: addr, diff --git a/stub/ui b/stub/ui deleted file mode 160000 index 3b58939a..00000000 --- a/stub/ui +++ /dev/null @@ -1 +0,0 @@ -Subproject commit 3b58939a4a307424d4f4a4c9591443ae9a15c815