Skip to content

Commit 7eb5611

Browse files
authored
Merge pull request #4119 from dims/copy-golang-binaries-using-alpine-image
golang: Build 1.25.0 images - take #2 (copy golang binaries from golang alpine image)
2 parents 9621a4d + 770234e commit 7eb5611

File tree

11 files changed

+82
-20
lines changed

11 files changed

+82
-20
lines changed

dependencies.yaml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -144,7 +144,7 @@ dependencies:
144144
- path: images/build/go-runner/VERSION
145145

146146
- name: "registry.k8s.io/build-image/go-runner (go1.25-bookworm)"
147-
version: v2.4.0-go1.25rc2-bookworm.0
147+
version: v2.4.0-go1.25.1-bookworm.0
148148
refPaths:
149149
- path: images/build/go-runner/variants.yaml
150150
match: v((([0-9]+)\.([0-9]+)\.([0-9]+)(?:-([0-9a-zA-Z-]+(?:\.[0-9a-zA-Z-]+)*))?)(?:\+([0-9a-zA-Z-]+(?:\.[0-9a-zA-Z-]+)*))?)
@@ -195,7 +195,7 @@ dependencies:
195195
match: "CONFIG: 'go\\d+.\\d+-bullseye'"
196196

197197
- name: "registry.k8s.io/build-image/kube-cross (v1.34-go1.25)"
198-
version: v1.34.0-go1.25rc2-bullseye.0
198+
version: v1.34.0-go1.25.1-bullseye.0
199199
refPaths:
200200
- path: images/build/cross/variants.yaml
201201
match: "IMAGE_VERSION: 'v((([0-9]+)\\.([0-9]+)\\.([0-9]+)(?:-([0-9a-zA-Z-]+(?:\\.[0-9a-zA-Z-]+)*))?)(?:\\+([0-9a-zA-Z-]+(?:\\.[0-9a-zA-Z-]+)*))?)'"

images/build/cross/Makefile

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ REVISION ?= 0
3535
TYPE ?= default
3636

3737
# Build args
38-
BASEIMAGE ?= golang:$(GO_VERSION)-$(OS_CODENAME)
38+
BASEIMAGE ?= debian:$(OS_CODENAME)-slim
3939
PROTOBUF_VERSION ?= 3.19.4
4040

