diff --git a/.gitignore b/.gitignore index 1ce2a87611e81..c293959b4d66d 100644 --- a/.gitignore +++ b/.gitignore @@ -36,15 +36,6 @@ _testmain.go coverage.all cpu.out -/modules/migration/bindata.go -/modules/migration/bindata.go.hash -/modules/options/bindata.go -/modules/options/bindata.go.hash -/modules/public/bindata.go -/modules/public/bindata.go.hash -/modules/templates/bindata.go -/modules/templates/bindata.go.hash - *.db *.log diff --git a/Dockerfile b/Dockerfile index fad8ae1790d52..205faf268b8fe 100644 --- a/Dockerfile +++ b/Dockerfile @@ -6,7 +6,7 @@ ENV GOPROXY ${GOPROXY:-direct} ARG GITEA_VERSION ARG TAGS="sqlite sqlite_unlock_notify" -ENV TAGS "bindata timetzdata $TAGS" +ENV TAGS "timetzdata $TAGS" ARG CGO_EXTRA_CFLAGS #Build deps diff --git a/Dockerfile.rootless b/Dockerfile.rootless index 98051f7ddba74..123598d90e7d4 100644 --- a/Dockerfile.rootless +++ b/Dockerfile.rootless @@ -6,7 +6,7 @@ ENV GOPROXY ${GOPROXY:-direct} ARG GITEA_VERSION ARG TAGS="sqlite sqlite_unlock_notify" -ENV TAGS "bindata timetzdata $TAGS" +ENV TAGS "timetzdata $TAGS" ARG CGO_EXTRA_CFLAGS #Build deps @@ -73,4 +73,3 @@ WORKDIR /var/lib/gitea ENTRYPOINT ["/usr/bin/dumb-init", "--", "/usr/local/bin/docker-entrypoint.sh"] CMD [] - diff --git a/Makefile b/Makefile index 717d7cafc660b..2e7596bb60b57 100644 --- a/Makefile +++ b/Makefile @@ -110,9 +110,6 @@ WEBPACK_CONFIGS := webpack.config.js WEBPACK_DEST := public/js/index.js public/css/index.css WEBPACK_DEST_ENTRIES := public/js public/css public/fonts public/img/webpack public/serviceworker.js -BINDATA_DEST := modules/public/bindata.go modules/options/bindata.go modules/templates/bindata.go -BINDATA_HASH := $(addsuffix .hash,$(BINDATA_DEST)) - GENERATED_GO_DEST := modules/charset/invisible_gen.go modules/charset/ambiguous_gen.go SVG_DEST_DIR := public/img/svg @@ -134,14 +131,8 @@ GO_DIRS := cmd tests models modules routers build services tools WEB_DIRS := web_src/js web_src/less GO_SOURCES := $(wildcard *.go) -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) +GO_SOURCES += $(shell find $(GO_DIRS) -type f -name "*.go") GO_SOURCES += $(GENERATED_GO_DEST) -GO_SOURCES_NO_BINDATA := $(GO_SOURCES) - -ifeq ($(filter $(TAGS_SPLIT),bindata),bindata) - GO_SOURCES += $(BINDATA_DEST) - GENERATED_GO_DEST += $(BINDATA_DEST) -endif # Force installation of playwright dependencies by setting this flag ifdef DEPS_PLAYWRIGHT @@ -253,7 +244,7 @@ clean-all: clean .PHONY: clean clean: $(GO) clean -i ./... - rm -rf $(EXECUTABLE) $(DIST) $(BINDATA_DEST) $(BINDATA_HASH) \ + rm -rf $(EXECUTABLE) $(DIST) \ integrations*.test \ e2e*.test \ 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 .PHONY: generate-swagger generate-swagger: $(SWAGGER_SPEC) -$(SWAGGER_SPEC): $(GO_SOURCES_NO_BINDATA) +$(SWAGGER_SPEC): $(GO_SOURCES) $(GO) run $(SWAGGER_PACKAGE) generate spec -x "$(SWAGGER_EXCLUDE)" -o './$(SWAGGER_SPEC)' $(SED_INPLACE) '$(SWAGGER_SPEC_S_TMPL)' './$(SWAGGER_SPEC)' $(SED_INPLACE) $(SWAGGER_NEWLINE_COMMAND) './$(SWAGGER_SPEC)' @@ -950,11 +941,11 @@ editorconfig-checker: .PHONY: docker docker: docker build --disable-content-trust=false -t $(DOCKER_REF) . -# support also build args docker build --build-arg GITEA_VERSION=v1.2.3 --build-arg TAGS="bindata sqlite sqlite_unlock_notify" . +# support also build args docker build --build-arg GITEA_VERSION=v1.2.3 --build-arg TAGS="sqlite sqlite_unlock_notify" . .PHONY: docker-build docker-build: - 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 + 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 # This endif closes the if at the top of the file endif diff --git a/README.md b/README.md index 29d5371a3684e..394c7d6f283ad 100644 --- a/README.md +++ b/README.md @@ -71,11 +71,11 @@ This project has been From the root of the source tree, run: - TAGS="bindata" make build + make build or if SQLite support is required: - TAGS="bindata sqlite sqlite_unlock_notify" make build + TAGS="sqlite sqlite_unlock_notify" make build The `build` target is split into two sub-targets: diff --git a/build.go b/build.go index d2e724a7f70c5..2dbf8acf38dbc 100644 --- a/build.go +++ b/build.go @@ -1,7 +1,6 @@ // Copyright 2020 The Gitea Authors. All rights reserved. // SPDX-License-Identifier: MIT - //go:build vendor package main @@ -10,9 +9,6 @@ package main // These libraries will not be included in a normal compilation. import ( - // for embed - _ "github.com/shurcooL/vfsgen" - // for cover merge _ "golang.org/x/tools/cover" diff --git a/build/code-batch-process.go b/build/code-batch-process.go index 9cc47442b2252..2a71bb95aab4a 100644 --- a/build/code-batch-process.go +++ b/build/code-batch-process.go @@ -69,7 +69,6 @@ func newFileCollector(fileFilter string, batchSize int) (*fileCollector, error) } co.includePatterns = append(co.includePatterns, regexp.MustCompile(`.*\.go$`)) - co.excludePatterns = append(co.excludePatterns, regexp.MustCompile(`.*\bbindata\.go$`)) co.excludePatterns = append(co.excludePatterns, regexp.MustCompile(`tests/gitea-repositories-meta`)) co.excludePatterns = append(co.excludePatterns, regexp.MustCompile(`tests/integration/migration-test`)) co.excludePatterns = append(co.excludePatterns, regexp.MustCompile(`modules/git/tests`)) diff --git a/build/generate-bindata.go b/build/generate-bindata.go deleted file mode 100644 index 2fcb7c2f2a088..0000000000000 --- a/build/generate-bindata.go +++ /dev/null @@ -1,92 +0,0 @@ -// Copyright 2020 The Gitea Authors. All rights reserved. -// SPDX-License-Identifier: MIT - -//go:build ignore - -package main - -import ( - "bytes" - "crypto/sha1" - "fmt" - "log" - "net/http" - "os" - "path/filepath" - "strconv" - - "github.com/shurcooL/vfsgen" -) - -func needsUpdate(dir, filename string) (bool, []byte) { - needRegen := false - _, err := os.Stat(filename) - if err != nil { - needRegen = true - } - - oldHash, err := os.ReadFile(filename + ".hash") - if err != nil { - oldHash = []byte{} - } - - hasher := sha1.New() - - err = filepath.WalkDir(dir, func(path string, d os.DirEntry, err error) error { - if err != nil { - return err - } - info, err := d.Info() - if err != nil { - return err - } - _, _ = hasher.Write([]byte(d.Name())) - _, _ = hasher.Write([]byte(info.ModTime().String())) - _, _ = hasher.Write([]byte(strconv.FormatInt(info.Size(), 16))) - return nil - }) - if err != nil { - return true, oldHash - } - - newHash := hasher.Sum([]byte{}) - - if bytes.Compare(oldHash, newHash) != 0 { - return true, newHash - } - - return needRegen, newHash -} - -func main() { - if len(os.Args) < 4 { - log.Fatal("Insufficient number of arguments. Need: directory packageName filename") - } - - dir, packageName, filename := os.Args[1], os.Args[2], os.Args[3] - var useGlobalModTime bool - if len(os.Args) == 5 { - useGlobalModTime, _ = strconv.ParseBool(os.Args[4]) - } - - update, newHash := needsUpdate(dir, filename) - - if !update { - fmt.Printf("bindata for %s already up-to-date\n", packageName) - return - } - - fmt.Printf("generating bindata for %s\n", packageName) - var fsTemplates http.FileSystem = http.Dir(dir) - err := vfsgen.Generate(fsTemplates, vfsgen.Options{ - PackageName: packageName, - BuildTags: "bindata", - VariableName: "Assets", - Filename: filename, - UseGlobalModTime: useGlobalModTime, - }) - if err != nil { - log.Fatalf("%v\n", err) - } - _ = os.WriteFile(filename+".hash", newHash, 0o666) -} diff --git a/cmd/embedded.go b/cmd/embedded.go index d87fc0187c70d..697c04500ca57 100644 --- a/cmd/embedded.go +++ b/cmd/embedded.go @@ -1,7 +1,7 @@ // Copyright 2020 The Gitea Authors. All rights reserved. // SPDX-License-Identifier: MIT -//go:build bindata +//go:build !servedynamic package cmd @@ -89,8 +89,7 @@ var ( }, } - sections map[string]*section - assets []asset + assets []asset ) type section struct { @@ -227,7 +226,7 @@ func runExtractDo(c *cli.Context) error { if err != nil { return fmt.Errorf("%s: %s", destdir, err) } else if !fi.IsDir() { - return fmt.Errorf("%s is not a directory.", destdir) + return fmt.Errorf("%s is not a directory", destdir) } fmt.Printf("Extracting to %s:\n", destdir) @@ -324,11 +323,11 @@ func getPatterns(args []string) ([]glob.Glob, error) { } pat := make([]glob.Glob, len(args)) for i := range args { - if g, err := glob.Compile(args[i], '/'); err != nil { + g, err := glob.Compile(args[i], '/') + if err != nil { return nil, fmt.Errorf("'%s': Invalid glob pattern: %w", args[i], err) - } else { - pat[i] = g } + pat[i] = g } return pat, nil } diff --git a/cmd/embedded_stub.go b/cmd/embedded_stub.go index 874df06f9d7fc..b61a7086ffb9a 100644 --- a/cmd/embedded_stub.go +++ b/cmd/embedded_stub.go @@ -1,7 +1,7 @@ // Copyright 2020 The Gitea Authors. All rights reserved. // SPDX-License-Identifier: MIT -//go:build !bindata +//go:build servedynamic package cmd @@ -23,7 +23,7 @@ var ( ) func extractorNotImplemented(c *cli.Context) error { - err := fmt.Errorf("Sorry: the 'embedded' subcommand is not available in builds without bindata") + err := fmt.Errorf("Sorry: the 'embedded' subcommand is not available in servedynamic builds") fmt.Fprintf(os.Stderr, "%s\n", err) return err } diff --git a/docs/content/doc/developers/hacking-on-gitea.en-us.md b/docs/content/doc/developers/hacking-on-gitea.en-us.md index 3283240c980e6..abd309ba245c5 100644 --- a/docs/content/doc/developers/hacking-on-gitea.en-us.md +++ b/docs/content/doc/developers/hacking-on-gitea.en-us.md @@ -81,7 +81,7 @@ One of these three distributions of Make will run on Windows: - 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`. - [Chocolatey package](https://chocolatey.org/packages/make). Run `choco install make` -**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`. +**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`. ## Downloading and cloning the Gitea source code @@ -128,10 +128,10 @@ from source. The simplest recommended way to build from source is: ```bash -TAGS="bindata sqlite sqlite_unlock_notify" make build +TAGS="sqlite sqlite_unlock_notify" make build ``` -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. +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. 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. @@ -299,7 +299,7 @@ Unit tests are covered by `*_test.go` in `go test` system. 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). ```bash -TAGS="bindata sqlite sqlite_unlock_notify" make test # Runs the unit tests +TAGS="sqlite sqlite_unlock_notify" make test # Runs the unit tests ``` ### Integration Tests @@ -308,7 +308,7 @@ Unit tests will not and cannot completely test Gitea alone. Therefore, we have written integration tests; however, these are database dependent. ```bash -TAGS="bindata sqlite sqlite_unlock_notify" make build test-sqlite +TAGS="sqlite sqlite_unlock_notify" make build test-sqlite ``` will run the integration tests in an SQLite environment. Integration tests diff --git a/docs/content/doc/installation/from-source.en-us.md b/docs/content/doc/installation/from-source.en-us.md index ae3ddc5c41864..79c4cc797f6fc 100644 --- a/docs/content/doc/installation/from-source.en-us.md +++ b/docs/content/doc/installation/from-source.en-us.md @@ -94,7 +94,7 @@ are provided to keep the build process as simple as possible. Depending on requirements, the following build tags can be included. -- `bindata`: Build a single monolithic binary, with all assets included. Required for production build. +- `servedynamic`: Read files from the filesystem instead of embedded. - `sqlite sqlite_unlock_notify`: Enable support for a [SQLite3](https://sqlite.org/) database. Suggested only for tiny installations. @@ -103,21 +103,19 @@ Depending on requirements, the following build tags can be included. available to PAM. - `gogit`: (EXPERIMENTAL) Use go-git variants of Git commands. -Bundling all assets (JS/CSS/templates, etc) into the binary. Using the `bindata` build tag is required for -production deployments. You could exclude `bindata` when you are developing/testing Gitea or able to separate the assets correctly. - -To include all assets, use the `bindata` tag: +You could use tag `servedynamic` when you are developing/testing Gitea to serve +assets from the filesystem instead of the embedded versions. ```bash -TAGS="bindata" make build +make build ``` In the default release build of our continuous integration system, the build -tags are: `TAGS="bindata sqlite sqlite_unlock_notify"`. The simplest +tags are: `TAGS="sqlite sqlite_unlock_notify"`. The simplest recommended way to build from source is therefore: ```bash -TAGS="bindata sqlite sqlite_unlock_notify" make build +TAGS="sqlite sqlite_unlock_notify" make build ``` The `build` target is split into two sub-targets: @@ -128,7 +126,7 @@ The `build` target is split into two sub-targets: If pre-built frontend files are present it is possible to only build the backend: ```bash -TAGS="bindata" make backend +make backend ``` ## Test @@ -181,7 +179,7 @@ GOOS=linux GOARCH=arm64 make build Cross-build Gitea for Linux ARM64, with recommended build tags: ``` -CC=aarch64-unknown-linux-gnu-gcc GOOS=linux GOARCH=arm64 TAGS="bindata sqlite sqlite_unlock_notify" make build +CC=aarch64-unknown-linux-gnu-gcc GOOS=linux GOARCH=arm64 TAGS="sqlite sqlite_unlock_notify" make build ``` Replace `CC`, `GOOS`, and `GOARCH` as appropriate for your architecture target. diff --git a/docs/content/doc/usage/command-line.en-us.md b/docs/content/doc/usage/command-line.en-us.md index 70efebd203618..3ecd35bf359d3 100644 --- a/docs/content/doc/usage/command-line.en-us.md +++ b/docs/content/doc/usage/command-line.en-us.md @@ -28,7 +28,7 @@ menu: All global options can be placed at the command level. - `--help`, `-h`: Show help text and exit. Optional. -- `--version`, `-v`: Show version and exit. Optional. (example: `Gitea version 1.1.0+218-g7b907ed built with: bindata, sqlite`). +- `--version`, `-v`: Show version and exit. Optional. (example: `Gitea version 1.1.0+218-g7b907ed built with: sqlite`). - `--custom-path path`, `-C path`: Location of the Gitea custom folder. Optional. (default: `AppWorkPath`/custom or `$GITEA_CUSTOM`). - `--config path`, `-c path`: Gitea configuration file path. Optional. (default: `custom`/conf/app.ini). - `--work-path path`, `-w path`: Gitea `AppWorkPath`. Optional. (default: LOCATION_OF_GITEA_BINARY or `$GITEA_WORK_DIR`) diff --git a/go.mod b/go.mod index f003d444b403d..42d77a383b7c7 100644 --- a/go.mod +++ b/go.mod @@ -91,7 +91,6 @@ require ( github.com/quasoft/websspi v1.1.2 github.com/santhosh-tekuri/jsonschema/v5 v5.1.1 github.com/sergi/go-diff v1.2.0 - github.com/shurcooL/vfsgen v0.0.0-20200824052919-0d455de96546 github.com/stretchr/testify v1.8.1 github.com/syndtr/goleveldb v1.0.0 github.com/tstranex/u2f v1.0.0 @@ -246,7 +245,6 @@ require ( github.com/rs/xid v1.4.0 // indirect github.com/russross/blackfriday/v2 v2.1.0 // indirect github.com/shopspring/decimal v1.2.0 // indirect - github.com/shurcooL/httpfs v0.0.0-20190707220628-8d4bc4ba7749 // indirect github.com/sirupsen/logrus v1.9.0 // indirect github.com/skeema/knownhosts v1.1.0 // indirect github.com/spf13/afero v1.8.2 // indirect @@ -282,8 +280,6 @@ require ( replace github.com/hashicorp/go-version => github.com/6543/go-version v1.3.1 -replace github.com/shurcooL/vfsgen => github.com/lunny/vfsgen v0.0.0-20220105142115-2c99e1ffdfa0 - replace github.com/blevesearch/zapx/v15 v15.3.6 => github.com/zeripath/zapx/v15 v15.3.6-alignment-fix replace github.com/nektos/act => gitea.com/gitea/act v0.234.2-0.20230131074955-e46ede1b1744 diff --git a/go.sum b/go.sum index 7eb420b02b03a..967c1e6323dd5 100644 --- a/go.sum +++ b/go.sum @@ -867,8 +867,6 @@ github.com/lightstep/lightstep-tracer-common/golang/gogo v0.0.0-20190605223551-b github.com/lightstep/lightstep-tracer-go v0.18.1/go.mod h1:jlF1pusYV4pidLvZ+XD0UBX0ZE6WURAspgAczcDHrL4= github.com/lunny/log v0.0.0-20160921050905-7887c61bf0de/go.mod h1:3q8WtuPQsoRbatJuy3nvq/hRSvuBJrHHr+ybPPiNvHQ= github.com/lunny/nodb v0.0.0-20160621015157-fc1ef06ad4af/go.mod h1:Cqz6pqow14VObJ7peltM+2n3PWOz7yTrfUuGbVFkzN0= -github.com/lunny/vfsgen v0.0.0-20220105142115-2c99e1ffdfa0 h1:F/3FfGmKdiKFa8kL3YrpZ7pe9H4l4AzA1pbaOUnRvPI= -github.com/lunny/vfsgen v0.0.0-20220105142115-2c99e1ffdfa0/go.mod h1:JEfTc3+2DF9Z4PXhLLvXL42zexJyh8rIq3OzUj/0rAk= github.com/lyft/protoc-gen-validate v0.0.13/go.mod h1:XbGvPuh87YZc5TdIa2/I4pLk0QoUACkjt2znoq26NVQ= github.com/magiconair/properties v1.8.0/go.mod h1:PppfXfuXeibc/6YijjN8zIbojt8czPbwD3XqdrwzmxQ= github.com/magiconair/properties v1.8.6 h1:5ibWZ6iY0NctNGWo87LalDlEZ6R41TqbbDamhfG/Qzo= @@ -1138,8 +1136,6 @@ github.com/shopspring/decimal v0.0.0-20180709203117-cd690d0c9e24/go.mod h1:M+9Nz github.com/shopspring/decimal v0.0.0-20200227202807-02e2044944cc/go.mod h1:DKyhrW/HYNuLGql+MJL6WCR6knT2jwCFRcu2hWCYk4o= github.com/shopspring/decimal v1.2.0 h1:abSATXmQEYyShuxI4/vyW3tV1MrKAJzCZ/0zLUXYbsQ= github.com/shopspring/decimal v1.2.0/go.mod h1:DKyhrW/HYNuLGql+MJL6WCR6knT2jwCFRcu2hWCYk4o= -github.com/shurcooL/httpfs v0.0.0-20190707220628-8d4bc4ba7749 h1:bUGsEnyNbVPw06Bs80sCeARAlK8lhwqGyi6UT8ymuGk= -github.com/shurcooL/httpfs v0.0.0-20190707220628-8d4bc4ba7749/go.mod h1:ZY1cvUeJuFPAdZ/B6v7RHavJWZn2YPVFQ1OSXhCGOkg= github.com/shurcooL/sanitized_anchor_name v1.0.0/go.mod h1:1NzhyTcUVG4SuEtjjoZeVRXNmyL/1OwPU0+IJeTBvfc= github.com/siddontang/go v0.0.0-20180604090527-bdc77568d726/go.mod h1:3yhqj7WBBfRhbBlzyOC3gUxftwsU0u8gqevxwIHQpMw= github.com/siddontang/go-snappy v0.0.0-20140704025258-d8f7bb82a96d/go.mod h1:vq0tzqLRu6TS7Id0wMo2N5QzJoKedVeovOpHjnykSzY= diff --git a/modules/migration/schemas/schemas.go b/modules/migration/schemas/schemas.go new file mode 100644 index 0000000000000..fb62f0d1cff21 --- /dev/null +++ b/modules/migration/schemas/schemas.go @@ -0,0 +1,13 @@ +// Copyright 2022 The Gitea Authors. All rights reserved. +// SPDX-License-Identifier: MIT + +//go:build !servedynamic + +package schemas + +import "embed" + +// SchemasFS contains the schema files. +// +//go:embed *.json +var SchemasFS embed.FS diff --git a/modules/migration/schemas/schemas_servedynamic.go b/modules/migration/schemas/schemas_servedynamic.go new file mode 100644 index 0000000000000..364644261a264 --- /dev/null +++ b/modules/migration/schemas/schemas_servedynamic.go @@ -0,0 +1,6 @@ +// Copyright 2022 The Gitea Authors. All rights reserved. +// SPDX-License-Identifier: MIT + +//go:build servedynamic + +package schemas diff --git a/modules/migration/schemas_bindata.go b/modules/migration/schemas_bindata.go deleted file mode 100644 index c5db3b3461510..0000000000000 --- a/modules/migration/schemas_bindata.go +++ /dev/null @@ -1,8 +0,0 @@ -// Copyright 2022 The Gitea Authors. All rights reserved. -// SPDX-License-Identifier: MIT - -//go:build bindata - -package migration - -//go:generate go run ../../build/generate-bindata.go ../../modules/migration/schemas migration bindata.go diff --git a/modules/migration/schemas_dynamic.go b/modules/migration/schemas_dynamic.go index dca109d6afc87..bab8897c9079f 100644 --- a/modules/migration/schemas_dynamic.go +++ b/modules/migration/schemas_dynamic.go @@ -1,7 +1,7 @@ // Copyright 2022 The Gitea Authors. All rights reserved. // SPDX-License-Identifier: MIT -//go:build !bindata +//go:build servedynamic package migration diff --git a/modules/migration/schemas_static.go b/modules/migration/schemas_static.go index 8a0c340a65583..0ef0514fa4a1a 100644 --- a/modules/migration/schemas_static.go +++ b/modules/migration/schemas_static.go @@ -1,15 +1,17 @@ // Copyright 2022 The Gitea Authors. All rights reserved. // SPDX-License-Identifier: MIT -//go:build bindata +//go:build !servedynamic package migration import ( "io" "path" + + "code.gitea.io/gitea/modules/migration/schemas" ) func openSchema(filename string) (io.ReadCloser, error) { - return Assets.Open(path.Base(filename)) + return schemas.SchemasFS.Open(path.Base(filename)) } diff --git a/modules/options/dynamic.go b/modules/options/dynamic.go index a20253676e671..009acdbef9c5c 100644 --- a/modules/options/dynamic.go +++ b/modules/options/dynamic.go @@ -1,7 +1,7 @@ // Copyright 2016 The Gitea Authors. All rights reserved. // SPDX-License-Identifier: MIT -//go:build !bindata +//go:build servedynamic package options @@ -122,7 +122,7 @@ func fileFromDir(name string) ([]byte, error) { return []byte{}, fmt.Errorf("Asset file does not exist: %s", name) } -// IsDynamic will return false when using embedded data (-tags bindata) +// IsDynamic will return false when using embedded data. func IsDynamic() bool { return true } diff --git a/modules/options/options_bindata.go b/modules/options/options_bindata.go deleted file mode 100644 index 29151cb3cbc42..0000000000000 --- a/modules/options/options_bindata.go +++ /dev/null @@ -1,8 +0,0 @@ -// Copyright 2020 The Gitea Authors. All rights reserved. -// SPDX-License-Identifier: MIT - -//go:build bindata - -package options - -//go:generate go run ../../build/generate-bindata.go ../../options options bindata.go diff --git a/modules/options/static.go b/modules/options/static.go index ff3c86d3f84f6..027899f8fed3b 100644 --- a/modules/options/static.go +++ b/modules/options/static.go @@ -1,7 +1,7 @@ // Copyright 2022 The Gitea Authors. All rights reserved. // SPDX-License-Identifier: MIT -//go:build bindata +//go:build !servedynamic package options @@ -16,11 +16,12 @@ import ( "code.gitea.io/gitea/modules/log" "code.gitea.io/gitea/modules/setting" "code.gitea.io/gitea/modules/util" + "code.gitea.io/gitea/options" ) var directories = make(directorySet) -// Dir returns all files from bindata or custom directory. +// Dir returns all files from embedded assets or custom directory. func Dir(name string) ([]string, error) { if directories.Filled(name) { return directories.Get(name), nil @@ -52,24 +53,10 @@ func Dir(name string) ([]string, error) { } func AssetDir(dirName string) ([]string, error) { - d, err := Assets.Open(dirName) - if err != nil { - return nil, err - } - defer d.Close() - - files, err := d.Readdir(-1) - if err != nil { - return nil, err - } - results := make([]string, 0, len(files)) - for _, file := range files { - results = append(results, file.Name()) - } - return results, nil + return options.AssetDir(dirName) } -// Locale reads the content of a specific locale from bindata or custom path. +// Locale reads the content of a specific locale from embedded assets or custom path. func Locale(name string) ([]byte, error) { return fileFromDir(path.Join("locale", name)) } @@ -82,17 +69,17 @@ func WalkLocales(callback func(path, name string, d fs.DirEntry, err error) erro return nil } -// Readme reads the content of a specific readme from bindata or custom path. +// Readme reads the content of a specific readme from embedded assets or custom path. func Readme(name string) ([]byte, error) { return fileFromDir(path.Join("readme", name)) } -// Gitignore reads the content of a gitignore locale from bindata or custom path. +// Gitignore reads the content of a gitignore locale from embedded assets or custom path. func Gitignore(name string) ([]byte, error) { return fileFromDir(path.Join("gitignore", name)) } -// License reads the content of a specific license from bindata or custom path. +// License reads the content of a specific license from embedded assets or custom path. func License(name string) ([]byte, error) { return fileFromDir(path.Join("license", name)) } @@ -102,7 +89,7 @@ func Labels(name string) ([]byte, error) { return fileFromDir(path.Join("label", name)) } -// fileFromDir is a helper to read files from bindata or custom path. +// fileFromDir is a helper to read files from embedded assets or custom path. func fileFromDir(name string) ([]byte, error) { customPath := path.Join(setting.CustomPath, "options", name) @@ -114,7 +101,7 @@ func fileFromDir(name string) ([]byte, error) { return os.ReadFile(customPath) } - f, err := Assets.Open(name) + f, err := options.OptionsFS.Open(name) if err != nil { return nil, err } @@ -124,7 +111,7 @@ func fileFromDir(name string) ([]byte, error) { } func Asset(name string) ([]byte, error) { - f, err := Assets.Open("/" + name) + f, err := options.OptionsFS.Open(name) if err != nil { return nil, err } @@ -133,28 +120,23 @@ func Asset(name string) ([]byte, error) { } func AssetNames() []string { - realFS := Assets.(vfsgen۰FS) - results := make([]string, 0, len(realFS)) - for k := range realFS { - results = append(results, k[1:]) - } - return results + return options.AssetNames() } func AssetIsDir(name string) (bool, error) { - if f, err := Assets.Open("/" + name); err != nil { + f, err := options.OptionsFS.Open(name) + if err != nil { + return false, err + } + defer f.Close() + fi, err := f.Stat() + if err != nil { return false, err - } else { - defer f.Close() - if fi, err := f.Stat(); err != nil { - return false, err - } else { - return fi.IsDir(), nil - } } + return fi.IsDir(), nil } -// IsDynamic will return false when using embedded data (-tags bindata) +// IsDynamic will return false when using embedded data. func IsDynamic() bool { return false } diff --git a/modules/public/public_bindata.go b/modules/public/public_bindata.go deleted file mode 100644 index 4878f88ad1d9a..0000000000000 --- a/modules/public/public_bindata.go +++ /dev/null @@ -1,8 +0,0 @@ -// Copyright 2020 The Gitea Authors. All rights reserved. -// SPDX-License-Identifier: MIT - -//go:build bindata - -package public - -//go:generate go run ../../build/generate-bindata.go ../../public public bindata.go true diff --git a/modules/public/serve_dynamic.go b/modules/public/serve_dynamic.go index cd74ee574366c..d1a0769909923 100644 --- a/modules/public/serve_dynamic.go +++ b/modules/public/serve_dynamic.go @@ -1,17 +1,26 @@ // Copyright 2016 The Gitea Authors. All rights reserved. // SPDX-License-Identifier: MIT -//go:build !bindata +//go:build servedynamic package public import ( + "errors" "io" "net/http" "os" "time" ) +func Asset(name string) ([]byte, error) { + return nil, errors.New("assets are not built-in when servedynamic tag is enabled") +} + +func AssetNames() []string { + return nil +} + func fileSystem(dir string) http.FileSystem { return http.Dir(dir) } diff --git a/modules/public/serve_static.go b/modules/public/serve_static.go index e85ca79253f74..3ea3786cf4888 100644 --- a/modules/public/serve_static.go +++ b/modules/public/serve_static.go @@ -1,50 +1,39 @@ // Copyright 2016 The Gitea Authors. All rights reserved. // SPDX-License-Identifier: MIT -//go:build bindata +//go:build !servedynamic package public import ( - "bytes" "io" "net/http" "os" - "path/filepath" "time" "code.gitea.io/gitea/modules/timeutil" + "code.gitea.io/gitea/public" ) -// GlobalModTime provide a global mod time for embedded asset files -func GlobalModTime(filename string) time.Time { - return timeutil.GetExecutableModTime() +func Asset(name string) ([]byte, error) { + return public.Asset(name) } -func fileSystem(dir string) http.FileSystem { - return Assets +func AssetNames() []string { + return public.AssetNames() } -func Asset(name string) ([]byte, error) { - f, err := Assets.Open("/" + name) - if err != nil { - return nil, err - } - defer f.Close() - return io.ReadAll(f) +// GlobalModTime provide a global mod time for embedded asset files +func GlobalModTime(filename string) time.Time { + return timeutil.GetExecutableModTime() } -func AssetNames() []string { - realFS := Assets.(vfsgen۰FS) - results := make([]string, 0, len(realFS)) - for k := range realFS { - results = append(results, k[1:]) - } - return results +func fileSystem(dir string) http.FileSystem { + return http.FS(&public.PublicFS) } func AssetIsDir(name string) (bool, error) { - if f, err := Assets.Open("/" + name); err != nil { + if f, err := public.PublicFS.Open(name); err != nil { return false, err } else { defer f.Close() @@ -58,23 +47,6 @@ func AssetIsDir(name string) (bool, error) { // serveContent serve http content func serveContent(w http.ResponseWriter, req *http.Request, fi os.FileInfo, modtime time.Time, content io.ReadSeeker) { - encodings := parseAcceptEncoding(req.Header.Get("Accept-Encoding")) - if encodings.Contains("gzip") { - if cf, ok := fi.(*vfsgen۰CompressedFileInfo); ok { - rdGzip := bytes.NewReader(cf.GzipBytes()) - // all static files are managed by Gitea, so we can make sure every file has the correct ext name - // then we can get the correct Content-Type, we do not need to do http.DetectContentType on the decompressed data - mimeType := detectWellKnownMimeType(filepath.Ext(fi.Name())) - if mimeType == "" { - mimeType = "application/octet-stream" - } - w.Header().Set("Content-Type", mimeType) - w.Header().Set("Content-Encoding", "gzip") - http.ServeContent(w, req, fi.Name(), modtime, rdGzip) - return - } - } - http.ServeContent(w, req, fi.Name(), modtime, content) return } diff --git a/modules/svg/discover_bindata.go b/modules/svg/discover_bindata.go index b6abd294f17d4..8541d7de8df5e 100644 --- a/modules/svg/discover_bindata.go +++ b/modules/svg/discover_bindata.go @@ -1,17 +1,17 @@ // Copyright 2020 The Gitea Authors. All rights reserved. // SPDX-License-Identifier: MIT -//go:build bindata +//go:build !servedynamic package svg import ( "path/filepath" - "code.gitea.io/gitea/modules/public" + "code.gitea.io/gitea/public" ) -// Discover returns a map of discovered SVG icons in bindata +// Discover returns a map of discovered SVG icons in embedded assets. func Discover() map[string]string { svgs := make(map[string]string) diff --git a/modules/svg/discover_nobindata.go b/modules/svg/discover_nobindata.go index da7ab7b98f5de..c873d63e49bd6 100644 --- a/modules/svg/discover_nobindata.go +++ b/modules/svg/discover_nobindata.go @@ -1,7 +1,7 @@ // Copyright 2020 The Gitea Authors. All rights reserved. // SPDX-License-Identifier: MIT -//go:build !bindata +//go:build servedynamic package svg diff --git a/modules/templates/dynamic.go b/modules/templates/dynamic.go index 7d25a61fedfd9..10f26d7c04277 100644 --- a/modules/templates/dynamic.go +++ b/modules/templates/dynamic.go @@ -1,7 +1,7 @@ // Copyright 2016 The Gitea Authors. All rights reserved. // SPDX-License-Identifier: MIT -//go:build !bindata +//go:build servedynamic package templates diff --git a/modules/templates/static.go b/modules/templates/static.go index 7ebb327ae6ebd..4ea544bf8674e 100644 --- a/modules/templates/static.go +++ b/modules/templates/static.go @@ -1,7 +1,7 @@ // Copyright 2016 The Gitea Authors. All rights reserved. // SPDX-License-Identifier: MIT -//go:build bindata +//go:build !servedynamic package templates @@ -18,6 +18,7 @@ import ( "code.gitea.io/gitea/modules/setting" "code.gitea.io/gitea/modules/timeutil" + "code.gitea.io/gitea/templates" ) var ( @@ -61,15 +62,13 @@ func walkTemplateFiles(callback func(path, name string, d fs.DirEntry, err error return nil } -// GetTemplateAssetNames only for chi func GetTemplateAssetNames() []string { - realFS := Assets.(vfsgen۰FS) - tmpls := make([]string, 0, len(realFS)) - for k := range realFS { - if strings.HasPrefix(k, "/mail/") { + var tmpls []string + for _, k := range templates.AssetNames() { + if strings.HasPrefix(k, "mail/") { continue } - tmpls = append(tmpls, "templates/"+k[1:]) + tmpls = append(tmpls, path.Join("templates", k)) } customDir := path.Join(setting.CustomPath, "templates") @@ -86,7 +85,7 @@ func walkMailerTemplates(callback func(path, name string, d fs.DirEntry, err err // BuiltinAsset reads the provided asset from the builtin embedded assets func BuiltinAsset(name string) ([]byte, error) { - f, err := Assets.Open("/" + name) + f, err := templates.TemplatesFS.Open(name) if err != nil { return nil, err } @@ -96,24 +95,19 @@ func BuiltinAsset(name string) ([]byte, error) { // BuiltinAssetNames returns the names of the built-in embedded assets func BuiltinAssetNames() []string { - realFS := Assets.(vfsgen۰FS) - results := make([]string, 0, len(realFS)) - for k := range realFS { - results = append(results, k[1:]) - } - return results + return templates.AssetNames() } // BuiltinAssetIsDir returns if a provided asset is a directory func BuiltinAssetIsDir(name string) (bool, error) { - if f, err := Assets.Open("/" + name); err != nil { + f, err := templates.TemplatesFS.Open(name) + if err != nil { + return false, err + } + defer f.Close() + fi, err := f.Stat() + if err != nil { return false, err - } else { - defer f.Close() - if fi, err := f.Stat(); err != nil { - return false, err - } else { - return fi.IsDir(), nil - } } + return fi.IsDir(), nil } diff --git a/modules/templates/templates_bindata.go b/modules/templates/templates_bindata.go deleted file mode 100644 index 6f1d3cf539590..0000000000000 --- a/modules/templates/templates_bindata.go +++ /dev/null @@ -1,8 +0,0 @@ -// Copyright 2016 The Gitea Authors. All rights reserved. -// SPDX-License-Identifier: MIT - -//go:build bindata - -package templates - -//go:generate go run ../../build/generate-bindata.go ../../templates templates bindata.go true diff --git a/options/options.go b/options/options.go new file mode 100644 index 0000000000000..47886c64306d6 --- /dev/null +++ b/options/options.go @@ -0,0 +1,44 @@ +// Copyright 2022 The Gitea Authors. All rights reserved. +// SPDX-License-Identifier: MIT + +//go:build !servedynamic +// +build !servedynamic + +package options + +import ( + "embed" + "io/fs" +) + +// OptionsFS contains the options definitions. +// +//go:embed gitignore label license locale readme +var OptionsFS embed.FS + +func Asset(name string) ([]byte, error) { + return fs.ReadFile(OptionsFS, name) +} + +func AssetNames() []string { + var results []string + _ = fs.WalkDir(OptionsFS, ".", func(path string, d fs.DirEntry, err error) error { + if d.Type().IsRegular() { + results = append(results, path) + } + return nil + }) + return results +} + +func AssetDir(dirName string) ([]string, error) { + files, err := fs.ReadDir(OptionsFS, dirName) + if err != nil { + return nil, err + } + results := make([]string, 0, len(files)) + for _, file := range files { + results = append(results, file.Name()) + } + return results, nil +} diff --git a/options/options_servedynamic.go b/options/options_servedynamic.go new file mode 100644 index 0000000000000..c215262269bc6 --- /dev/null +++ b/options/options_servedynamic.go @@ -0,0 +1,7 @@ +// Copyright 2022 The Gitea Authors. All rights reserved. +// SPDX-License-Identifier: MIT + +//go:build servedynamic +// +build servedynamic + +package options diff --git a/public/css/README b/public/css/README new file mode 100644 index 0000000000000..aa645f6034f95 --- /dev/null +++ b/public/css/README @@ -0,0 +1,3 @@ +CSS files will be generated in this directory. + +Run "make frontend" to build these files. diff --git a/public/fonts/README b/public/fonts/README new file mode 100644 index 0000000000000..8befd3786778d --- /dev/null +++ b/public/fonts/README @@ -0,0 +1,3 @@ +Font files will be generated in this directory. + +Run "make frontend" to build these files. diff --git a/public/js/README b/public/js/README new file mode 100644 index 0000000000000..150e7a22a3f83 --- /dev/null +++ b/public/js/README @@ -0,0 +1,3 @@ +JS files will be generated in this directory. + +Run "make frontend" to build these files. diff --git a/public/placeholder.js b/public/placeholder.js new file mode 100644 index 0000000000000..705a7c02e5797 --- /dev/null +++ b/public/placeholder.js @@ -0,0 +1,2 @@ +// This file prevents a build error when no js files are present in this +// directory. This happens if "go build" is run before "make frontend." diff --git a/public/public.go b/public/public.go new file mode 100644 index 0000000000000..fa5909f040177 --- /dev/null +++ b/public/public.go @@ -0,0 +1,31 @@ +// Copyright 2022 The Gitea Authors. All rights reserved. +// SPDX-License-Identifier: MIT + +//go:build !servedynamic + +package public + +import ( + "embed" + "io/fs" +) + +// PublicFS contains the public assets filesystem. +// +//go:embed css fonts img js vendor *.js +var PublicFS embed.FS + +func Asset(name string) ([]byte, error) { + return fs.ReadFile(PublicFS, name) +} + +func AssetNames() []string { + var results []string + _ = fs.WalkDir(PublicFS, ".", func(path string, d fs.DirEntry, err error) error { + if d.Type().IsRegular() { + results = append(results, path) + } + return nil + }) + return results +} diff --git a/public/public_servedynamic.go b/public/public_servedynamic.go new file mode 100644 index 0000000000000..b35867b0442e8 --- /dev/null +++ b/public/public_servedynamic.go @@ -0,0 +1,6 @@ +// Copyright 2022 The Gitea Authors. All rights reserved. +// SPDX-License-Identifier: MIT + +//go:build servedynamic + +package public diff --git a/public/vendor/README b/public/vendor/README new file mode 100644 index 0000000000000..9abfd75dbb8d3 --- /dev/null +++ b/public/vendor/README @@ -0,0 +1,3 @@ +vendor library files will be generated in this directory. + +Run "make frontend" to build these files. diff --git a/snap/snapcraft.yaml b/snap/snapcraft.yaml index 25494bde23985..2e91b8e99d076 100644 --- a/snap/snapcraft.yaml +++ b/snap/snapcraft.yaml @@ -49,7 +49,7 @@ parts: - LDFLAGS: "" override-pull: | snapcraftctl pull - + last_committed_tag="$(git for-each-ref --sort=taggerdate --format '%(tag)' refs/tags | tail -n 1)" last_released_tag="$(snap info gitea | awk '$1 == "latest/candidate:" { print $2 }')" # If the latest tag from the upstream project has not been released to @@ -57,7 +57,7 @@ parts: if [ "${last_committed_tag}" != "${last_released_tag}" ]; then git fetch git checkout "${last_committed_tag}" - fi + fi version="$(git describe --always | sed -e 's/-/+git/;y/-/./')" [ -n "$(echo $version | grep "+git")" ] && grade=devel || grade=stable @@ -67,7 +67,7 @@ parts: override-build: | set -x sed -i 's/os.Getuid()/1/g' modules/setting/setting.go - TAGS="bindata sqlite sqlite_unlock_notify pam cert" make build + TAGS="sqlite sqlite_unlock_notify pam cert" make build install -D gitea "${SNAPCRAFT_PART_INSTALL}/gitea" cp -r options "${SNAPCRAFT_PART_INSTALL}/" diff --git a/templates/templates.go b/templates/templates.go new file mode 100644 index 0000000000000..02500668ea939 --- /dev/null +++ b/templates/templates.go @@ -0,0 +1,48 @@ +// Copyright 2022 The Gitea Authors. All rights reserved. +// SPDX-License-Identifier: MIT + +//go:build !servedynamic + +package templates + +import ( + "embed" + "io/fs" +) + +// TemplatesFS contains the embedded templates. +// +//go:embed admin api base code custom explore mail swagger +//go:embed org package projects repo shared status user +//go:embed *.tmpl +var TemplatesFS embed.FS + +func Asset(name string) ([]byte, error) { + if name[0] == '/' { + name = name[1:] + } + return fs.ReadFile(TemplatesFS, name) +} + +func AssetNames() []string { + var results []string + _ = fs.WalkDir(TemplatesFS, ".", func(path string, d fs.DirEntry, err error) error { + if d.Type().IsRegular() { + results = append(results, path) + } + return nil + }) + return results +} + +func AssetDir(dirName string) ([]string, error) { + files, err := fs.ReadDir(TemplatesFS, dirName) + if err != nil { + return nil, err + } + results := make([]string, 0, len(files)) + for _, file := range files { + results = append(results, file.Name()) + } + return results, nil +} diff --git a/templates/templates_servedynamic.go b/templates/templates_servedynamic.go new file mode 100644 index 0000000000000..2996e953ce107 --- /dev/null +++ b/templates/templates_servedynamic.go @@ -0,0 +1,6 @@ +// Copyright 2022 The Gitea Authors. All rights reserved. +// SPDX-License-Identifier: MIT + +//go:build servedynamic + +package templates