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 <christian@paral.in>
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
}

docs/content/doc/developers/hacking-on-gitea.en-us.md

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,7 @@ One of these three distributions of Make will run on Windows:
8181
- To compile Gitea with CGO_ENABLED (eg: SQLite3), you might need to use [tdm-gcc](https://jmeubank.github.io/tdm-gcc/) instead of MSYS2 gcc, because MSYS2 gcc headers lack some Windows-only CRT functions like `_beginthread`.
8282
- [Chocolatey package](https://chocolatey.org/packages/make). Run `choco install make`
8383

84-
**Note**: If you are attempting to build using make with Windows Command Prompt, you may run into issues. The above prompts (Git bash, or MinGW) are recommended, however if you only have command prompt (or potentially PowerShell) you can set environment variables using the [set](https://docs.microsoft.com/en-us/windows-server/administration/windows-commands/set_1) command, e.g. `set TAGS=bindata`.
84+
**Note**: If you are attempting to build using make with Windows Command Prompt, you may run into issues. The above prompts (Git bash, or MinGW) are recommended, however if you only have command prompt (or potentially PowerShell) you can set environment variables using the [set](https://docs.microsoft.com/en-us/windows-server/administration/windows-commands/set_1) command, e.g. `set TAGS=servedynamic`.
8585

8686
## Downloading and cloning the Gitea source code
8787

@@ -128,10 +128,10 @@ from source</a>.
128128
The simplest recommended way to build from source is:
129129

130130
```bash
131-
TAGS="bindata sqlite sqlite_unlock_notify" make build
131+
TAGS="sqlite sqlite_unlock_notify" make build
132132
```
133133

134-
The `build` target will execute both `frontend` and `backend` sub-targets. If the `bindata` tag is present, the frontend files will be compiled into the binary. It is recommended to leave out the tag when doing frontend development so that changes will be reflected.
134+
The `build` target will execute both `frontend` and `backend` sub-targets. If the `servedynamic` tag is present, the frontend files will not be compiled into the binary. It is recommended to set `servedynamic` tag when doing frontend development so that changes will be reflected.
135135

136136
See `make help` for all available `make` targets. Also see [`.drone.yml`](https://github.com/go-gitea/gitea/blob/main/.drone.yml) to see how our continuous integration works.
137137

@@ -299,7 +299,7 @@ Unit tests are covered by `*_test.go` in `go test` system.
299299
You can set the environment variable `GITEA_UNIT_TESTS_LOG_SQL=1` to display all SQL statements when running the tests in verbose mode (i.e. when `GOTESTFLAGS=-v` is set).
300300

301301
```bash
302-
TAGS="bindata sqlite sqlite_unlock_notify" make test # Runs the unit tests
302+
TAGS="sqlite sqlite_unlock_notify" make test # Runs the unit tests
303303
```
304304

305305
### Integration Tests
@@ -308,7 +308,7 @@ Unit tests will not and cannot completely test Gitea alone. Therefore, we
308308
have written integration tests; however, these are database dependent.
309309

310310
```bash
311-
TAGS="bindata sqlite sqlite_unlock_notify" make build test-sqlite
311+
TAGS="sqlite sqlite_unlock_notify" make build test-sqlite
312312
```
313313

314314
will run the integration tests in an SQLite environment. Integration tests

docs/content/doc/installation/from-source.en-us.md

Lines changed: 8 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -94,7 +94,7 @@ are provided to keep the build process as simple as possible.
9494

9595
Depending on requirements, the following build tags can be included.
9696

97-
- `bindata`: Build a single monolithic binary, with all assets included. Required for production build.
97+
- `servedynamic`: Read files from the filesystem instead of embedded.
9898
- `sqlite sqlite_unlock_notify`: Enable support for a
9999
[SQLite3](https://sqlite.org/) database. Suggested only for tiny
100100
installations.
@@ -103,21 +103,19 @@ Depending on requirements, the following build tags can be included.
103103
available to PAM.
104104
- `gogit`: (EXPERIMENTAL) Use go-git variants of Git commands.
105105

106-
Bundling all assets (JS/CSS/templates, etc) into the binary. Using the `bindata` build tag is required for
107-
production deployments. You could exclude `bindata` when you are developing/testing Gitea or able to separate the assets correctly.
108-
109-
To include all assets, use the `bindata` tag:
106+
You could use tag `servedynamic` when you are developing/testing Gitea to serve
107+
assets from the filesystem instead of the embedded versions.
110108

111109
```bash
112-
TAGS="bindata" make build
110+
make build
113111
```
114112

115113
In the default release build of our continuous integration system, the build
116-
tags are: `TAGS="bindata sqlite sqlite_unlock_notify"`. The simplest
114+
tags are: `TAGS="sqlite sqlite_unlock_notify"`. The simplest
117115
recommended way to build from source is therefore:
118116

119117
```bash
120-
TAGS="bindata sqlite sqlite_unlock_notify" make build
118+
TAGS="sqlite sqlite_unlock_notify" make build
121119
```
122120

123121
The `build` target is split into two sub-targets:
@@ -128,7 +126,7 @@ The `build` target is split into two sub-targets:
128126
If pre-built frontend files are present it is possible to only build the backend:
129127

130128
```bash
131-
TAGS="bindata" make backend
129+
make backend
132130
```
133131

134132
## Test
@@ -181,7 +179,7 @@ GOOS=linux GOARCH=arm64 make build
181179
Cross-build Gitea for Linux ARM64, with recommended build tags:
182180

183181
```
184-
CC=aarch64-unknown-linux-gnu-gcc GOOS=linux GOARCH=arm64 TAGS="bindata sqlite sqlite_unlock_notify" make build
182+
CC=aarch64-unknown-linux-gnu-gcc GOOS=linux GOARCH=arm64 TAGS="sqlite sqlite_unlock_notify" make build
185183
```
186184

187185
Replace `CC`, `GOOS`, and `GOARCH` as appropriate for your architecture target.

docs/content/doc/usage/command-line.en-us.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ menu:
2828
All global options can be placed at the command level.
2929

3030
- `--help`, `-h`: Show help text and exit. Optional.
31-
- `--version`, `-v`: Show version and exit. Optional. (example: `Gitea version 1.1.0+218-g7b907ed built with: bindata, sqlite`).
31+
- `--version`, `-v`: Show version and exit. Optional. (example: `Gitea version 1.1.0+218-g7b907ed built with: sqlite`).
3232
- `--custom-path path`, `-C path`: Location of the Gitea custom folder. Optional. (default: `AppWorkPath`/custom or `$GITEA_CUSTOM`).
3333
- `--config path`, `-c path`: Gitea configuration file path. Optional. (default: `custom`/conf/app.ini).
3434
- `--work-path path`, `-w path`: Gitea `AppWorkPath`. Optional. (default: LOCATION_OF_GITEA_BINARY or `$GITEA_WORK_DIR`)

0 commit comments

Comments
 (0)