fix: Dockerfile should re-use bindata files when possible (#8176)
Reviewed-on: https://codeberg.org/forgejo/forgejo/pulls/8176 Reviewed-by: Michael Kriese <michael.kriese@gmx.de> Reviewed-by: Gusted <gusted@noreply.codeberg.org>
This commit is contained in:
		
				commit
				
					
						35e051aaee
					
				
			
		
					 5 changed files with 29 additions and 18 deletions
				
			
		| 
						 | 
					@ -37,13 +37,9 @@ coverage.all
 | 
				
			||||||
coverage/
 | 
					coverage/
 | 
				
			||||||
cpu.out
 | 
					cpu.out
 | 
				
			||||||
 | 
					
 | 
				
			||||||
/modules/migration/bindata.go
 | 
					 | 
				
			||||||
/modules/migration/bindata.go.hash
 | 
					/modules/migration/bindata.go.hash
 | 
				
			||||||
/modules/options/bindata.go
 | 
					 | 
				
			||||||
/modules/options/bindata.go.hash
 | 
					/modules/options/bindata.go.hash
 | 
				
			||||||
/modules/public/bindata.go
 | 
					 | 
				
			||||||
/modules/public/bindata.go.hash
 | 
					/modules/public/bindata.go.hash
 | 
				
			||||||
/modules/templates/bindata.go
 | 
					 | 
				
			||||||
/modules/templates/bindata.go.hash
 | 
					/modules/templates/bindata.go.hash
 | 
				
			||||||
 | 
					
 | 
				
			||||||
*.db
 | 
					*.db
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -33,10 +33,10 @@ RUN apk --no-cache add build-base git nodejs npm
 | 
				
			||||||
COPY . ${GOPATH}/src/forgejo.org
 | 
					COPY . ${GOPATH}/src/forgejo.org
 | 
				
			||||||
WORKDIR ${GOPATH}/src/forgejo.org
 | 
					WORKDIR ${GOPATH}/src/forgejo.org
 | 
				
			||||||
 | 
					
 | 
				
			||||||
RUN make clean
 | 
					RUN make clean-no-bindata
 | 
				
			||||||
RUN make frontend
 | 
					RUN make frontend
 | 
				
			||||||
RUN go build contrib/environment-to-ini/environment-to-ini.go && xx-verify environment-to-ini
 | 
					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 local files
 | 
				
			||||||
COPY docker/root /tmp/local
 | 
					COPY docker/root /tmp/local
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -33,10 +33,10 @@ RUN apk --no-cache add build-base git nodejs npm
 | 
				
			||||||
COPY . ${GOPATH}/src/forgejo.org
 | 
					COPY . ${GOPATH}/src/forgejo.org
 | 
				
			||||||
WORKDIR ${GOPATH}/src/forgejo.org
 | 
					WORKDIR ${GOPATH}/src/forgejo.org
 | 
				
			||||||
 | 
					
 | 
				
			||||||
RUN make clean
 | 
					RUN make clean-no-bindata
 | 
				
			||||||
RUN make frontend
 | 
					RUN make frontend
 | 
				
			||||||
RUN go build contrib/environment-to-ini/environment-to-ini.go && xx-verify environment-to-ini
 | 
					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 local files
 | 
				
			||||||
COPY docker/rootless /tmp/local
 | 
					COPY docker/rootless /tmp/local
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
							
								
								
									
										10
									
								
								Makefile
									
										
									
									
									
								
							
							
						
						
									
										10
									
								
								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 := public/assets/js/index.js public/assets/css/index.css
 | 
				
			||||||
WEBPACK_DEST_ENTRIES := public/assets/js public/assets/css public/assets/fonts
 | 
					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))
 | 
					BINDATA_HASH := $(addsuffix .hash,$(BINDATA_DEST))
 | 
				
			||||||
 | 
					
 | 
				
			||||||
GENERATED_GO_DEST := modules/charset/invisible_gen.go modules/charset/ambiguous_gen.go
 | 
					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
 | 
						rm -rf $(WEBPACK_DEST_ENTRIES) node_modules
 | 
				
			||||||
 | 
					
 | 
				
			||||||
.PHONY: clean
 | 
					.PHONY: clean
 | 
				
			||||||
clean:
 | 
					clean: clean-no-bindata
 | 
				
			||||||
	rm -rf $(EXECUTABLE) $(DIST) $(BINDATA_DEST) $(BINDATA_HASH) \
 | 
						rm -rf $(BINDATA_DEST) $(BINDATA_HASH)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					.PHONY: clean-no-bindata
 | 
				
			||||||
 | 
					clean-no-bindata:
 | 
				
			||||||
 | 
						rm -rf $(EXECUTABLE) $(DIST) \
 | 
				
			||||||
		integrations*.test \
 | 
							integrations*.test \
 | 
				
			||||||
		e2e*.test \
 | 
							e2e*.test \
 | 
				
			||||||
		tests/integration/gitea-integration-* \
 | 
							tests/integration/gitea-integration-* \
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -22,12 +22,19 @@ import (
 | 
				
			||||||
	"github.com/klauspost/compress/zstd"
 | 
						"github.com/klauspost/compress/zstd"
 | 
				
			||||||
)
 | 
					)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
func needsUpdate(dir, filename string) (bool, []byte) {
 | 
					func fileExists(filename string) bool {
 | 
				
			||||||
	needRegen := false
 | 
					 | 
				
			||||||
	_, err := os.Stat(filename)
 | 
						_, err := os.Stat(filename)
 | 
				
			||||||
	if err != nil {
 | 
						if err == nil {
 | 
				
			||||||
		needRegen = true
 | 
							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")
 | 
						oldHash, err := os.ReadFile(filename + ".hash")
 | 
				
			||||||
	if err != nil {
 | 
						if err != nil {
 | 
				
			||||||
| 
						 | 
					@ -73,10 +80,14 @@ func main() {
 | 
				
			||||||
		useGlobalModTime, _ = strconv.ParseBool(os.Args[4])
 | 
							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 {
 | 
						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
 | 
							return
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
| 
						 | 
					@ -113,7 +124,7 @@ type direntry struct {
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
func generate(fsRoot fs.FS, packageName string, globalTime bool, output io.Writer) error {
 | 
					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 {
 | 
						if err != nil {
 | 
				
			||||||
		return err
 | 
							return err
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue