Skip to content

Commit

Permalink
Use go embed for web files and remove httptreemux (#382) (#489)
Browse files Browse the repository at this point in the history
* Use go embed for web files and remove httptreemux (#382)

- replace togo with go embed
- replace httptreemux with gin

closes #308

* adapt

* ajust & cleanup

Co-authored-by: Anbraten <anton@ju60.de>
  • Loading branch information
6543 and anbraten committed Oct 28, 2021
1 parent dff4491 commit 96155a4
Show file tree
Hide file tree
Showing 28 changed files with 65 additions and 13,084 deletions.
5 changes: 3 additions & 2 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 Down
44 changes: 1 addition & 43 deletions .woodpecker/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,14 +8,12 @@ pipeline:
group: test
commands:
- make test
# - make vet
# - make formatcheck

test-frontend:
image: node:10.17.0-stretch
group: test
commands:
- (cd web/; yarn install)
- (cd web/; yarn install --frozen-lockfile)
- (cd web/; yarn run lesshint)
- (cd web/; yarn run lint --quiet)
- make test-frontend
Expand Down Expand Up @@ -46,20 +44,8 @@ pipeline:
build:
image: golang:1.16
commands:
- go get github.com/woodpecker-ci/togo
- (cd web/; go generate ./...)
- make release

# publish-server-alpine:
# image: plugins/docker
# repo: woodpeckerci/woodpecker-server
# dockerfile: Dockerfile.alpine
# secrets: [ docker_username, docker_password ]
# tag: [ alpine ]
# when:
# branch: master
# event: push

build-cli:
image: golang:1.16
commands: make release-cli
Expand All @@ -83,34 +69,6 @@ pipeline:
branch: release/v0.14
event: push

# publish-agent-alpine:
# image: plugins/docker
# repo: woodpeckerci/woodpecker-agent
# dockerfile: Dockerfile.agent.alpine
# secrets: [ docker_username, docker_password ]
# tag: [ alpine ]
# when:
# branch: master
# event: push

# release-server-alpine:
# image: plugins/docker
# repo: woodpeckerci/woodpecker-server
# dockerfile: Dockerfile.alpine
# secrets: [ docker_username, docker_password ]
# tag: "${DRONE_TAG}-alpine"
# when:
# event: tag
#
# release-agent-alpine:
# image: plugins/docker
# repo: woodpeckerci/woodpecker-agent
# dockerfile: Dockerfile.agent.alpine
# secrets: [ docker_username, docker_password ]
# tag: "${DRONE_TAG}-alpine"
# when:
# event: tag

release-server:
image: plugins/docker
repo: woodpeckerci/woodpecker-server
Expand Down
12 changes: 6 additions & 6 deletions cmd/drone-server/setup.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,12 @@ import (
"fmt"
"time"

"github.com/dimfeld/httptreemux"
"github.com/gin-gonic/gin"
"github.com/prometheus/client_golang/prometheus"
"github.com/prometheus/client_golang/prometheus/promauto"
"github.com/urfave/cli"
"golang.org/x/sync/errgroup"

"github.com/woodpecker-ci/woodpecker/cncd/queue"
"github.com/woodpecker-ci/woodpecker/model"
"github.com/woodpecker-ci/woodpecker/plugins/environments"
Expand All @@ -39,9 +42,6 @@ import (
"github.com/woodpecker-ci/woodpecker/server/web"
"github.com/woodpecker-ci/woodpecker/store"
"github.com/woodpecker-ci/woodpecker/store/datastore"
"golang.org/x/sync/errgroup"

"github.com/urfave/cli"
)

func setupStore(c *cli.Context) store.Store {
Expand Down Expand Up @@ -206,8 +206,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.WithDir(c.String("www")),
web.WithSync(time.Hour*72),
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/Microsoft/go-winio v0.4.15-0.20190919025122-fc70bd9a86b5 // indirect
github.com/bmatcuk/doublestar/v4 v4.0.2
github.com/cpuguy83/go-md2man/v2 v2.0.0 // 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 v17.12.0-ce-rc1.0.20200309214505-aa6a9891b09c+incompatible
Expand Down
2 changes: 0 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,6 @@ github.com/creack/pty v1.1.9/go.mod h1:oKZEueFk5CKHvIhNR5MUki03XCEU+Q6VDXinZuGJ3
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=
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/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=
github.com/docker/distribution v2.7.1+incompatible h1:a5mlkVzth6W5A4fOsS3D2EO5BUmsJpcB+cRlLU7cSug=
Expand Down
3 changes: 1 addition & 2 deletions router/router.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@ package router
import (
"net/http"

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

"github.com/woodpecker-ci/woodpecker/router/middleware/header"
Expand All @@ -30,7 +29,7 @@ import (
)

// Load loads the router
func Load(mux *httptreemux.ContextMux, middleware ...gin.HandlerFunc) http.Handler {
func Load(mux *gin.Engine, middleware ...gin.HandlerFunc) http.Handler {

e := gin.New()
e.Use(gin.Recovery())
Expand Down
18 changes: 9 additions & 9 deletions server/web/web.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,15 +27,15 @@ import (
"github.com/woodpecker-ci/woodpecker/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 @@ -50,10 +50,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 @@ -77,12 +77,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 96155a4

Please sign in to comment.