diff --git a/Dockerfile b/Dockerfile index 18cfd6d9e..35e79c10b 100644 --- a/Dockerfile +++ b/Dockerfile @@ -36,10 +36,34 @@ # $ docker exec tailscaled tailscale status -FROM golang:1.27-alpine AS build-env +# Use Tailscale's Go toolchain (a fork of Go) as specified by the +# go.toolchain.rev file, matching how everything else in this repo is +# built, rather than the golang Docker image. This avoids this +# Dockerfile breaking for a day or two after each Go minor version +# bump, when go.mod requires a Go version that the official golang +# Docker image doesn't yet ship. See +# https://github.com/tailscale/tailscale/issues/21072 +FROM alpine:3.22 AS build-env WORKDIR /go/src/tailscale +RUN apk add --no-cache curl tar + +COPY go.toolchain.rev ./ +RUN read -r REV &2; exit 1 ;; \ + esac && \ + curl --retry 3 -f -L -o /tmp/go.tar.gz "https://github.com/tailscale/go/releases/download/build-${REV}/linux-${ARCH}.tar.gz" && \ + mkdir -p /usr/local/go && \ + tar -C /usr/local/go --strip-components=1 -xzf /tmp/go.tar.gz && \ + rm /tmp/go.tar.gz + +ENV GOPATH=/go +ENV PATH=/usr/local/go/bin:$GOPATH/bin:$PATH + COPY go.mod go.sum ./ RUN go mod download diff --git a/docs/go-bump-checklist.md b/docs/go-bump-checklist.md index 5088777bb..3bb478f2d 100644 --- a/docs/go-bump-checklist.md +++ b/docs/go-bump-checklist.md @@ -26,7 +26,6 @@ and past bump commits (e.g. "go.toolchain.branch: switch to Go 1.26", ## Version strings elsewhere -- [ ] `Dockerfile`: `FROM golang:1.NN-alpine` in the build stage. - [ ] `README.md`: "We always require the latest Go release, currently Go 1.NN". - [ ] `.github/workflows/`: grep for hardcoded Go versions. As of Go 1.27 the workflows use `go-version-file: go.mod` and need no diff --git a/version/version_test.go b/version/version_test.go index 01fcd47ec..db01ae471 100644 --- a/version/version_test.go +++ b/version/version_test.go @@ -38,7 +38,9 @@ func readAlpineTag(t *testing.T, file string) string { if !ok { continue } - return string(suf) + // Drop anything after the tag, such as an "AS stage-name" suffix. + tag, _, _ := bytes.Cut(suf, []byte(" ")) + return string(tag) } return "" } diff --git a/version_test.go b/version_test.go index 6fb3ddef9..bcd5fb9c5 100644 --- a/version_test.go +++ b/version_test.go @@ -4,7 +4,6 @@ package tailscaleroot import ( - "fmt" "os" "os/exec" "runtime" @@ -14,19 +13,6 @@ import ( "golang.org/x/mod/modfile" ) -func TestDockerfileVersion(t *testing.T) { - goVersion := mustGetGoModVersion(t, false) - - dockerFile, err := os.ReadFile("Dockerfile") - if err != nil { - t.Fatal(err) - } - wantSub := fmt.Sprintf("FROM golang:%s-alpine AS build-env", goVersion) - if !strings.Contains(string(dockerFile), wantSub) { - t.Errorf("didn't find %q in Dockerfile", wantSub) - } -} - // TestGoVersion tests that the Go version specified in go.mod matches ./tool/go version. func TestGoVersion(t *testing.T) { // We could special-case ./tool/go path for Windows, but really there is no @@ -34,7 +20,7 @@ func TestGoVersion(t *testing.T) { if runtime.GOOS == "windows" { t.Skip("Skipping test on Windows") } - goModVersion := mustGetGoModVersion(t, true) + goModVersion := mustGetGoModVersion(t) goToolCmd := exec.Command("./tool/go", "version") goToolOutput, err := goToolCmd.Output() @@ -56,7 +42,7 @@ func TestGoVersion(t *testing.T) { } } -func mustGetGoModVersion(t *testing.T, includePatchVersion bool) string { +func mustGetGoModVersion(t *testing.T) string { t.Helper() goModBytes, err := os.ReadFile("go.mod") @@ -73,13 +59,5 @@ func mustGetGoModVersion(t *testing.T, includePatchVersion bool) string { t.Fatal("no Go version found in go.mod") } - version := modFile.Go.Version - - parts := strings.Split(version, ".") - if !includePatchVersion { - if len(parts) >= 2 { - version = parts[0] + "." + parts[1] - } - } - return version + return modFile.Go.Version }