Files
livekit/.github/scripts/go-version.sh
Elliot Morales Solé a55d4c6c0f build: pin the builder stage to the host platform
The build already cross-compiles explicitly (CGO_ENABLED=0, GOOS=linux,
GOARCH=$TARGETARCH), so the toolchain never needs to match the target arch.
Without --platform=$BUILDPLATFORM a cross-arch build runs the entire Go
compilation under QEMU emulation for a byte-identical binary: building
linux/amd64 on an arm64 host went from minutes to still-running after ten.

Only the final stage stays on $TARGETPLATFORM, where it belongs.

go-version.sh reads the Go version out of the builder's FROM line, so its
pattern now accepts an optional --platform flag before the image.
2026-10-27 15:18:28 +01:00

51 lines
1.8 KiB
Bash
Executable File

#!/usr/bin/env bash
# Copyright 2026 LiveKit, Inc.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#
# Print the Go toolchain version pinned by a Dockerfile's golang builder image.
#
# usage: .github/scripts/go-version.sh [dockerfile] (default: Dockerfile)
#
# The pinned `golang:X.Y.Z-alpineA.B@sha256:...` builder image is the single source
# of truth, and Renovate keeps it current via an approvable PR. Each workflow reads
# the version out of the Dockerfile it builds against (setup-go cannot parse a
# Dockerfile itself), so a job's Go runtime always matches the image it produces.
#
# Deliberately NOT derived from go.mod's `go` directive: that is the module
# minimum, owned by the toolchain and by dependency requirements, and the go
# command may rewrite it to a bare major.minor.
set -euo pipefail
dockerfile="${1:-Dockerfile}"
if [ ! -f "$dockerfile" ]; then
echo "$dockerfile: no such file" >&2
exit 1
fi
version=$(sed -nE 's/^FROM[[:space:]]+(--platform=[^[:space:]]+[[:space:]]+)?golang:([0-9]+\.[0-9]+\.[0-9]+)[^[:space:]]*.*/\2/p' "$dockerfile" | sort -u)
if [ -z "$version" ]; then
echo "$dockerfile: no pinned 'FROM [--platform=...] golang:X.Y.Z-...' base image found" >&2
exit 1
fi
if [ "$(printf '%s\n' "$version" | wc -l)" -ne 1 ]; then
echo "$dockerfile pins more than one Go version: $(echo $version)" >&2
exit 1
fi
echo "$version"