Skip to content

Commit

Permalink
Merge pull request #134 from razo7/fix-golang-version
Browse files Browse the repository at this point in the history
Fix Fetching Go version in Dockerfile
  • Loading branch information
openshift-merge-bot[bot] authored Sep 6, 2024
2 parents a659ac4 + 977486f commit 9501562
Showing 1 changed file with 18 additions and 8 deletions.
26 changes: 18 additions & 8 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,19 +1,29 @@
# Build the manager binary
FROM quay.io/centos/centos:stream9 AS builder
RUN dnf install git golang -y
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 to PATH
ENV PATH="/usr/local/go/bin:${PATH}"
RUN go version

# Copy the go source
COPY api/ api/
Expand Down

0 comments on commit 9501562

Please sign in to comment.