Skip to content

Commit

Permalink
Add build arg for docker version
Browse files Browse the repository at this point in the history
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
  • Loading branch information
idlewis committed Oct 25, 2023
1 parent 80dd578 commit 19d48fc
Showing 1 changed file with 10 additions and 1 deletion.
11 changes: 10 additions & 1 deletion Dockerfile
Original file line number Diff line number Diff line change
@@ -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
Expand Down

0 comments on commit 19d48fc

Please sign in to comment.