From 19d48fc61897721c4c2039f8a1e597b5d40ed882 Mon Sep 17 00:00:00 2001 From: ilewis Date: Tue, 24 Oct 2023 15:46:39 +0100 Subject: [PATCH] Add build arg for docker version and fix env -> ENV And if no version is supplied, grab a default by parsing go.mod, in the same way that the go install script does --- Dockerfile | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/Dockerfile b/Dockerfile index 07f93f01..2ff2ae58 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,14 +1,23 @@ # Build the manager binary FROM registry.access.redhat.com/ubi8-minimal:latest as builder ARG GO_PLATFORM=amd64 +ARG GO_VERSION_ARG env PATH=$PATH:/usr/local/go/bin RUN microdnf install tar gzip -RUN curl -L --output - "https://golang.org/dl/go1.20.10.linux-${GO_PLATFORM}.tar.gz" | tar -xz -C /usr/local/ WORKDIR /workspace # Copy the Go Modules manifests COPY go.mod go.mod COPY go.sum go.sum + +RUN if [ -z "${GO_VERSION_ARG}" ]; then \ + GO_VERSION=$(grep '^go [0-9]\+.[0-9]\+' go.mod | cut -d ' ' -f 2); \ + else \ + GO_VERSION=${GO_VERSION_ARG}; \ + fi; \ + rm -rf /usr/local/go; \ + curl -L --output - "https://golang.org/dl/go${GO_VERSION}.linux-${GO_PLATFORM}.tar.gz" | tar -xz -C /usr/local/ + # cache deps before building and copying source so that we don't need to re-download as much # and so that source changes don't invalidate our downloaded layer RUN go mod download