Skip to content

Commit

Permalink
Use go embed for web files and remove httptreemux (#382)
Browse files Browse the repository at this point in the history
- replace togo with go embed
- replace httptreemux with gin

closes #308
  • Loading branch information
anbraten committed Sep 29, 2021
1 parent a82d569 commit ed6d3f3
Show file tree
Hide file tree
Showing 26 changed files with 62 additions and 12,984 deletions.
8 changes: 3 additions & 5 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,9 @@
*.out

### Frontend ###
web/node_modules
web/dist/files
web/dist/**
!web/dist/.gitkeep
web/node_modules/
web/*.log
web/.env

Expand All @@ -40,6 +41,3 @@ server/swagger/files/*.json
server/swagger/swagger_gen.go

docs/venv

dist/
node_modules/
4 changes: 2 additions & 2 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ test-server:
$(DOCKER_RUN) go test -race -timeout 30s github.com/woodpecker-ci/woodpecker/cmd/server

test-frontend:
(cd web/; yarn run test)
(cd web/; yarn; yarn run test)

test-lib:
$(DOCKER_RUN) go test -race -timeout 30s $(shell go list ./... | grep -v '/cmd/')
Expand All @@ -60,7 +60,7 @@ build-server:
$(DOCKER_RUN) go build -o build/woodpecker-server github.com/woodpecker-ci/woodpecker/cmd/server

build-frontend:
(cd web/; yarn run build)
(cd web/; yarn; yarn run build)

build: build-agent build-server

Expand Down
6 changes: 3 additions & 3 deletions cmd/server/setup.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ import (
"fmt"
"time"

"github.com/gin-gonic/gin"
"github.com/woodpecker-ci/woodpecker/server"
"github.com/woodpecker-ci/woodpecker/server/model"
"github.com/woodpecker-ci/woodpecker/server/plugins/environments"
Expand All @@ -37,7 +38,6 @@ import (
"github.com/woodpecker-ci/woodpecker/server/store/datastore"
"github.com/woodpecker-ci/woodpecker/server/web"

"github.com/dimfeld/httptreemux"
"github.com/prometheus/client_golang/prometheus"
"github.com/prometheus/client_golang/prometheus/promauto"
"github.com/sirupsen/logrus"
Expand Down Expand Up @@ -201,8 +201,8 @@ func setupCoding(c *cli.Context) (remote.Remote, error) {
})
}

func setupTree(c *cli.Context) *httptreemux.ContextMux {
tree := httptreemux.NewContextMux()
func setupTree(c *cli.Context) *gin.Engine {
tree := gin.New()
web.New(
web.WithSync(time.Hour*72),
web.WithDocs(c.String("docs")),
Expand Down
1 change: 0 additions & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ require (
github.com/bmatcuk/doublestar/v4 v4.0.2
github.com/bradrydzewski/togo v0.0.0-20180401185031-50a0e4726e74 // indirect
github.com/containerd/containerd v1.5.5 // indirect
github.com/dimfeld/httptreemux v5.0.1+incompatible
github.com/docker/cli v0.0.0-20200303215952-eb310fca4956
github.com/docker/distribution v2.7.1+incompatible
github.com/docker/docker v20.10.8+incompatible
Expand Down
2 changes: 0 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -231,8 +231,6 @@ github.com/denverdino/aliyungo v0.0.0-20190125010748-a747050bb1ba/go.mod h1:dV8l
github.com/dgrijalva/jwt-go v0.0.0-20170104182250-a601269ab70c/go.mod h1:E3ru+11k8xSBh+hMPgOLZmtrrCbhqsmaPHjLKYnJCaQ=
github.com/dgrijalva/jwt-go v3.2.0+incompatible/go.mod h1:E3ru+11k8xSBh+hMPgOLZmtrrCbhqsmaPHjLKYnJCaQ=
github.com/dgryski/go-sip13 v0.0.0-20181026042036-e10d5fee7954/go.mod h1:vAd38F8PWV+bWy6jNmig1y/TA+kYO4g3RSRF0IAv0no=
github.com/dimfeld/httptreemux v5.0.1+incompatible h1:Qj3gVcDNoOthBAqftuD596rm4wg/adLLz5xh5CmpiCA=
github.com/dimfeld/httptreemux v5.0.1+incompatible/go.mod h1:rbUlSV+CCpv/SuqUTP/8Bk2O3LyUV436/yaRGkhP6Z0=
github.com/dnaeon/go-vcr v1.0.1/go.mod h1:aBB1+wY4s93YsC3HHjMBMrwTj2R9FHDzUr9KyGc8n1E=
github.com/docker/cli v0.0.0-20200303215952-eb310fca4956 h1:5/ZRsUbguX7xFNLlbxVQY/yhD3Psy+vylKZrNme5BJs=
github.com/docker/cli v0.0.0-20200303215952-eb310fca4956/go.mod h1:JLrzqnKDaYBop7H2jaqPtU4hHvMKP+vjCwu2uszcLI8=
Expand Down
18 changes: 9 additions & 9 deletions server/web/web.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,15 +25,15 @@ import (
"github.com/woodpecker-ci/woodpecker/server/model"
"github.com/woodpecker-ci/woodpecker/shared/token"
"github.com/woodpecker-ci/woodpecker/version"
"github.com/woodpecker-ci/woodpecker/web/dist"
"github.com/woodpecker-ci/woodpecker/web"

"github.com/dimfeld/httptreemux"
"github.com/gin-gonic/gin"
)

// Endpoint provides the website endpoints.
type Endpoint interface {
// Register registers the provider endpoints.
Register(*httptreemux.ContextMux)
Register(*gin.Engine)
}

// New returns the default website endpoint.
Expand All @@ -44,10 +44,10 @@ func New(opt ...Option) Endpoint {
}

return &website{
fs: dist.New(),
fs: web.HttpFS(),
opts: opts,
tmpl: mustCreateTemplate(
string(dist.MustLookup("/index.html")),
string(web.MustLookup("index.html")),
),
}
}
Expand All @@ -58,12 +58,12 @@ type website struct {
tmpl *template.Template
}

func (w *website) Register(mux *httptreemux.ContextMux) {
func (w *website) Register(mux *gin.Engine) {
h := http.FileServer(w.fs)
h = setupCache(h)
mux.Handler("GET", "/favicon.svg", h)
mux.Handler("GET", "/static/*filepath", h)
mux.NotFoundHandler = w.handleIndex
mux.GET("/favicon.svg", gin.WrapH(h))
mux.GET("/static/*filepath", gin.WrapH(h))
mux.NoRoute(gin.WrapF(w.handleIndex))
}

func (w *website) handleIndex(rw http.ResponseWriter, r *http.Request) {
Expand Down
23 changes: 0 additions & 23 deletions vendor/github.com/dimfeld/httptreemux/.gitignore

This file was deleted.

14 changes: 0 additions & 14 deletions vendor/github.com/dimfeld/httptreemux/.travis.yml

This file was deleted.

21 changes: 0 additions & 21 deletions vendor/github.com/dimfeld/httptreemux/LICENSE

This file was deleted.

Loading

0 comments on commit ed6d3f3

Please sign in to comment.