build: enable go toolchain download on docker images (#9837)

This ensures we use the right go toolchain on docker build even if there is an older image already cached.

Tested manually:
- `docker buildx build --progress plain  -f Dockerfile.rootless .` currently is up-to-date
- change `build-env` image to `golang:1.24-alpine3.22` and run again: see `go: downloading go1.25.3 (linux/amd64)` in output

```diff
diff --git a/Dockerfile.rootless b/Dockerfile.rootless
index 2dbcd6ddd2..8c6ac5f266 100644
--- a/Dockerfile.rootless
+++ b/Dockerfile.rootless
@@ -1,6 +1,6 @@
 FROM --platform=$BUILDPLATFORM data.forgejo.org/oci/xx AS xx

-FROM --platform=$BUILDPLATFORM data.forgejo.org/oci/golang:1.25-alpine3.22 AS build-env
+FROM --platform=$BUILDPLATFORM data.forgejo.org/oci/golang:1.24-alpine3.22 AS build-env

 ARG GOPROXY
 ENV GOPROXY=${GOPROXY:-https://proxy.golang.org,direct}
@@ -10,10 +10,13 @@ ARG TAGS="sqlite sqlite_unlock_notify"
 ENV TAGS="bindata timetzdata $TAGS"
 ARG CGO_EXTRA_CFLAGS

+RUN go env
+
 # it's set to local by default in the base image
 # we want to use auto to let go choose the right toolchain
 ENV GOTOOLCHAIN=auto

+
 #
 # Transparently cross compile for the target platform
 #
@@ -37,6 +40,9 @@ RUN apk --no-cache add build-base git nodejs npm
 COPY . ${GOPATH}/src/forgejo.org
 WORKDIR ${GOPATH}/src/forgejo.org

+
+RUN set -ex; go env;
+
 RUN make clean-no-bindata
 RUN make frontend
 RUN go build contrib/environment-to-ini/environment-to-ini.go && xx-verify environment-to-ini
```

Reviewed-on: https://codeberg.org/forgejo/forgejo/pulls/9837
Reviewed-by: Mathieu Fenniak <mfenniak@noreply.codeberg.org>
Reviewed-by: Gusted <gusted@noreply.codeberg.org>
This commit is contained in:
Michael Kriese 2026-07-04 16:56:25 +02:00 committed by Gusted
commit 47ae5e6841
2 changed files with 8 additions and 0 deletions

View file

@ -10,6 +10,10 @@ ARG TAGS="sqlite sqlite_unlock_notify"
ENV TAGS="bindata timetzdata $TAGS" ENV TAGS="bindata timetzdata $TAGS"
ARG CGO_EXTRA_CFLAGS ARG CGO_EXTRA_CFLAGS
# it's set to local by default in the base image
# we want to use auto to let go choose the right toolchain
ENV GOTOOLCHAIN=auto
# #
# Transparently cross compile for the target platform # Transparently cross compile for the target platform
# #

View file

@ -10,6 +10,10 @@ ARG TAGS="sqlite sqlite_unlock_notify"
ENV TAGS="bindata timetzdata $TAGS" ENV TAGS="bindata timetzdata $TAGS"
ARG CGO_EXTRA_CFLAGS ARG CGO_EXTRA_CFLAGS
# it's set to local by default in the base image
# we want to use auto to let go choose the right toolchain
ENV GOTOOLCHAIN=auto
# #
# Transparently cross compile for the target platform # Transparently cross compile for the target platform
# #