From c21d27135887739df19e063a099bd59f95c8d36d Mon Sep 17 00:00:00 2001 From: Earl Warren Date: Fri, 13 Jun 2025 08:25:18 +0200 Subject: [PATCH 1/2] Revert "fix: use zstd.WithLowerEncoderMem for generate-bindata (#8172)" This reverts commit 402a85a9b629ea540ce49d53de321289d35449ee. --- build/generate-bindata.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/build/generate-bindata.go b/build/generate-bindata.go index fd4ae7d29e..2bdfc39574 100644 --- a/build/generate-bindata.go +++ b/build/generate-bindata.go @@ -113,7 +113,7 @@ type direntry struct { } func generate(fsRoot fs.FS, packageName string, globalTime bool, output io.Writer) error { - enc, err := zstd.NewWriter(nil, zstd.WithLowerEncoderMem(true)) + enc, err := zstd.NewWriter(nil, zstd.WithEncoderLevel(zstd.SpeedBestCompression)) if err != nil { return err } From fd2f9e684223cf44137e44a0f13b24ccfcbdf2ec Mon Sep 17 00:00:00 2001 From: Earl Warren Date: Fri, 13 Jun 2025 08:22:54 +0200 Subject: [PATCH 2/2] fix: Dockerfile should re-use bindata files when possible - Revert "fix: use zstd.WithLowerEncoderMem for generate-bindata - Re-use bindata files when available instead of ignoring them in Dockerfile - Add missing modules/migration/bindata.go to go sources in the Makefile Closes forgejo/forgejo#8165 --- .dockerignore | 4 ---- Dockerfile | 4 ++-- Dockerfile.rootless | 4 ++-- Makefile | 10 +++++++--- build/generate-bindata.go | 23 +++++++++++++++++------ 5 files changed, 28 insertions(+), 17 deletions(-) diff --git a/.dockerignore b/.dockerignore index 5e7a893014..807c70b000 100644 --- a/.dockerignore +++ b/.dockerignore @@ -37,13 +37,9 @@ coverage.all coverage/ 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 diff --git a/Dockerfile b/Dockerfile index a94f4d2b46..397e97acb1 100644 --- a/Dockerfile +++ b/Dockerfile @@ -33,10 +33,10 @@ RUN apk --no-cache add build-base git nodejs npm COPY . ${GOPATH}/src/forgejo.org WORKDIR ${GOPATH}/src/forgejo.org -RUN make clean +RUN make clean-no-bindata RUN make frontend RUN go build contrib/environment-to-ini/environment-to-ini.go && xx-verify environment-to-ini -RUN LDFLAGS="-buildid=" make RELEASE_VERSION=$RELEASE_VERSION GOFLAGS="-trimpath" go-check generate-backend static-executable && xx-verify gitea +RUN LDFLAGS="-buildid=" make FORGEJO_GENERATE_SKIP_HASH=true RELEASE_VERSION=$RELEASE_VERSION GOFLAGS="-trimpath" go-check generate-backend static-executable && xx-verify gitea # Copy local files COPY docker/root /tmp/local diff --git a/Dockerfile.rootless b/Dockerfile.rootless index 36df26c042..9ee71f64e0 100644 --- a/Dockerfile.rootless +++ b/Dockerfile.rootless @@ -33,10 +33,10 @@ RUN apk --no-cache add build-base git nodejs npm COPY . ${GOPATH}/src/forgejo.org WORKDIR ${GOPATH}/src/forgejo.org -RUN make clean +RUN make clean-no-bindata RUN make frontend RUN go build contrib/environment-to-ini/environment-to-ini.go && xx-verify environment-to-ini -RUN make RELEASE_VERSION=$RELEASE_VERSION go-check generate-backend static-executable && xx-verify gitea +RUN make FORGEJO_GENERATE_SKIP_HASH=true RELEASE_VERSION=$RELEASE_VERSION go-check generate-backend static-executable && xx-verify gitea # Copy local files COPY docker/rootless /tmp/local diff --git a/Makefile b/Makefile index 9774200b06..e0e6e12ed4 100644 --- a/Makefile +++ b/Makefile @@ -129,7 +129,7 @@ WEBPACK_CONFIGS := webpack.config.js tailwind.config.js WEBPACK_DEST := public/assets/js/index.js public/assets/css/index.css WEBPACK_DEST_ENTRIES := public/assets/js public/assets/css public/assets/fonts -BINDATA_DEST := modules/public/bindata.go modules/options/bindata.go modules/templates/bindata.go +BINDATA_DEST := modules/migration/bindata.go 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 @@ -325,8 +325,12 @@ clean-all: clean rm -rf $(WEBPACK_DEST_ENTRIES) node_modules .PHONY: clean -clean: - rm -rf $(EXECUTABLE) $(DIST) $(BINDATA_DEST) $(BINDATA_HASH) \ +clean: clean-no-bindata + rm -rf $(BINDATA_DEST) $(BINDATA_HASH) + +.PHONY: clean-no-bindata +clean-no-bindata: + rm -rf $(EXECUTABLE) $(DIST) \ integrations*.test \ e2e*.test \ tests/integration/gitea-integration-* \ diff --git a/build/generate-bindata.go b/build/generate-bindata.go index 2bdfc39574..67d3776847 100644 --- a/build/generate-bindata.go +++ b/build/generate-bindata.go @@ -22,12 +22,19 @@ import ( "github.com/klauspost/compress/zstd" ) -func needsUpdate(dir, filename string) (bool, []byte) { - needRegen := false +func fileExists(filename string) bool { _, err := os.Stat(filename) - if err != nil { - needRegen = true + if err == nil { + return true } + if os.IsNotExist(err) { + return false + } + panic(err) +} + +func needsUpdate(dir, filename string) (bool, []byte) { + needRegen := !fileExists(filename) oldHash, err := os.ReadFile(filename + ".hash") if err != nil { @@ -73,10 +80,14 @@ func main() { useGlobalModTime, _ = strconv.ParseBool(os.Args[4]) } - update, newHash := needsUpdate(dir, filename) + if os.Getenv("FORGEJO_GENERATE_SKIP_HASH") == "true" && fileExists(filename) { + fmt.Printf("bindata %s already exists and FORGEJO_GENERATE_SKIP_HASH=true\n", packageName) + return + } + update, newHash := needsUpdate(dir, filename) if !update { - fmt.Printf("bindata for %s already up-to-date\n", packageName) + fmt.Printf("bindata %s already exists and the checksum is a match\n", packageName) return }