Skip to content

Commit 5c2b57f

Browse files
committed
Migrate from bindata to go:embed
go:embed is part of the standard library and does not require an extra go:generate step. Migrate all usages of bindata to go:embed. Make embedded the new default (previously required bindata tag). Add new tag "servedynamic" which serves from filesystem (old !bindata). Accept-Encoding compression has been dropped. The assets in go:embed are not available in a compressed form. The compression could be enabled again by adding a compress middleware: https://github.com/vearutop/statigz Drop vfsgen dependency (no longer required). Fixes #17352 Signed-off-by: Christian Stewart <[email protected]>
1 parent 3adfc0f commit 5c2b57f

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

43 files changed

+280
-305
lines changed

.gitignore

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -36,15 +36,6 @@ _testmain.go
3636
coverage.all
3737
cpu.out
3838

39-
/modules/migration/bindata.go
40-
/modules/migration/bindata.go.hash
41-
/modules/options/bindata.go
42-
/modules/options/bindata.go.hash
43-
/modules/public/bindata.go
44-
/modules/public/bindata.go.hash
45-
/modules/templates/bindata.go
46-
/modules/templates/bindata.go.hash
47-
4839
*.db
4940
*.log
5041

Dockerfile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ ENV GOPROXY ${GOPROXY:-direct}
66

77
ARG GITEA_VERSION
88
ARG TAGS="sqlite sqlite_unlock_notify"
9-
ENV TAGS "bindata timetzdata $TAGS"
9+
ENV TAGS "timetzdata $TAGS"
1010
ARG CGO_EXTRA_CFLAGS
1111

1212
#Build deps

Dockerfile.rootless

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ ENV GOPROXY ${GOPROXY:-direct}
66

77
ARG GITEA_VERSION
88
ARG TAGS="sqlite sqlite_unlock_notify"
9-
ENV TAGS "bindata timetzdata $TAGS"
9+
ENV TAGS "timetzdata $TAGS"
1010
ARG CGO_EXTRA_CFLAGS
1111

1212
#Build deps
@@ -73,4 +73,3 @@ WORKDIR /var/lib/gitea
7373

7474
ENTRYPOINT ["/usr/bin/dumb-init", "--", "/usr/local/bin/docker-entrypoint.sh"]
7575
CMD []
76-

Makefile

Lines changed: 5 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -110,9 +110,6 @@ WEBPACK_CONFIGS := webpack.config.js
110110
WEBPACK_DEST := public/js/index.js public/css/index.css
111111
WEBPACK_DEST_ENTRIES := public/js public/css public/fonts public/img/webpack public/serviceworker.js
112112

113-
BINDATA_DEST := modules/public/bindata.go modules/options/bindata.go modules/templates/bindata.go
114-
BINDATA_HASH := $(addsuffix .hash,$(BINDATA_DEST))
115-
116113
GENERATED_GO_DEST := modules/charset/invisible_gen.go modules/charset/ambiguous_gen.go
117114

118115
SVG_DEST_DIR := public/img/svg
@@ -134,14 +131,8 @@ GO_DIRS := cmd tests models modules routers build services tools
134131
WEB_DIRS := web_src/js web_src/less
135132

136133
GO_SOURCES := $(wildcard *.go)
137-
GO_SOURCES += $(shell find $(GO_DIRS) -type f -name "*.go" -not -path modules/options/bindata.go -not -path modules/public/bindata.go -not -path modules/templates/bindata.go)
134+
GO_SOURCES += $(shell find $(GO_DIRS) -type f -name "*.go")
138135
GO_SOURCES += $(GENERATED_GO_DEST)
139-
GO_SOURCES_NO_BINDATA := $(GO_SOURCES)
140-
141-
ifeq ($(filter $(TAGS_SPLIT),bindata),bindata)
142-
GO_SOURCES += $(BINDATA_DEST)
143-
GENERATED_GO_DEST += $(BINDATA_DEST)
144-
endif
145136

146137
# Force installation of playwright dependencies by setting this flag
147138
ifdef DEPS_PLAYWRIGHT
@@ -253,7 +244,7 @@ clean-all: clean
253244
.PHONY: clean
254245
clean:
255246
$(GO) clean -i ./...
256-
rm -rf $(EXECUTABLE) $(DIST) $(BINDATA_DEST) $(BINDATA_HASH) \
247+
rm -rf $(EXECUTABLE) $(DIST) \
257248
integrations*.test \
258249
e2e*.test \
259250
tests/integration/gitea-integration-pgsql/ tests/integration/gitea-integration-mysql/ tests/integration/gitea-integration-mysql8/ tests/integration/gitea-integration-sqlite/ \
@@ -301,7 +292,7 @@ endif
301292
.PHONY: generate-swagger
302293
generate-swagger: $(SWAGGER_SPEC)
303294

