Skip to content

Commit 88f07c1

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

File tree

2 files changed

+41
-6
lines changed

2 files changed

+41
-6
lines changed

images/build/go-runner/Dockerfile

Lines changed: 37 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,44 @@ 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+
# Download and install bootstrap Go (binary)
33+
ARG BOOTSTRAP_GO_VERSION=1.24.7
34+
ARG TARGETARCH
35+
RUN echo "Installing bootstrap Go version: ${BOOTSTRAP_GO_VERSION} (${TARGETARCH})" && \
36+
curl -fsSL "https://go.dev/dl/go${BOOTSTRAP_GO_VERSION}.linux-${TARGETARCH}.tar.gz" -o /tmp/go-bootstrap.tar.gz && \
37+
tar -xzf /tmp/go-bootstrap.tar.gz -C /usr/local && \
38+
mv /usr/local/go /usr/local/go-bootstrap && \
39+
rm /tmp/go-bootstrap.tar.gz
40+
41+
# Download Go source
42+
RUN echo "Downloading Go source version: ${GO_VERSION}" && \
43+
curl -fsSL "https://go.dev/dl/go${GO_VERSION}.src.tar.gz" -o /tmp/go.src.tar.gz && \
44+
tar -xzf /tmp/go.src.tar.gz -C /usr/local && \
45+
rm /tmp/go.src.tar.gz
46+
47+
# Build Go from source with bootstrap
48+
WORKDIR /usr/local/go/src
49+
ENV GOROOT_BOOTSTRAP=/usr/local/go-bootstrap
50+
RUN ./make.bash
51+
52+
# Set up Go environment
53+
ENV PATH=/usr/local/go/bin:$PATH
54+
ENV GOROOT=/usr/local/go
55+
ENV GOPATH=/workspace/gopath
56+
2157
# Copy the sources
58+
WORKDIR /workspace
2259
COPY ./go-runner.go ./
2360
COPY ./go.* ./
2461

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

3976
# Build
4077
ARG package=.
41-
ARG ARCH
4278

4379
ENV CGO_ENABLED=0
44-
ENV GOOS=linux
45-
ENV GOARCH=${ARCH}
4680

4781
RUN go env
4882

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)

0 commit comments

Comments
 (0)