|
12 | 12 | # See the License for the specific language governing permissions and |
13 | 13 | # limitations under the License. |
14 | 14 |
|
| 15 | +# Get Go from official Alpine image |
| 16 | +ARG GO_VERSION |
| 17 | +FROM golang:${GO_VERSION}-alpine as go-source |
| 18 | + |
15 | 19 | # Build the manager binary |
16 | 20 | ARG DISTROLESS_IMAGE |
17 | 21 | ARG BUILDER_IMAGE |
18 | 22 | FROM ${BUILDER_IMAGE} as builder |
19 | 23 | WORKDIR /workspace |
20 | 24 |
|
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 |
| 25 | +# Copy Go installation from official image |
| 26 | +COPY --from=go-source /usr/local/go /usr/local/go |
53 | 27 |
|
54 | 28 | # Set up Go environment |
55 | 29 | ENV PATH=/usr/local/go/bin:$PATH |
56 | 30 | ENV GOROOT=/usr/local/go |
57 | | -ENV GOPATH=/workspace/gopath |
58 | 31 |
|
59 | 32 | # Copy the sources |
60 | 33 | WORKDIR /workspace |
@@ -90,6 +63,5 @@ FROM ${DISTROLESS_IMAGE} |
90 | 63 | LABEL maintainers="Kubernetes Authors" |
91 | 64 | LABEL description="go based runner for distroless scenarios" |
92 | 65 | WORKDIR / |
93 | | -COPY --from=builder /usr/local/go /usr/local/go |
94 | 66 | COPY --from=builder /workspace/go-runner . |
95 | 67 | ENTRYPOINT ["/go-runner"] |
0 commit comments