304-
$(SWAGGER_SPEC): $(GO_SOURCES_NO_BINDATA)
295+
$(SWAGGER_SPEC): $(GO_SOURCES)
305296
$(GO) run $(SWAGGER_PACKAGE) generate spec -x "$(SWAGGER_EXCLUDE)" -o './$(SWAGGER_SPEC)'
306297
$(SED_INPLACE) '$(SWAGGER_SPEC_S_TMPL)' './$(SWAGGER_SPEC)'
307298
$(SED_INPLACE) $(SWAGGER_NEWLINE_COMMAND) './$(SWAGGER_SPEC)'
@@ -950,11 +941,11 @@ editorconfig-checker:
950941
.PHONY: docker
951942
docker:
952943
docker build --disable-content-trust=false -t $(DOCKER_REF) .
953-
# support also build args docker build --build-arg GITEA_VERSION=v1.2.3 --build-arg TAGS="bindata sqlite sqlite_unlock_notify" .
944+
# support also build args docker build --build-arg GITEA_VERSION=v1.2.3 --build-arg TAGS="sqlite sqlite_unlock_notify" .
954945

955946
.PHONY: docker-build
956947
docker-build:
957-
docker run -ti --rm -v "$(CURDIR):/srv/app/src/code.gitea.io/gitea" -w /srv/app/src/code.gitea.io/gitea -e TAGS="bindata $(TAGS)" LDFLAGS="$(LDFLAGS)" CGO_EXTRA_CFLAGS="$(CGO_EXTRA_CFLAGS)" webhippie/golang:edge make clean build
948+
docker run -ti --rm -v "$(CURDIR):/srv/app/src/code.gitea.io/gitea" -w /srv/app/src/code.gitea.io/gitea -e TAGS="$(TAGS)" LDFLAGS="$(LDFLAGS)" CGO_EXTRA_CFLAGS="$(CGO_EXTRA_CFLAGS)" webhippie/golang:edge make clean build
958949

959950
# This endif closes the if at the top of the file
960951
endif

README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -71,11 +71,11 @@ This project has been
7171

7272
From the root of the source tree, run:
7373

74-
TAGS="bindata" make build
74+
make build
7575

7676
or if SQLite support is required:
7777

78-
TAGS="bindata sqlite sqlite_unlock_notify" make build
78+
TAGS="sqlite sqlite_unlock_notify" make build
7979

8080
The `build` target is split into two sub-targets:
8181

build.go

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
// Copyright 2020 The Gitea Authors. All rights reserved.
22
// SPDX-License-Identifier: MIT
33

4-
54
//go:build vendor
65

76
package main
@@ -10,9 +9,6 @@ package main
109
// These libraries will not be included in a normal compilation.
1110

1211
import (
13-
// for embed
14-
_ "github.com/shurcooL/vfsgen"
15-
1612
// for cover merge
1713
_ "golang.org/x/tools/cover"
1814

build/code-batch-process.go

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,6 @@ func newFileCollector(fileFilter string, batchSize int) (*fileCollector, error)
6969
}
7070
co.includePatterns = append(co.includePatterns, regexp.MustCompile(`.*\.go$`))
7171

72-
co.excludePatterns = append(co.excludePatterns, regexp.MustCompile(`.*\bbindata\.go$`))
7372
co.excludePatterns = append(co.excludePatterns, regexp.MustCompile(`tests/gitea-repositories-meta`))
7473
co.excludePatterns = append(co.excludePatterns, regexp.MustCompile(`tests/integration/migration-test`))
7574
co.excludePatterns = append(co.excludePatterns, regexp.MustCompile(`modules/git/tests`))

build/generate-bindata.go

Lines changed: 0 additions & 92 deletions
This file was deleted.

cmd/embedded.go

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
// Copyright 2020 The Gitea Authors. All rights reserved.
22
// SPDX-License-Identifier: MIT
33

4-
//go:build bindata
4+
//go:build !servedynamic
55

66
package cmd
77

@@ -89,8 +89,7 @@ var (
8989
},
9090
}
9191

92-
sections map[string]*section
93-
assets []asset
92+
assets []asset
9493
)
9594

9695
type section struct {
@@ -227,7 +226,7 @@ func runExtractDo(c *cli.Context) error {
227226
if err != nil {
228227
return fmt.Errorf("%s: %s", destdir, err)
229228
} else if !fi.IsDir() {
230-
return fmt.Errorf("%s is not a directory.", destdir)
229+
return fmt.Errorf("%s is not a directory", destdir)
231230
}
232231

233232
fmt.Printf("Extracting to %s:\n", destdir)
@@ -324,11 +323,11 @@ func getPatterns(args []string) ([]glob.Glob, error) {
324323
}
325324
pat := make([]glob.Glob, len(args))
326325
for i := range args {
327-
if g, err := glob.Compile(args[i], '/'); err != nil {
326+
g, err := glob.Compile(args[i], '/')
327+
if err != nil {
328328
return nil, fmt.Errorf("'%s': Invalid glob pattern: %w", args[i], err)
329-
} else {
330-
pat[i] = g
331329
}
330+
pat[i] = g
332331
}
333332
return pat, nil
334333
}

cmd/embedded_stub.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
// Copyright 2020 The Gitea Authors. All rights reserved.
22
// SPDX-License-Identifier: MIT
33

4-
//go:build !bindata
4+
//go:build servedynamic
55

66
package cmd
77

@@ -23,7 +23,7 @@ var (
2323
)
2424

2525
func extractorNotImplemented(c *cli.Context) error {
26-
err := fmt.Errorf("Sorry: the 'embedded' subcommand is not available in builds without bindata")
26+
err := fmt.Errorf("Sorry: the 'embedded' subcommand is not available in servedynamic builds")
2727
fmt.Fprintf(os.Stderr, "%s\n", err)
2828
return err
2929
}

0 commit comments

Comments
 (0)