Skip to content

Commit

Permalink
Merge pull request #134 from openshift-cherrypick-robot/cherry-pick-1…
Browse files Browse the repository at this point in the history
…32-to-release-0.3

[release-0.3] Set Golang version in Dockerfile
  • Loading branch information
openshift-merge-bot[bot] authored Mar 17, 2024
2 parents 59ab63d + 6099744 commit b9bab9d
Showing 1 changed file with 17 additions and 8 deletions.
25 changes: 17 additions & 8 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,19 +1,28 @@
# Build the manager binary
FROM quay.io/centos/centos:stream8 AS builder
RUN dnf install -y golang git \
RUN dnf install -y jq git \
&& dnf clean all -y

WORKDIR /workspace
# Copy the Go Modules manifests
# Copy the Go Modules manifests for detecting Go version
COPY go.mod go.mod
COPY go.sum go.sum

# Ensure correct Go version
RUN export GO_VERSION=$(grep -E "go [[:digit:]]\.[[:digit:]][[:digit:]]" go.mod | awk '{print $2}') && \
go install golang.org/dl/go${GO_VERSION}@latest && \
~/go/bin/go${GO_VERSION} download && \
/bin/cp -f ~/go/bin/go${GO_VERSION} /usr/bin/go && \
go version
RUN \
# get Go version from mod file
export GO_VERSION=$(grep -E "go [[:digit:]]\.[[:digit:]][[:digit:]]" go.mod | awk '{print $2}') && \
echo ${GO_VERSION} && \
# find filename for latest z version from Go download page
export GO_FILENAME=$(curl -sL 'https://go.dev/dl/?mode=json&include=all' | jq -r "[.[] | select(.version | startswith(\"go${GO_VERSION}\"))][0].files[] | select(.os == \"linux\" and .arch == \"amd64\") | .filename") && \
echo ${GO_FILENAME} && \
# download and unpack
curl -sL -o go.tar.gz "https://golang.org/dl/${GO_FILENAME}" && \
tar -C /usr/local -xzf go.tar.gz && \
rm go.tar.gz

# add Go directory to PATH
ENV PATH="${PATH}:/usr/local/go/bin"
RUN go version

# Copy the go source
COPY main.go main.go
Expand Down

0 comments on commit b9bab9d

Please sign in to comment.