4141
IMAGE = $(REGISTRY)/$(IMGNAME)
@@ -83,6 +83,8 @@ container: check-env init-docker-buildx
8383
--tag $(IMAGE)-$${platform##*/}:latest-$(CONFIG)-$(TYPE) \
8484
--build-arg=BASEIMAGE=$(BASEIMAGE) \
8585
--build-arg=PROTOBUF_VERSION=$(PROTOBUF_VERSION) \
86+
--build-arg=TARGETPLATFORM=$${platform} \
87+
--build-arg=GO_VERSION=$(GO_VERSION) \
8688
--file $(TYPE)/Dockerfile \
8789
.; \
8890
done

images/build/cross/default/Dockerfile

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,8 @@
1616
# platform go binary for the architecture kubernetes cares about.
1717

1818
ARG BASEIMAGE
19+
ARG GO_VERSION
20+
FROM golang:${GO_VERSION}-alpine as go-source
1921
FROM ${BASEIMAGE}
2022

2123
##------------------------------------------------------------
@@ -40,6 +42,12 @@ ENV KUBE_CROSSPLATFORMS \
4042
windows/amd64 windows/386
4143

4244
##------------------------------------------------------------
45+
COPY --from=go-source /usr/local/go /usr/local/go
46+
ENV PATH=/usr/local/go/bin:$PATH
47+
ENV GOROOT=/usr/local/go
48+
ENV GOLANG_VERSION=${GO_VERSION}
49+
ENV GOTOOLCHAIN=local
50+
ENV GOPATH=/usr/local/go
4351

4452
# Pre-compile the standard go library when cross-compiling. This is much easier now when we have go1.5+
4553
RUN targetArch=$(echo $TARGETPLATFORM | cut -f2 -d '/') \
@@ -52,12 +60,17 @@ fi
5260
RUN apt-get -q update \
5361
&& apt-get install -qqy \
5462
apt-utils \
63+
curl \
5564
file \
65+
git \
66+
gnupg2 \
67+
iproute2 \
5668
jq \
69+
openssh-client \
5770
patch \
5871
rsync \
5972
unzip \
60-
iproute2
73+
wget
6174

6275
# Use dynamic cgo linking for architectures other than amd64 for the server platforms
6376
# To install crossbuild essential for other architectures add the following repository.

images/build/cross/variants.yaml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,9 @@ variants:
22
v1.34-go1.25-bullseye:
33
CONFIG: 'go1.25-bullseye'
44
TYPE: 'default'
5-
IMAGE_VERSION: 'v1.34.0-go1.25rc2-bullseye.0'
5+
IMAGE_VERSION: 'v1.34.0-go1.25.1-bullseye.0'
66
KUBERNETES_VERSION: 'v1.34.0'
7-
GO_VERSION: '1.25rc2'
7+
GO_VERSION: '1.25.1'
88
GO_MAJOR_VERSION: '1.25'
99
OS_CODENAME: 'bullseye'
1010
REVISION: '0'

images/build/go-runner/Dockerfile

Lines changed: 16 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -12,12 +12,27 @@
1212
# See the License for the specific language governing permissions and
1313
# limitations under the License.
1414

15-
# Build the manager binary
15+
ARG GO_VERSION
1616
ARG DISTROLESS_IMAGE
1717
ARG BUILDER_IMAGE
18+
19+
# Get Go from official Alpine image
20+
FROM golang:${GO_VERSION}-alpine as go-source
21+
22+
# Build the manager binary
1823
FROM ${BUILDER_IMAGE} as builder
1924
WORKDIR /workspace
2025

26+
# Copy Go installation from official image
27+
COPY --from=go-source /usr/local/go /usr/local/go
28+
29+
# Set up Go environment
30+
ENV PATH=/usr/local/go/bin:$PATH
31+
ENV GOROOT=/usr/local/go
32+
ENV GOLANG_VERSION=${GO_VERSION}
33+
ENV GOTOOLCHAIN=local
34+
ENV GOPATH=/usr/local/go
35+
2136
# Copy the sources
2237
COPY ./go-runner.go ./
2338
COPY ./go.* ./
@@ -38,11 +53,8 @@ ENV GOPROXY="https://proxy.golang.org|direct"
3853

3954
# Build
4055
ARG package=.
41-
ARG ARCH
4256

4357
ENV CGO_ENABLED=0
44-
ENV GOOS=linux
45-
ENV GOARCH=${ARCH}
4658

4759
RUN go env
4860

images/build/go-runner/Makefile

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -20,12 +20,12 @@ APP_VERSION = $(shell cat VERSION)
2020
GO_MAJOR_VERSION ?= 1.24
2121
REVISION ?= 0
2222
GO_VERSION ?= 1.24.6
23-
OS_CODENAME ?= bookworm
23+
OS_CODENAME ?= bookworm-slim
2424

2525
# Build args
2626
DISTROLESS_REGISTRY ?= gcr.io/distroless
2727
DISTROLESS_IMAGE ?= static-debian12
28-
BUILDER_IMAGE ?= golang:$(GO_VERSION)-$(OS_CODENAME)
28+
BUILDER_IMAGE ?= debian:$(OS_CODENAME)
2929

3030
# Configuration
3131
CONFIG = go$(GO_MAJOR_VERSION)-$(OS_CODENAME)
@@ -53,4 +53,5 @@ clean:
5353
rm go-runner
5454

5555
BUILD_ARGS = --build-arg=BUILDER_IMAGE=$(BUILDER_IMAGE) \
56-
--build-arg=DISTROLESS_IMAGE=$(DISTROLESS_REGISTRY)/$(DISTROLESS_IMAGE)
56+
--build-arg=DISTROLESS_IMAGE=$(DISTROLESS_REGISTRY)/$(DISTROLESS_IMAGE) \
57+
--build-arg=GO_VERSION=$(GO_VERSION)

images/build/go-runner/variants.yaml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
11
variants:
22
go1.25-bookworm:
33
CONFIG: 'go1.25-bookworm'
4-
IMAGE_VERSION: 'v2.4.0-go1.25rc2-bookworm.0'
4+
IMAGE_VERSION: 'v2.4.0-go1.25.1-bookworm.0'
55
GO_MAJOR_VERSION: '1.25'
66
OS_CODENAME: 'bookworm'
77
REVISION: '0'
8-
GO_VERSION: '1.25rc2'
8+
GO_VERSION: '1.25.1'
99
DISTROLESS_IMAGE: 'static-debian12'
1010
go1.24-bookworm:
1111
CONFIG: 'go1.24-bookworm'

images/releng/ci/Dockerfile

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,25 @@
1414

1515
ARG GO_VERSION
1616
ARG OS_CODENAME
17-
FROM golang:${GO_VERSION}-${OS_CODENAME} as builder
17+
18+
# Get Go from official Alpine image
19+
FROM golang:${GO_VERSION}-alpine as go-source
20+
21+
FROM debian:${OS_CODENAME}-slim
22+
23+
# Copy Go installation from official image
24+
COPY --from=go-source /usr/local/go /usr/local/go
25+
26+
# Set up Go environment
27+
ENV PATH=/usr/local/go/bin:$PATH
28+
ENV GOROOT=/usr/local/go
29+
ENV GOLANG_VERSION=${GO_VERSION}
30+
ENV GOTOOLCHAIN=local
31+
ENV GOPATH=/usr/local/go
32+
33+
# Install required packages for adding Google Cloud SDK repository
34+
RUN apt-get update && \
35+
apt-get install -y curl gnupg
1836

1937
RUN echo "deb [signed-by=/usr/share/keyrings/cloud.google.gpg] http://packages.cloud.google.com/apt cloud-sdk main" | \
2038
tee -a /etc/apt/sources.list.d/google-cloud-sdk.list
@@ -26,9 +44,11 @@ RUN apt-get update && \
2644
apt-get install -y \
2745
bsdmainutils \
2846
build-essential \
47+
git \
2948
google-cloud-sdk \
3049
jq \
3150
rpmlint \
51+
wget \
3252
&& rm -rf /var/lib/apt/lists/*
3353

3454
# install goreleaser

images/releng/ci/variants.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
variants:
22
go1.25-bookworm:
33
CONFIG: 'go1.25-bookworm'
4-
GO_VERSION: '1.25rc2'
4+
GO_VERSION: '1.25.1'
55
OS_CODENAME: 'bookworm'
66
REVISION: '0'
77
go1.24-bookworm:

images/releng/k8s-ci-builder/Dockerfile

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,21 @@ ARG OS_CODENAME
1717

1818
# The Release Tooling can be compiled with a different version of Go than the
1919
# the Go version used in the kubernetes/kubernetes active development branch.
20-
FROM golang:${GO_VERSION_TOOLING}-${OS_CODENAME} AS builder
20+
FROM golang:${GO_VERSION_TOOLING}-alpine as go-source
21+
FROM debian:${OS_CODENAME}-slim AS builder
22+
23+
# Install CA certificates for TLS verification
24+
RUN apt-get update && apt-get install -y ca-certificates && rm -rf /var/lib/apt/lists/*
25+
26+
# Copy Go installation from official image
27+
COPY --from=go-source /usr/local/go /go
28+
29+
# Set up Go environment
30+
ENV PATH=/go/bin:$PATH
31+
ENV GOROOT=/go
32+
ENV GOLANG_VERSION=${GO_VERSION_TOOLING}
33+
ENV GOTOOLCHAIN=local
34+
ENV GOPATH=/go
2135

2236
WORKDIR /go/src/k8s.io/release
2337

0 commit comments

Comments
 (0)