Skip to content

Commit afaf4dc

Browse files
committed
Switch to building golang outselves
1 parent f65da27 commit afaf4dc

File tree

3 files changed

+46
-8
lines changed

3 files changed

+46
-8
lines changed

images/build/go-runner/Dockerfile

Lines changed: 40 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,46 @@ ARG BUILDER_IMAGE
1818
FROM ${BUILDER_IMAGE} as builder
1919
WORKDIR /workspace
2020

21+
# Install dependencies for building Go from source
22+
RUN apt-get update && apt-get install -y \
23+
build-essential \
24+
curl \
25+
git \
26+
ca-certificates \
27+
&& rm -rf /var/lib/apt/lists/*
28+
29+
# Download and build Go from source
30+
ARG GO_VERSION
31+
32+
ARG TARGETARCH
33+
RUN echo "Determining bootstrap Go version for ${GO_VERSION}" && \
34+
BOOTSTRAP_GO_VERSION=$(curl -fsSL "https://raw.githubusercontent.com/golang/go/go${GO_VERSION}/src/make.bash" | grep "^bootgo=" | cut -d= -f2) && \
35+
echo "Installing bootstrap Go version: ${BOOTSTRAP_GO_VERSION} (${TARGETARCH})" && \
36+
GO_ARCH="${TARGETARCH}"; \
37+
if [ "${TARGETARCH}" = "arm" ]; then GO_ARCH="armv6l"; fi && \
38+
curl -fsSL "https://go.dev/dl/go${BOOTSTRAP_GO_VERSION}.linux-${GO_ARCH}.tar.gz" -o /tmp/go-bootstrap.tar.gz && \
39+
tar -xzf /tmp/go-bootstrap.tar.gz -C /usr/local && \
40+
mv /usr/local/go /usr/local/go-bootstrap && \
41+
rm /tmp/go-bootstrap.tar.gz
42+
43+
# Download Go source
44+
RUN echo "Downloading Go source version: ${GO_VERSION}" && \
45+
curl -fsSL "https://go.dev/dl/go${GO_VERSION}.src.tar.gz" -o /tmp/go.src.tar.gz && \
46+
tar -xzf /tmp/go.src.tar.gz -C /usr/local && \
47+
rm /tmp/go.src.tar.gz
48+
49+
# Build Go from source with bootstrap
50+
WORKDIR /usr/local/go/src
51+
ENV GOROOT_BOOTSTRAP=/usr/local/go-bootstrap
52+
RUN ./make.bash
53+
54+
# Set up Go environment
55+
ENV PATH=/usr/local/go/bin:$PATH
56+
ENV GOROOT=/usr/local/go
57+
ENV GOPATH=/workspace/gopath
58+
2159
# Copy the sources
60+
WORKDIR /workspace
2261
COPY ./go-runner.go ./
2362
COPY ./go.* ./
2463

@@ -38,11 +77,8 @@ ENV GOPROXY="https://proxy.golang.org|direct"
3877

3978
# Build
4079
ARG package=.
41-
ARG ARCH
4280

4381
ENV CGO_ENABLED=0
44-
ENV GOOS=linux
45-
ENV GOARCH=${ARCH}
4682

4783
RUN go env
4884

@@ -54,5 +90,6 @@ FROM ${DISTROLESS_IMAGE}
5490
LABEL maintainers="Kubernetes Authors"
5591
LABEL description="go based runner for distroless scenarios"
5692
WORKDIR /
93+
COPY --from=builder /usr/local/go /usr/local/go
5794
COPY --from=builder /workspace/go-runner .
5895
ENTRYPOINT ["/go-runner"]

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/cloudbuild.yaml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,13 @@
11
# See https://github.com/kubernetes/test-infra/blob/master/config/jobs/image-pushing/README.md for more details on image pushing process
22

33
# this must be specified in seconds. If omitted, defaults to 600s (10 mins)
4-
timeout: 3600s
4+
timeout: 28800s
55

66
# this prevents errors if you don't use both _GIT_TAG and _PULL_BASE_REF,
77
# or any new substitutions added in the future.
88
options:
99
substitutionOption: ALLOW_LOOSE
10-
machineType: 'N1_HIGHCPU_8'
10+
machineType: E2_HIGHCPU_32
1111

1212
steps:
1313
- name: 'ghcr.io/sigstore/cosign/cosign:v2.5.3-dev@sha256:fe84ab87222b60d2d87f5efcb8ef3cfd895897c088fbeb973280689c81aedff1'

0 commit comments

Comments
 (0)